Gnuru.org
Productive Linux


Subscribe

 Subscribe via Feedburner in a reader

Enter your email address:

Delivered by FeedBurner


Login
Login:
Password:



Don't have an account?
Sign up to Gnuru.org
Forgot your password?

Monitoring Apache for Crashes
26 February 2006 @ 11:49 GMT
by Paul

Unfortunately, this server was down for two weeks when I was away. When a cron job was running on Sunday mornings, apache would hang and would not come up again without a manual stop and start.

This may be because of a problem in php4. There may also be a problem in libmm as described here and here.

The bug fixes are apparently winging their way down from the developers. In the meantime, I wanted something that would stop and restart apache if it was hanging. I thought that I'd be able to continue learning bash by writing a little bash script to do this, but no! The monit utility was all I needed, which I got using apt:

apt-get install monit

Setup is straight-forward. Here is my config file entry for monitoring apache-perl:

check process apache-perl with pidfile /var/run/apache-perl.pid
   start program = "/etc/init.d/apache-perl start"
   stop  program = "/etc/init.d/apache-perl stop"
   if failed host 127.0.0.1 port 80
        protocol http then restart
   if 5 restarts within 5 cycles then timeout

So far, it seems to work.

Update: Sometimes the server is very, very slow. One day, perhaps I'll be able to afford to get some more oomph. However, in the meantime, to stop monit from restarting apache when it is slow to respond, but still up, I've changed the script to:

check process apache-perl with pidfile /var/run/apache-perl.pid
   start program = "/etc/init.d/apache-perl start"
   stop  program = "/etc/init.d/apache-perl stop"
   if failed host 127.0.0.1 port 80 with timeout 60 seconds
        protocol http request /monit/token then restart
   if 5 restarts within 5 cycles then timeout

The file /monit/token is an empty file created by:

mkdir /var/www/monit
touch /var/www/monit/token

Note the rather long timeout of 60 seconds that I've allowed apache to respond. This is because the server is can be very sluggish and monit's default 5 seconds is not nearly enough. Now, monit doesn't restart apache just because the web application is slow, but when apache really is down.

More info on monit can be found here.




Comments disabled