-
Notifications
You must be signed in to change notification settings - Fork 0
/
daemon.sh
51 lines (45 loc) · 1.63 KB
/
daemon.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /bin/sh
PRO_NAME_EMQX=/data/emqx
PRO_NAME_WIFIDOG=/data/wifidog
while true ; do
# ps to get $PRO_NAME_EMQX
NUM=`ps aux | grep -w ${PRO_NAME_EMQX} | grep -v grep |wc -l`
#echo $NUM
# less than 1,restart process
if [ "${NUM}" -lt "1" ];then
echo "${PRO_NAME_EMQX} was killed"
${PRO_NAME_EMQX} -d
# more than 1,kill all to restart
elif [ "${NUM}" -gt "1" ];then
echo "more than 1 ${PRO_NAME_EMQX},killall ${PRO_NAME_EMQX}"
killall -9 $PRO_NAME_EMQX
${PRO_NAME_EMQX} -d
fi
#kill zombi
NUM_STAT=`ps aux | grep -w ${PRO_NAME_EMQX} | grep T | grep -v grep | wc -l`
if [ "${NUM_STAT}" -gt "0" ];then
killall -9 ${PRO_NAME_EMQX}
${PRO_NAME_EMQX} -d
fi
# ps to get $PRO_NAME_WIFIDOG
NUM_WIFIDOG=`ps aux | grep -w ${PRO_NAME_WIFIDOG} | grep -v grep |wc -l`
#echo $NUM_WIFIDOG
# less than 1,restart process
if [ "${NUM_WIFIDOG}" -lt "1" ];then
echo "${PRO_NAME_WIFIDOG} was killed"
${PRO_NAME_WIFIDOG} -d 7 -c /usr/local/etc/wifidog.conf
# more than 1,kill all to restart
elif [ "${NUM_WIFIDOG}" -gt "1" ];then
echo "more than 1 ${PRO_NAME_WIFIDOG},killall ${PRO_NAME_WIFIDOG}"
killall -9 $PRO_NAME_WIFIDOG
${PRO_NAME_WIFIDOG} -d 7 -c /usr/local/etc/wifidog.conf
fi
#kill zombi
NUM_STAT_WIFIDOG=`ps aux | grep -w ${PRO_NAME_WIFIDOG} | grep T | grep -v grep | wc -l`
if [ "${NUM_STAT_WIFIDOG}" -gt "0" ];then
killall -9 ${PRO_NAME_WIFIDOG}
${PRO_NAME_WIFIDOG} -d 7 -c /usr/local/etc/wifidog.conf
fi
sleep 5s
done
exit 0