nginx奔溃自动重启Shell脚本

# vi /usr/local/nginx/sbin/nginx_restart.sh 贴入一下代码:

#!/bin/bash

#www.xmsolink.com

#Monitor nginx service

#check root user

if [ $(id -u) != "0" ]

then

echo "Not the root user! Try using sudo command!"

exit 1

fi

netstat -anop | grep 0.0.0.0:80

if [ $? -ne 1 ]

then

exit

fi

echo $(date +%T%n%F)" Restart nginx Services " >> nginx.log

#/usr/local/nginx/sbin/nginx -s quit

/usr/local/nginx/sbin/nginx

其实主要内容就是

检查是否是root用户

检查监听服务程序的端口是否还正常

对运行不正常的进程进行重启

:wq! 保存退出,chmod +w nginx_restart.sh 授权为可自行脚本

加入Linux crontab自动任务里即可:

1

*/5 * * * * sh /usr/local/nginx/sbin/nginx_restart.sh

# /etc/init.d/crond reload 刷新生效

————————————————

版权声明:本文为CSDN博主「hongping626」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/hongping626/article/details/84428589