LNMP定时自动检测502 Bad Gateway错误并重启PHP

简单的脚本,用来监控php的 502 Bad Getway 并自动重启php服务进程,下面记录一下具体的脚本内容,比如将文件命名为 check_php.sh ,放在 /root 目录中

#!/bin/bash
MY_URL="https://jiloc.com/"
RESULT=`curl -I $MY_URL|grep "HTTP/1.1 502"`
if [ -n "$RESULT" ]; then
    /etc/init.d/php-fpm restart
fi

给予可执行权限:

chmod +x /root/check_php.sh

通过 crontab 设置自动运行:

crontab -e

crontab里写入如下内容

*/5 * * * * /root/check_php.sh

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注