linux apache 自动监护脚本

 1 首先安装curl

yum install curl

2 编写shell

vi restart_apache.sh

写入一下内容

#!/bin/bash
URL="http://127.0.0.1/"
curlit()
{
curl --connect-timeout 35 --max-time 40 --head --silent "$URL" | grep ‘200‘
}

doit()
{
if ! curlit; then
sleep 20
top -n 1 -b >> /var/log/restart_log/apache.log
/etc/init.d/httpd stop
sleep 2
/etc/init.d/httpd start > /dev/null
echo $(date) "Apache Restart" >> /var/log/restart_log/re_apache.log
sleep 30
if ! curlit; then
echo $(date) "Failed! Now Reboot Computer!" >> /var/log/restart_log/rebot_apache.log
reboot
fi
sleep 180
fi
}

sleep 300
while true; do
doit > /dev/null
sleep 10
done

3 把restart_apache.sh 加入到定时计划任务

crontab -e

写入以下内容 

  */1 * * * * /home/restart_apache.sh  //一分钟执行一次

crontab -l 查看 是否加入成功

4 chmod +x  restart_apache.sh 表示可以执行

5 测试 把apache停止  然后测试 过一会看看apache是否已经自动启动

linux apache 自动监护脚本,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。