The post
Monit & Mongrel
Ryan Creasey posted this 10 months ago (more), and updated it 10 months ago.
I just got done configuring this rails application (kaneda.net) to be monitored by monit. Monit will now watch my mongrel children and make sure they're playing nice. If they're not, I'll get an email stating so. Then, a few moments later, another email is received stating that it was able to fix the problem.
I got the idea to take a look at getting this setup while reading the usual ruby blogs a while back. This tutorial will get you started in the right direction. Do note that you'll probably have to patch your mongrel_rails script. I know that Ryan McGeary doesn't think it's a good idea, but as that tutorial points out, you're requiring monit to monitor individual children in your mongrel cluster; not the entire cluster itself. If only the mongrel devs could put --clean as a flag on normal mongrel_rails start commands, it'd be fine. But as of writing, it's only a flag on the cluster::start option.
Here's the patch that I used to "fix" my mongrel_rails script:
Index: bin/mongrel_rails
===================================================================
--- bin/mongrel_rails (revision 536)
+++ bin/mongrel_rails (working copy)
@@ -83,9 +83,17 @@
config = Mongrel::Rails::RailsConfigurator.new(settings) do
if defaults[:daemon]
if File.exist? defaults[:pid_file]
- log "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors."
- log "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start."
- exit 1
+ # mongrels that crash can leave stale PID files behind, and these
+ # should not stop mongrel from being restarted by monitors...
+ pid = File.new(defaults[:pid_file]).readline
+ running = Process.kill(0, pid.to_i) rescue nil
+ if running
+ log "!!! PID file #{defaults[:pid_file]} already exists and the process id "
+ log " referred to in it is running. This mongrel is probably already running."
+ log " Check #{defaults[:log_file]} for errors. EXITING."
+ exit 1
+ else
+ log "!!! PID file #{defaults[:pid_file]} exists, but is stale, and will be deleted"
+ log " so that this mongrel can run."
+ File.delete(defaults[:pid_file])
+ end
end
daemonize
I hope it helps someone as much as it helped me.
0 comments
You need to be logged in to leave a comment.