-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverctl
More file actions
executable file
·188 lines (154 loc) · 5 KB
/
serverctl
File metadata and controls
executable file
·188 lines (154 loc) · 5 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
file=`basename $0`
cd `dirname $0`
ROOT_DIR=`pwd`
BIN_DIR=$ROOT_DIR/bin
BIN_NUM=`ls $BIN_DIR | grep app.bin | wc -l`
if [ "$1" != "envinit" ] && [ $BIN_NUM -gt 1 ]; then
echo "Error: more than one binfile in $BIN_DIR"
exit 1
fi
if [ "$1" != "envinit" ] && [ $BIN_NUM = 0 ];then
echo "Error: binfile is not exist in $BIN_DIR"
exit 1
fi
APPNAME=`ls $BIN_DIR | grep app.bin`
wait_for () {
try=0
#先sleep1秒, 防止启动后马上又出错退出的情况
sleep 1
while test $try -lt 5 ; do
case "$1" in
'created')
alive=`ps -ef | grep /$APPNAME | grep -v grep | awk '{print $2}'`
if [ "$alive" != "" ]; then
return 0
fi
;;
'removed')
alive=`ps -ef | grep /$APPNAME | grep -v grep | awk '{print $2}'`
if [ "$alive" = "" ]; then
return 0
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
return 1
}
case "$1" in
start)
echo "starting...."
MODE=$2
if [ "$MODE" == "" ]; then
echo "server mode is unconfigured, try start with [[http]]!"
MODE=http
fi
alive=`ps -ef | grep /$APPNAME | grep -v grep | awk '{print $2}'`
if [ "$alive" != "" ]; then
echo "process already exist! name:$APPNAME pid:$alive"
exit 1
fi
nohup $ROOT_DIR/bin/$APPNAME -f $ROOT_DIR/conf/app.conf -m $MODE 1>>$ROOT_DIR/logs/run.log 2>>$ROOT_DIR/logs/run.log &
wait_for created
if [ 0 != $? ]
then
echo "failed, please refer to logs/run.log for more detail"
exit 1
else
echo "done"
fi
;;
stop)
echo "stopping...."
BIN_NUM=`ps -ef | grep /$APPNAME | grep -v grep | wc -l`
if [ $BIN_NUM -gt 1 ]; then
echo "more than one binfile like '$APPNAME' running"
exit 1
fi
alive=`ps -ef | grep /$APPNAME | grep -v grep | awk '{print $2}'`
if [ "$alive" != "" ]; then
kill -9 $alive
if [ 0 != $? ]; then
echo "failed"
exit 1
fi
fi
echo "done"
;;
restart)
sh $file stop
echo "To start session in 2 seconds later..."
sleep 2
sh $file start $2
if [ $? != 0 ]
then
echo "failed"
exit 1
fi
;;
reload)
#热启动 Graceful restart
alive=`ps -ef | grep /$APPNAME | grep -v grep | awk '{print $2}'`
if [ "$alive" != "" ]; then
echo "kill -HUP $alive"
kill -HUP $alive
if [ 0 != $? ]; then
echo "failed"
exit 1
fi
echo "done"
else
echo "process is not exist, try start..."
sh $file start $2
fi
;;
envinit)
if test $# -lt 2
then
echo Usage: $0 envinit idc
echo eg: $0 envinit bj
exit 1
fi
IDC=$2
DIRS="logs"
EXECUTES=""
cd $ROOT_DIR/conf
if test -e app.conf
then
rm -rf app.conf
fi
if (test -s app.conf.$IDC)
then
ln -s app.conf.$IDC app.conf
echo link -s app.conf ........... OK
else
echo link -s app.conf ........... Fail
fi
cd $ROOT_DIR
for dir in $DIRS
do
if (test ! -d $dir)
then
mkdir -p $dir
fi
chmod 777 $dir
echo mkdir $dir ................ OK
done
for execute in $EXECUTES
do
sh $execute > /dev/null
if test $? -eq 0
then
echo sh $execute ................ OK
fi
done
;;
*)
echo "Usage: $0 {start|stop|restart|reload|envinit}"
exit 1
;;
esac
exit 0