思路
通过crontab运行bash脚本监控Nginx状态,如果停止运行,重新启动即可。
1.(假定当前路径为家目录)vim wn.sh bash代码如下:
#!/bin/bash
Web=`ps -ef |grep nginx|grep -v grep|wc -l`
if [ $Web != 0 ];then
echo "your nginx ls running"
exit 0
else
/etc/init.d/nginx start >/dev/null 2>1&
echo "your nginx start sucessfully!"
exit 1
fi
2.crontab -e 添加定时执行:
*/3 * * * * ~/wn.sh