how to auto restart apache when it goes down

From WebHostingNeeds.com
Jump to: navigation, search

Create a shell script with following

#!/bin/sh
#
# Apache Process Monitor
#
checkapache=`ps ax | grep -v grep | grep -c httpd`
if [ $checkapache -le 0 ]
then
/usr/local/apache/bin/apachectl startssl
fi

Save it as /root/utils/monitor-apache.sh

Then set cronjob


*/5 * * * * sh /root/utils/monitor-apache.sh >/dev/null 2>&1

This will check Apache every 5 minutes, and if no httpd processes are running it will automatically restart the daemon.