linux Web服务程序监控shell脚本

来源:互联网 发布:各类化验单制作软件 编辑:程序博客网 时间:2024/04/30 06:39
#!/bin/bash
pgrep=/usr/bin/pgrep
killall=/usr/bin/killall
nohup=/usr/bin/nohup
curl=/usr/bin/curl
sleep=/bin/sleep
service=CC
host=127.0.0.1
port=8080
count=0
max=4
check_web(){
    while :
    do
    check_pid
    result=$($curl http://$host:$port/android_ping)
    echo "result:$result"
    if [ "$result" ] ; then
           count=0
        else
        let count+=1
        echo "exception:$count"
        if [ $count -gt $max ] ; then
            $killall -9 $service && $nohup /home/CC/CC $port &
            count=0
        fi
        fi    
        $sleep 3
    done
}
check_pid(){
    if [ -n "`$pgrep $service`" ] ; then
        echo "CC service was already started by another way"
    else
        echo "CC service was not started"
    echo "Starting service ..."
    $nohup /home/CC/CC $port &
    echo "CC service was exited!"
    fi
}
check_web
0 0