forked from ToyoDAdoubi/doubi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_status_client_debian
81 lines (78 loc) · 2.06 KB
/
server_status_client_debian
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
### BEGIN INIT INFO
# Provides: ServerStatus-Client
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Server status monitoring
# Description: Start or stop the ServerStatus Client server
### END INIT INFO
NAME="ServerStatus Client"
NAME_BIN="status-client.py"
SERVER_BIN="/usr/local/ServerStatus"
BIN="/usr/local/ServerStatus/status-client.py"
Info_font_prefix="\033[32m" && Error_font_prefix="\033[31m" && Info_background_prefix="\033[42;37m" && Error_background_prefix="\033[41;37m" && Font_suffix="\033[0m"
RETVAL=0
check_running(){
PID=`ps -ef |grep "${NAME_BIN}" |grep -v "grep" |grep -v "init.d" |grep -v "service" |awk '{print $2}'`
if [[ ! -z ${PID} ]]; then
return 0
else
return 1
fi
}
do_start(){
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info_font_prefix}[信息]${Font_suffix} $NAME (PID ${PID}) 正在运行..." && exit 0
else
cd "${SERVER_BIN}"
nohup python "$BIN" > /tmp/serverstatus_client.log 2>&1 &
sleep 2s
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info_font_prefix}[信息]${Font_suffix} $NAME 启动成功 !"
else
echo -e "${Error_font_prefix}[错误]${Font_suffix} $NAME 启动失败 !"
fi
fi
}
do_stop(){
check_running
if [[ $? -eq 0 ]]; then
kill -9 ${PID}
RETVAL=$?
if [[ $RETVAL -eq 0 ]]; then
echo -e "${Info_font_prefix}[信息]${Font_suffix} $NAME 停止成功 !"
else
echo -e "${Error_font_prefix}[错误]${Font_suffix}$NAME 停止失败 !"
fi
else
echo -e "${Info_font_prefix}[信息]${Font_suffix} $NAME 未运行 !"
RETVAL=1
fi
}
do_status(){
check_running
if [[ $? -eq 0 ]]; then
echo -e "${Info_font_prefix}[信息]${Font_suffix} $NAME (PID ${PID}) 正在运行..."
else
echo -e "${Info_font_prefix}[信息]${Font_suffix} $NAME 未运行 !"
RETVAL=1
fi
}
do_restart(){
do_stop
do_start
}
case "$1" in
start|stop|restart|status)
do_$1
;;
*)
echo "使用方法: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL