ACPI administration advocacy advocacy advocacy opinion alsa amarok apache apple apt aptitude audio audo authentication automount avi awk bash BIOS boot business cache calendar calibre cdr cdrecord censorship commandline computerscience console convert cron cut database date debian degree design desktop development disk dpkg dvd economics education emacs email europe exim faad ffmpeg file files firefox firewall flash foss freedom ftp fun fuse git gnumeric graphics grep growisofs grub gtkpod hardware hardware html idiocy image imagemagick images installation ip iphone ipod iptables iso itunes ivman kde kernel keyboard knoppix lame laptop latex linux locale lockin longlines m4a microsoft mimetypes minitab mount mp3 mp4 mplayer multimedia music mysql network nfs nfs4 nmap openbox openoffice opinion opinion partition pdf perl php politics postgresql printing privacy programming rant remote rhythmbox rss rsync rxvt scp screengrab screenshot script scripting scsi security sed server shell siteadmin sitenews sitesoftware skype skype slackware sound sox spam spreadsheet ssh statistics subversion sudo svk swap t23 t43 terminal text thinkpad thunderbird time timezone ubuntu udev upgrade usb usbmount users uuid versioncontrol vfat video vnc windows wine wordpress wordprocessing X40 xwindows xwindows youtube
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.