The Inner Workings Of A Coders Brain
Posts tagged ubuntu linux apache2 cron cronjob crash restart crontab bash
Automatically Restarting Apache2 Via Cronjob If It Crashes
014 years
by FishGuy876
in Linux
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 🙂
Recent Comments