I had a need of something like that once, so I came up with this scheme:
In each rails folder, I create three files:
app_start
app_stop
app_restart
app_start and app_stop contain the shell script calls necessary to
start the particular application. So if you are using Mongrel,
app_start might look something like
mongrel_rails start -p 3010 -e production -d
and app_stop would look like
mongrel_rails stop
That way each app_start/stop pair is specific to the application, but
general enough to be called via a universal script. Then I created
the universal script that would descend into the directory where all
the rails apps were (/var/www in this case), and if there was an
app_start, exec it. I named the script rails_ctrl and it looks like
this:
#! /usr/bin/ruby
This script is used to launch all rails apps after a restart. It
assumes that each
app will have a file named app_start in the project’s root
directory. This file needs
to call mongrel_rails or mongrel_cluster with the proper parameters.
action = ARGV.at(0)
action ||= ‘’
action = action.downcase
app = ARGV.at(1)
if ![‘start’, ‘stop’, ‘restart’].include?(action)
puts “rails_ctrl: Invalid action: #{action}”
exit
end
root_dir = ‘/var/www/’
dirs = Dir.entries(root_dir)
dirs.each do |dir|
if ![’.’, ‘…’].include?(dir) && dir == (app || dir)
d = “#{root_dir}#{dir}”
if File.directory?(d)
f = “#{d}/app_#{action}”
if File.file?(f)
Dir.chdir(d)
puts “Performing #{action} action on #{dir}…”
system(f)
end
end
end
end
This was just hacked together one day to suit my purposes, so it may
have some holes in it. Feel free to take it and modify to fit your
environment.
Peace,
Phillip