点击登录
  • 欢迎访问无限星辰技术博客,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏无限星辰吧
  • 好集导航开张了,传送门:好集导航

centos 自动重启 php-fpm 的脚本

LINUX服务器 crx349 7848次浏览 0个评论 扫描二维码
#!/bin/bash
##
#Program:check502
##
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# web_URL #
site=测试网页地址
# mailto #
receiver_email="接受邮箱"
sender_email="发送邮箱"
recevier="Admin"
sender="Zeroto"
# email #
function run_502(){
    sendmail -t <<EOF
From: $sender <$sender_email>
To: $receiver <$receiver_email>
Subject: VPS has encountered a 502 error!
----------------------------------------

The VPS has encountered a 502 error, and it has been handled.
Congratulations! The VPS runs well now!

----------------------------------------
EOF
}
function restart_error(){
    sendmail -t <<EOF
From: $sender <$sender_email>
To: $receiver <$receiver_email>
Subject: A terrible error occurred to the VPS.
----------------------------------------

The VPS has encountered an error, but it failed to restart php-fpm.
The information has already saved to /home/wwwlogs/502log.log.

----------------------------------------
EOF
}
# test #
stat=`curl -I $site | head -1 | cut -d ' ' -f2`
if [ $stat == "502" ]; then
    service php-fpm restart 2>>/home/wwwlogs/502log.log
    temp=`echo $?`
    if [ $temp != "0" ]; then
        restart_error
    else
        run_502
    fi
fi
exit 0

1测试网页必须在同一个服务器上,可以自己创建一个php:

<?php
echo "This is a test page!";
?>

脚本保存成 /home/check502.sh ,并授权 chmod 755 。
添加定时任务,每十分钟检查一次状态并写记录。crontab –l 检查任务添加。
*/10 * * * * (/home/check502.sh >> /home/wwwlogs/502log.log)


无限星辰 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明centos 自动重启 php-fpm 的脚本!
喜欢 (1)
[]
分享 (0)

您必须 登录 才能发表评论!