Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
175 views
in Q2A Core by

1 Answer

+2 votes
by
selected by
 
Best answer
  • Create a file using vi or nano editor at your desired location (in this demo I will put it under /var/rstart.sh)
  • Copy & paste below script to the file and save it

#!/bin/bash
#Scripts to start services if not running
ps -ef | grep nginx |grep -v grep > /dev/null
if [ $? != 0 ]
then
       /etc/init.d/nginx start > /dev/null
fi
ps -ef | grep php5-fpm |grep -v grep > /dev/null
if [ $? != 0 ]
then
       /etc/init.d/php5-fpm start > /dev/null
fi
ps -ef | grep mysql |grep -v grep > /dev/null
if [ $? != 0 ]
then
       /etc/init.d/mysql start > /dev/null 
fi
cd /var
chmod 755 rstart.sh

 

put this in cron to run every 15 minutes.

*/1 * * * * /var/rstart.sh

hope this help

by
toput the cron job corectly

run on the command line

sudo crontab -e


than using the vi
add at the end

*/1 * * * * /var/rstart.sh
...