Customized Mongrel Startup Script
This shell script allows to start and stop bunch of Rails application on Mongrel webserver. This is Tim Morgan’s script, while I added ability to customize port, rails environment and directory for every app while respecting default values.
I use it on linux development machine where there is no need for mongrel_cluster and I do not want to make extra configuration.
We can save this script as /etc/init.d/mongrel and start|restart|stop all mongrels with /etc/init.d/mongrel start (or stop|restart). And to configure for startup we can use:
# redhat
sudo /sbin/chkconfig --level 345 mongrel on
#debian/ubuntu
sudo /usr/sbin/update-rc.d -f mongrel defaults
And here is script:
#!/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 => 'myapp'},
{:app => 'mephisto', :environment => 'production'},
]
default_port = 8000
default_options = {
:app_dir => '/home/rails',
: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
I am Bojan Mihelac and this blog is dedicated to share code, thoughts, tools and advices I came up with while working in
6 comments
this is the best script ive found so far
also you might want to add /sbin/chkconfig—level 06 mongrel off
to kill mongrel
as well you might want to add in the ability to use ips:
default_ip = ‘127.0.0.1’ and further on :
ip = options[:ip] || default_ip puts “Starting #{options[:app]} on #{port}...” `mongrel_rails start -d -p #{port} -a #{ip} -e #{options[:environment]} -c #{path} -P log/mongrel.pid`
Hi! Today getting a credit card is easy. Almost every credit card company issues credit cards for any credit score. Great? Sure. You can solve your financial problems with the right credit card.
best deal on discover cards discover miles card 0% apr for life on transferred balances
Hi! Today getting a credit card is easy. Almost every credit card company issues credit cards for any credit score. Great? Sure. You can solve your financial problems with the right credit card.
best deal on discover cards discover miles card 0% apr for life on transferred balances
Hi! Today getting a credit card is easy. Almost every credit card company issues credit cards for any credit score. Great? Sure. You can solve your financial problems with the right credit card.
best deal on discover cards discover miles card 0% apr for life on transferred balances
Speak your mind: