I have been having an issue with my trac server that causes random apache2 crashes, and as of late I haven’t been able to figure out exactly what is causing them, seems the server just seems to automagically turn off at random intervals.

This is a script I put together to test if any of the apache2 executables are currently running:

run=`ps ax | grep /usr/sbin/apache2 | grep -v grep | cut -c1-5 | paste -s -`
if [ "$run" ];
echo "Apache2 is running"
/etc/init.d/httpd start

The script checks to see if they are, and if it can’t find any running tasks it will attempt to restart apache2. Install this to a crontab every couple of minutes, and it should cause Apache to auto-restart in the event of a crash. Works well on the trac server anyways 🙂