This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
wts.sh
executable file
·118 lines (108 loc) · 2.92 KB
/
wts.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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
TIME_STAMP=$(date +%Y-%m-%d-%H-%M-%S)
SERVICE_DIR=$(cd `dirname $0`; pwd)
SERVICE_LOG_DIR="$SERVICE_DIR/log/"
SERVICE_LOG_FILE="$SERVICE_LOG_DIR/$TIME_STAMP.log"
service_msg(){
echo "* $*"
}
mkdir -p $SERVICE_LOG_DIR
if [ $? -ne 0 ]; then
service_msg "Fail to create service log folder"
exit 1
fi
PYTHON_VERSION=`python -V 2>&1`
MAIN_VERSION=`echo $PYTHON_VERSION | cut -c 8-11`
if [ "${MAIN_VERSION}" != "2.7." ]; then
service_msg "Wrong Python version, WTS need Python 2.7+(but not Python 3.x)"
exit 1
fi
check_service(){
service_process=`ps -ef|grep 'wts-serve.py'|grep -v grep|awk '{print $2}'`
if [ -z "$service_process" ]; then
return 1
fi
return 0
}
kill_service(){
kill -9 `ps -ef|grep 'wts-serve.py'|grep -v grep|awk '{print $2}'`
return 0
}
start_service(){
cd $SERVICE_DIR
python wts-serve.py 2> $SERVICE_LOG_FILE &
cd - 1> /dev/null 2>&1
sleep 1
check_service
if [ $? -ne 0 ]; then
service_msg "Fail to start service"
return 1
fi
return 0
}
stop_service(){
check_service
if [ $? -eq 0 ]; then
kill_service
sleep 1
check_service
if [ $? -eq 0 ]; then
service_msg "Fail to stop service"
return 1
fi
fi
return 0
}
update_service(){
cd $SERVICE_DIR
git pull
if [ $? -ne 0 ]; then
service_msg "Fail to update service source code"
return 1
fi
cd - 1> /dev/null 2>&1
sync
return 0
}
case $1 in
stop)
service_msg "Stoping service ..."
stop_service
if [ $? -ne 0 ]; then
exit 1
fi
;;
start | restart)
service_msg "Stoping service ..."
stop_service
if [ $? -ne 0 ]; then
exit 1
fi
service_msg "Starting service ..."
start_service
if [ $? -ne 0 ]; then
exit 1
fi
;;
upgrade)
service_msg "Stoping service ..."
stop_service
if [ $? -ne 0 ]; then
exit 1
fi
service_msg "Updating service ..."
update_service
if [ $? -ne 0 ]; then
exit 1
fi
service_msg "Starting service ..."
start_service
if [ $? -ne 0 ]; then
exit 1
fi
;;
*)
service_msg "Usage: wts.sh {start|restart|stop|upgrade}"
exit 1
;;
esac