Here is what I do in 3 steps:
1. Create a wrapper - https://rvm.io/integration/init-d/
rvm wrapper ruby-1.8.7-p334 bootup mongrel_rails
rvm wrapper ruby-1.8.7-p334 bootup starling
2. Create /etc/init.d/mongrel
#!/usr/bin/env ruby
#
# mongrel Startup script for Mongrel by Tim Morgan, modifyed by Eric
#
# chkconfig: - 85 15
# description: mongrel manages Mongrel
#
apps = [
{:app => 'eric', :cluster_config_path => '/home/u/apps/eric/current/config/mongrel_cluster.yml'} ]
default_port = 9300
default_options ={
:app_dir => '/home/u/apps/eric/current',
:enviroment => 'production'
}
if ['start','restart','stop', 'status'].include? ARGV.first
apps.each do |app|
options = default_options.merge(app)
puts "#{ARGV.first}: #{options[:app]} using #{options[:cluster_config_path]}..."
puts `su eric -c 'bootup_mongrel_rails cluster::#{ARGV.first} -v -C #{options[:cluster_config_path]}' `
end
end
if ['start'].include? ARGV.first
puts `su eric -c 'bootup_starling -d -P /home/u/apps/pfs/current/tmp/pids/starling.pid -q /home/u/apps/pfs/current/starling'`
end
unless ['start','stop','restart','status'].include? ARGV.first
puts "Usage: service mongrel {start|stop|restart|status}"
exit
end
3. Add into runlevel by chkconfig
chkconfig --add mongrel
chkconfig --level 3 mongrel on