STATUS=`/sbin/pidof SERVICE_NAME`
if [ $STATUS > 0 ]
then
exit 0
else
echo “Service SERVICE_NAME started.”
/sbin/service SERVICE_NAME start
exit 0
fi
4) Replace SERVICE_NAME with the service you aiming to Monitor, for example one my Ubuntu Servers I had a problem with ‘nginx’ which a mini webserver from Apache.
5) You can repeat the code above in the same file for other services.
6) Add the Shell Script to your Crontab depending on your own frequency, for example I had to check this for every 5 minutes, so the cronjob should be:
*/5 * * * * * /opt/chkservice.sh
6) The cronjob will email the Server Admin the output result, incase of any issues.
Please feel free to contribute, feedback is very much appreciated.
Comments are closed