#!/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 "
1 | 1` |
$pgrep $service
1 | 1` |
" ] ; 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