Ok, well it never had a version number before, but I thought I'd add one now.
So What's New?
As requested, it has a way to fix the fact that PID's exist if the server fails. Typically, if the server fails, and you reboot, the PID's are still there and the script won't start the clusters (because it see's the PIDs and thinks the cluster is already started). So it bit me in the butt enough that I finally fixed it.
Now, this won't happen on boot, you'll have to do a force_restart. But I'm going to take a leap and expect that if a server hangs, and you have to manually reboot it, you'll be there to do a force_restart on your apps to insure they're working.
I didn't want to do this on the start task because it wasn't as graceful. Since this is a 20% thing and not an 80% thing, I put it in force_restart.
Also, since the start task is ran on boot, this isn't going to fix itself on boot. That's why you'll have to do a force_restart on it. If anyone knows more about that, let me know. I'd love to get it going on boot, without putting it in the start task.
Grab it here with SVN or just a copy and paste.
Popularity: 9% [?]



About
Mmm, Del.icio.us
I can't seem to access the script from your link. Is there an alternate location?
Thanks,
Joe
Its there now. My svn was down.
I made a slight change to your mongrel_processes.rb script to check for processes running on the server.
ON START:
If the pid files exist, the script will check for processes running. If it finds them, it will not start as usual.
If the processes are missing (due to a server crash), a message is output, and the force_restart function is run.
To get this to work, I changed your "start" method and added two new ones. Just after the force_restart call in the start method would be a good place to send a page or something like that, in case you wanted human attention.
Hope this helps someone. Thanks for your original article!
Kyle Oba
def mongrel_pids(app, app_dir)
pids = `ps
ef | grep "[m]ongrel_rails start" | grep "[]c #{app_dir}/#{app}/current" | awk '{print $2}'`end
def mongrel_running?(app, app_dir)
return mongrel_pids(app, app_dir) != ""
end
def start(app)
# Checks for PID files.
if is_started?(app) == true
if mongrel_running?(app, APP_DIR)
puts "#{app} is already started"
else
puts "#{app} did not shutdown properly."
force_restart(app)
end
else
puts "starting #{app}"
`mongrel_rails cluster::start -c #{File.join(APP_DIR, app, "current", "config", "mongrel_cluster.yml")}`
end
end
Hi !
It's awesome to have an init file in ruby !
Oba, can you pls send me the final script after modification ?
thanks
Addame
[...] Automated PHP Deployment With CapistranoApache 2.2, mod_proxy_balancer, & Mongrel on Ubuntu 6.06Start and Stop All Your Mongrel_Cluster ProcessesStart and Stop MySql in Mac Os X 10.5 LeopardMongrel_Processes Updated To 0.6 [...]
If you're using the
mongrel_clustergem you could use the--cleanoption to clean up stale pid files upon starting the cluster. I've written about it here.