:: How to create script for auto restart daemon if it down
+ create auto restart daemon script (nginx)
|
0 |
cat > alwaysup.sh |
add the script, like these:
#!/bin/bash
alwaysup=ps aux | grep -v grep | grep -c nginx
if [ $alwaysup -le 0 ]
then
/etc/init.d/nginx restart
fi
press ctrl+d for exit
+ make the script executable
|
0 |
chmod +x alwaysup.sh |
+ add to cron
crontab -e
|
0 |
*/5 * * * * /root/alwaysup.sh > /dev/null 2>&1 |

In my case:
#!/bin/bash
alwaysup=$(ps aux | grep -v grep | grep -c nginx)
if [ $alwaysup -le 0 ]
then
/etc/init.d/nginx restart
fi