Here is an sh script file to restart the Apache2 server in case it is not running.
#!/bin/sh
run=`ps ax | grep /usr/sbin/apache2 | grep -v grep | cut -c1-5 | paste -s -`
if [ "$run" ];
then
echo “Apache is running”
else
sudo /etc/init.d/apache2 restart
fi
Save to a file checkapache2.sh. Then set it as executible.(sudo chmod ug+x checkapache2.sh).
Enter a cron entry (using crontab -e) to check every 3 minutes. Adjust if necessary. If you have a fast server, then you can lower the time interval between checking.
References: lampdocs
No comments:
Post a Comment