Thursday, March 9, 2017

Linux Server Service Start if it's automatically stopped.


Create File Name like servicestart and enter below lines in to that and replace the service=apache2 to anyother service name.

# vi servicestart
+++++++++++++++++++++
#!/bin/bash
service=apache2

if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running!!!"
else
/etc/init.d/$service start
fi
+++++++++++++++++++++
Save an Close this file.

Put it in to Cron to run at every minute.

# crontab -e
*/1 * * * * /bin/bash /root/servicerestart

No comments:

Post a Comment