脚本代码
代码如下 | 复制代码 |
if [ -e /var/lock/subsys/502 ] then killall -9 curl 2>/dev/null killall -9 php-fpm 2>/dev/null killall -9 php-cgi 2>/dev/null service php-fpm start >/dev/null echo "[ `date +'%h %d %T'` ] PHP-FPM died with no response, all processes restarted">>log.txt else touch /var/lock/subsys/502 if [ `curl --connect-timeout 5 -I http://www.111cn.net/ 2>/dev/null | grep '502 Bad Gateway' -c` != '0' ] then killall -9 php-fpm 2>/dev/null killall -9 php-cgi 2>/dev/null service php-fpm restart >/dev/null echo "[ `date +'%h %d %T'` ] PHP-FPM died with 502 bad gateway, all processes restarted">>log.txt fi rm -f /var/lock/subsys/502 fi |
脚本需要安装了curl了,唯一需要修改的地方就是里面涉及到的网址,即通过这个地址来判定服务器是否出现故障。通过crontab每1分钟执行下这个脚本就行了。就可以实现fastcgi无法响应的时候,服务自动重启。
时间: 2024-12-03 06:58:06