使用教程
使用宝塔定时任务执行下方代码即可实现定时检测
PHP监控(PHP5.6举例)
#!/bin/bash
# Linux监控PHP服务,关闭就自动重启
pgrep -x php-fpm &> /dev/null
if [ $? -ne 0 ];then
/etc/init.d/php-fpm-56 restart
echo "监控到php56已停止,已执行重启计划,时间: `date "+%Y-%m-%d %H:%M:%S"` " >> /www/php_jiankong.log
fi
redis监控
#!/bin/bash
# Linux监控redis服务,关闭就自动重启
pgrep -x redis &> /dev/null
if [ $? -ne 0 ];then
/etc/init.d/redis start
fi
MySQL监控
#!/bin/bash
# Linux监控MySQL服务,关闭就自动重启
pgrep -x mysqld &> /dev/null
if [ $? -ne 0 ];then
bash /www/server/panel/script/rememory.sh
/etc/init.d/mysqld start
echo "监控到MySQL已停止,已执行重启计划,时间: `date "+%Y-%m-%d %H:%M:%S"` " >> /www/mysql_jiankong.log
fi
Nginx监控
#!/bin/bash
# Linux监控Nginx服务,关闭就自动重启
nginx_procnum=`ps -ef|grep "nginx"|grep -v grep|wc -l`
if [ $nginx_procnum -eq 0 ]
then
echo $(date) "Success,Nginx重启成功!" >> /var/log/nginxmonitor.log
/etc/init.d/nginx start
else
sleep 5
echo "Nginx正常运行中..."
fi
#!/bin/bash
Aria2监控
# 服务脚本路径
SERVICE_SCRIPT="/etc/init.d/aria2"
# 检查服务脚本是否存在
if [ ! -f $SERVICE_SCRIPT ]; then
echo "aria2 service script not found at $SERVICE_SCRIPT."
exit 1
fi
# 检查 aria2 是否在运行
$SERVICE_SCRIPT status | grep -q "Aria2 未运行"
if [ $? -eq 0 ]; then
echo "aria2 is not running, starting it now..."
sudo $SERVICE_SCRIPT start
# 再次检查 aria2 是否成功启动
$SERVICE_SCRIPT status | grep -q "Aria2 运行中"
if [ $? -eq 0 ]; then
echo "aria2 started successfully."
else
echo "Failed to start aria2."
fi
else
echo "aria2 is already running."
fi