start mongrel on server boot

From WebHostingNeeds.com
Jump to: navigation, search
vi /etc/init.d/mongrel


Add following content

#!/usr/bin/env ruby
#
# mongrel Startup script for Mongrel by Tim Morgan, modified by bmihelac
#
# chkconfig: - 85 15
# description: mongrel manages Mongrel
#

# this would add one mongrels for these two apps on 
# ports 8000 and 8001, mephisto would be started in production

apps = [
  {:app => 'redmine', :environment => 'production'},
]

default_port = 3000
default_options = {
  :app_dir => '/home/',
  :environment => 'production'
}

if ['stop', 'restart'].include? ARGV.first
  apps.each do |app|
    options = default_options.merge(app)
    path = File.join options[:app_dir], options[:app]
    puts "Stopping #{path}..." 
    `mongrel_rails stop -c #{path} -P log/mongrel.pid`
  end
end

if ['start', 'restart'].include? ARGV.first
  apps.each do |app|
    options = default_options.merge(app)
    path = File.join options[:app_dir], options[:app]
    port = options[:port] || default_port
    puts "Starting #{options[:app]} on #{port}..." 
    `mongrel_rails start -d -p #{port} -e #{options[:environment]} -c #{path} -P log/mongrel.pid`
    default_port = port + 1
  end
end

unless ['start', 'stop', 'restart'].include? ARGV.first
    puts "Usage: mongrel {start|stop|restart}" 
    exit
end

Enable mongrel to start on boot.

chmod 755 /etc/init.d/mongrel
chkconfig mongrel on

Verify

chkconfig --list | grep mongrel


[email protected] [~]# chkconfig --list | grep mongrel
mongrel         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[email protected] [~]#


In my server, redmine installed at "/home/redmine".



redmine