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:

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

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 🙂