crontab定时检查web服务脚本

本文介绍了一段bash脚本,用于监控并自动化重启关键服务(如nginx、mysql和php-fpm),确保系统的稳定运行。
#!/bin/bash

service nginx status
if [ $? -ne 0 ];then
echo "nginx is down.try to restart now ! `date`" >> /check/check-log
service nginx start
#echo "nginx restart success `date`"
else 
echo "nginx is running well! `date`" >> /check/check-log
fi

echo "--------------------------------------"

ps -el | grep mysqld
if [ $? -ne 0 ];then
echo "mysql is down.try to restart now ! `date`" >> /check/check-log
service mysql start
#echo "mysql restart success `date`"
else
echo "mysql is running well `date`" >> /check/check-log
fi


echo "--------------------------------------"

service php5-fpm status
if [ $? -ne 0 ];then
echo "php is down.try to restart now ! `date`" >> /check/check-log
service php5-fpm start
#echo "php restart success `date`"
else
echo "php is running well `date`" >> /check/check-log
fi

转载于:https://www.cnblogs.com/lost-1987/articles/2727963.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值