apachemonitor.sh

回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

apachemonitor.sh

文章 yehlu »

/etc/rc.d/rc.local
./root/apachemonitor.sh &
cat apachemonitor.sh

代碼: 選擇全部

#!/bin/bash
#source:http://www.arefly.com/linux-apache-monitor/
URL="http://www.551.com.tw"
curlit() {
    curl --connect-timeout 15 --max-time 20 --head --silent "$URL" | grep '200'
}
doit() {
echo "CURLIT"
    if ! curlit; then

        sleep 20
        top -n 1 -b >> /var/log/apachemonitor.log
        /usr/bin/killall -9 httpd
        sleep 2
        /etc/init.d/httpd start > /dev/null
        echo $(date) "Apache Restart" >> /var/log/apachemonitor.log
        sleep 30

        if ! curlit; then
            echo $(date) "Restart Fail! Reboot Computer!" >> /var/log/apachemonitor.log
            reboot
        fi
        sleep 180
    fi
}
echo $(date) "Start!" >> /var/log/apachemonitor.log
sleep 300
while true; do
    doit > /dev/null
    sleep 10
done
回覆文章

回到「Linux」