So, Its possible to use mongrel cluster in a shared environment. I've shown that. But what about stopping and starting all these processes? No one wants to cap restart in every source directory after a server gets rebooted. And what if I need to shut them all down at once!? I can't be ghetto and sudo killall mongrel_rails, I've got self respect.
So to solve my little problem, I took the kick in the butt from Peter Cooper and finally created an init script for all the mongrel_clusters on a shared box.
The beauty of this is that when I add a new app to the server, I don't have to tell the script. Using conventions, it knows what rails apps I have installed.
Basically, when you call start, it iterates through the APP_DIR directory. When it finds a rails app with mongrel_cluster.conf in its config directory, it starts it, but not before it verifies that there isn't a pid under /log/. If it finds a pid, it just reports back to you that the app has already been started.
Calling stop does the inverse, with the same protections. Restart just does a stop then a start. If you've got a stuck process or some other wackyness going on, force_restart will skip past the checks and force restart your rails apps.
Huzzah! Another virtue of using conventions.
Grab the script here: svn export http://code.jtoe.net/rails/scripts/mongrel_processes.rb
Put it anywhere, chmod it, and symlink it to init.d
svn export http://code.jtoe.net/rails/scripts/mongrel_processes.rb
chmod 755 mongrel_processes.rb
sudo ln -s /home/dev/bin/mongrel_processes.rb /etc/init.d/mongrel_processes
If you're on (ubuntu|debian), add it to your start up processes like this:
sudo update-rc.d -f mongrel_processes defaults
And you're off...err automatically on...just reboot and try it out.
Popularity: 33% [?]



About
Mmm, Del.icio.us
Nice one mate - simple and clean :) Will make sure to link this when we get around to documenting our process with Flow and future apps.
Kee
Thanks - very handy. Linked in our forums.
And what is the user mongrel runs in ? I hope it's not root...
On (at least) RedHat-base distributions, the definition of the APP_DIR variable belongs to a file in /etc/sysconfig (/etc/sysconfig/mongrel_apps for example). Of course, this file has to be source in the script...
If Mongrel doesn't get a chance to shut itself down properly (say, if your server gets physically power cycled), will the script start Mongrel on boot? Or will it see a stale PID and assume the mongrel process is running when its not?
You can use the force_restart command on it. It skips the pid checks and does a stop & start.
But that WOULD have to happen manually, you're right. I'll have to look into that.
Since mongrel_cluster already gracefully handles the already running / not running conditions, I simply removed that functionality from the script - this way cluster::start is always run on startup.
For me the script still won't start up all mongrel clusters, if the pid files exist right after boot up. This happens i.e. after a restore of my backup.
Why not change the start method to something like this and let mongrel_rails take care of the existing pid file:
def start(app)
if is_started?(app) == true
puts "pid file exists. #{app} could be running, trying to start anyway:"
else
puts "starting #{app}"
end
`mongrel_rails cluster::start -c #{File.join(APP_DIR, app, "current", "config", "mongrel_cluster.yml")}`
end
Is the server down?
svn: could not connect to server (http://code.jtoe.net)
You will have problems running a non-Bourne init script on a Solaris system.
Regardless of the #! line. Solaris will use the /sbin/sh
as the interpreter...
see /sbin/rc3:
if [ -d /etc/rc3.d ]; then
for f in /etc/rc3.d/S*; do
if [ -s $f ]; then
case $f in
*.sh) . $f ;;
*) /sbin/sh $f start ;;
esac
fi
done
fi
Make sure you understand the boot process before you install this. I installed the script with update-rc.d mongrel_processes defaults, and one of my rails apps failed to start on boot because mysql wasn't up yet when it started.
"sudo update-rc.d mongrel_processes start 30 2 3 4 5 . stop 70 0 1 6 ." should do the trick.
for force_restart(app)
I add "stop app" before wipe_cluster(app) takes action.
for start(app)
I add wipe_cluster(app) at the beginning to deal with pid files problem on my server.
You're mixing Singular and Plural namings - and sometimes the .rb ending seems to be missing - you might want to fix it in your write up - in case I'm right ...
Thanx, great work of yours!
hello nice work friend ,
i deadly needed motivation in automising my apps, & i got here
chetanM
Hey boys!
Sex with cute girls freeonlinedatingservicesatholida
http://freeonlinedatingservicesatholida.blogspot.com
http://freenonlineatingcervicesuldesac.blogspot.com
http://freeonlinedatingserviceseleeleha.blogspot.com
http://freeonlinedatingservicesinbowman.blogspot.com
High definition porno movies
here
http://premonsw545.worddatingguide.info
High definition porno movies
here
http://webtechnologiesnew.blogspot.com
Oh, cool, I found this, cause now you can keep mongrel config in you app devel tree (svn-ed and all that). Very nice.
app's cluster?
or maybe palmtree (for cap 2.X) does exactly that...
thanks
[...] well it never had a version number before, but I thought I'd add one [...]
hi...
Agree...
Using the above script will run mongrel as root which is NOT GOOD. You have to add:
"su #{USER} -c mongrel_rails cluster::start etc"