- 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