您现在的位置是:网站首页> 编程资料编程资料
监控php-fpm并自动重启服务的shell脚本_linux shell_
2023-05-26
360人已围观
简介 监控php-fpm并自动重启服务的shell脚本_linux shell_
脚本代码:
复制代码 代码如下:
#!/bin/bash
#变量初始化
process="php-fpm" #进程名
startCmd="/etc/init.d/php-fpm start" #启动命令
down=0
while true
do
#取得http状态码
code=$(curl -H "Host:www.jb51.net" -m 5 -L -s -w %{http_code} http://127.0.0.1 -o /dev/null)
#当状态码返回000或者大于等于500时,计数故障到down变量
if [ $code -eq 000 -o $code -ge 500 ];then
((down++))
else
break
fi
#稍等5s
sleep 5
#判断是否连续检测三次都为故障.
if [ $down -ge 3 ];then
if [ "$(find /tmp/${process}_restart -mmin -3)" == "" ];then
#取得进程名对应的所有pid
pids=$(ps aux | grep ${process} | grep -v "grep" | awk '{print $2}')
#依次对所有pid执行kill命令
for i in $pids;do
kill -9 $i
kill -9 $i
done
#kill完pid后,启动服务
$startCmd
echo "$(date) Return code $code,${process} had been restarted" >> /tmp/${process}_restart
else
echo "$(date) ${process} not yet recovery.As it had been restarted in 2 minutes.so this time ignore." >> /tmp/${process}_not_restart
fi
break
fi
done
相关内容
- shell数组操作简明总结_linux shell_
- 使用shell脚本分析网站日志统计PV、404、500等数据_linux shell_
- 使用shell脚本采集系统cpu、内存、磁盘、网络等信息_linux shell_
- Bash Shell字符串操作小结_linux shell_
- bash批量重命名、批量更改后辍的方法_linux shell_
- Shell中处理包含空格的文件名实例_linux shell_
- shell实现FizzBuzzWhizz问题示例(拉勾网面试题)_linux shell_
- vtune自动化安装脚本_linux shell_
- 利用shell删除数据表中指定信息和字段对应的文件_linux shell_
- nginx多server日志分割脚本分享_linux shell_
