lnmp宕机网站出现502 Bad Gateway错误自动重启php-fpm脚本

作者: 站长 上传时间: 浏览: N/A 下载: N/A 格式: N/A 评分: N/A

#!/bin/bash

CheckURL="https://xiaohost.com"

STATUS_CODE=`curl -o /dev/null -m 10 --connect-timeout 10 -s -w %{http_code} $CheckURL`
#echo "$CheckURL Status Code:\t$STATUS_CODE"
if [ "$STATUS_CODE" = "502" ]; then
/etc/init.d/php-fpm restart
fi

将上面的CheckURL=”https://xiaohost.com”里面的网址修改为你的网址,然后保存为xxx.sh文件

添加shell脚本执行权限
chmod +x /root/xxx.sh
添加定时任务(5分钟检查一次)
crontab -e

*/5 * * * * /bin/bash /root/xxx.sh

service crond restart

补充:其实军哥的lnmp一键包里已经有这个脚本了,只需要修改为自己的网址,然后添加定时任务crontab即可
脚本路径/root/lnmp1.4/tools/check502.sh

Leave a Comment