进程启停自定义脚本

进程启停自定义脚本

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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/bash 

usage()
{
echo "Usage: $0 {start|stop|restart|status} [lineid]"
}

suffix=_stable
LINELIST="1 2 3 4 5 6"
LINK_NUM=3
UNAMED_ACTIVE=0
PROGRAME_ACTIVE=0

start_line()
{
IDLIST=$LINELIST
if [ ! -z $1 ]; then
IDLIST=$1
fi
SELFID=`id -u`
cd gamed
for LN in $IDLIST
do
PIDS=`pgrep -u $SELFID -f "./gs$suffix gs.conf gmserver.conf config/gsalias$LN.conf"`
if [ -z "$PIDS" ]; then
echo start line $LN
nohup setsid ./gs$suffix gs.conf gmserver.conf config/gsalias$LN.conf &>../logs/game$LN.log &
#nohup setsid ./gs_asan$suffix gs.conf gmserver.conf config/gsalias$LN.conf &>../logs/game$LN.log &
else
echo line $LN is already running
fi
sleep 1
done
cd ..
}



status()
{
PROGRAME_ACTIVE=0;
for LN in $LINELIST
do
check_line $LN
PROGRAME_ACTIVE=`expr $PROGRAME_ACTIVE + $?`;
done
check_process zlogd
PROGRAME_ACTIVE=`expr $PROGRAME_ACTIVE + $?`;
check_process gdeliveryd
PROGRAME_ACTIVE=`expr $PROGRAME_ACTIVE + $?`;
check_process gamedbd
PROGRAME_ACTIVE=`expr $PROGRAME_ACTIVE + $?`;
# check_process gonlineinfod
# PROGRAME_ACTIVE=`expr $PROGRAME_ACTIVE + $?`;
if [ $UNAMED_ACTIVE -eq 1 ]; then
check_process unamed
PROGRAME_ACTIVE=`expr $PROGRAME_ACTIVE + $?`;
fi
check_process glinkd
PROGRAME_ACTIVE=`expr $PROGRAME_ACTIVE + $?`;
return $PROGRAME_ACTIVE;
}

check_process()
{
SELFID=`id -u`
PIDS=`pgrep -u $SELFID -f "./$1$suffix.*$1.conf"`
if [ ! -z "$PIDS" ]; then
echo service $1 is running, pid $PIDS
return 1;
else
echo service $1 is stopped.
return 0;
fi
}

exists()
{
SELFID=`id -u`
PIDS=`pgrep -u $SELFID -f "./$1$suffix.*$1.conf"`
if [ ! -z "$PIDS" ]; then
echo service $1 is running, pid $PIDS
return 1
fi
return 0
}

kill_process()
{
NAME=$1
SIG=$2
SELFID=`id -u`
PIDS=`pgrep -u $SELFID -f "./$NAME$suffix.*$NAME.conf"`
if [ -n "$PIDS" ]; then
for PID in $PIDS
do
kill -$SIG $PID
echo service $NAME pid $PID is killed.
done
else
echo service $NAME is not running.
fi
}

check_line()
{
SELFID=`id -u`
LN=$1
PIDS=`pgrep -u $SELFID -f "./gs$suffix gs.conf gmserver.conf config/gsalias$LN.conf"`
if [ ! -z "$PIDS" ]; then
echo line $LN is running, pid $PIDS
return 1;
else
echo line $LN is stopped.
return 0;
fi
}

kill_line()
{
SELFID=`id -u`
LN=$1
PIDS=`pgrep -u $SELFID -f "./gs$suffix gs.conf gmserver.conf config/gsalias$LN.conf"`
if [ -n "$PIDS" ]; then
for PID in $PIDS
do
kill -9 $PID
echo line $LN pid $PID is killed.
done
else
echo line $LN is not running.
fi
}

kill_grc()
{
kill -9 $(ps -ef|grep grc.jar$suffix |grep -v grep|awk '{print $2}')
}

start_grc()
{
cd grc
rm -rf ./lib
unzip lib.zip
rm -rf grc.jar$suffix
cp grc.jar grc.jar$suffix
nohup java -jar ./grc.jar$suffix -Xms1G -Xmx2G >>/dev/null 2>>/tmp/grc.err$suffix &
cd ..
}

start()
{
mkdir -p logs
export LD_LIBRARY_PATH=.:../../lib
ulimit -c unlimited
ulimit -n 4096

if [ ! -z $1 ]; then
start_line $1
return
fi

exists zlogd
if [ $? -eq 0 ]; then
cd zlogd
echo 'start zlogd service'
nohup setsid ./zlogd$suffix zlogd.conf &>/dev/null &
sleep 2
cd ..
fi

exists gdeliveryd
if [ $? -eq 0 ]; then
cd gdeliveryd
echo 'start DS service'
nohup setsid ./gdeliveryd$suffix gdeliveryd.conf &>../logs/gdelivery.log &
#nohup setsid valgrind --log-file=../logs/valgrind_ds.log ./gdeliveryd$suffix gdeliveryd.conf &>../logs/gdelivery.log &
cd ..
fi

exists glinkd
if [ $? -eq 0 ]; then
cd glinkd
echo 'start LS service'
nohup setsid ./glinkd$suffix --ccs glinkd.conf &>../logs/glinkd.ccs.log &
for ((i = 1; i <= $LINK_NUM; i++))
do
nohup setsid ./glinkd$suffix --cls -i $i glinkd.conf &>../logs/glinkd.cls$i.log &
done
cd ..
fi

exists gamedbd
if [ $? -eq 0 ]; then
cd gamedbd
echo 'start DB service'
nohup setsid ./gamedbd$suffix gamedbd.conf &>../logs/gamedbd.log &
cd ..
fi

if [ $UNAMED_ACTIVE -eq 1 ]; then
exists unamed
if [ $? -eq 0 ]; then
cd unamed
echo 'start unamed service'
nohup setsid ./unamed$suffix unamed.conf &>../logs/unamed.log &
cd ..
fi
fi

# exists gonlineinfod
# if [ $? -eq 0 ]; then
# cd gonlineinfod
# echo 'start OL service'
# nohup setsid ./gonlineinfod$suffix gonlineinfod.conf &>../logs/gonlineinfod.log &
# cd ..
# fi

#start_grc

start_line
}

stop()
{
if [ ! -z $1 ]; then
kill_line $1
return
fi
#kill_grc
kill_process glinkd KILL
kill_process gdeliveryd KILL
kill_process gamedbd USR1
#kill_process gonlineinfod KILL
if [ $UNAMED_ACTIVE -eq 1 ]; then
kill_process unamed USR1
fi
for LN in $LINELIST
do
kill_line $LN
done
kill_process zlogd KILL
}

wait()
{
for (( i=0; i<5; i++))
do
echo -n "."
sleep 0.2
done
echo "."
}

restart()
{
stop $1
if [ ! -z $1 ]; then
wait
else
PROGRAME_ACTIVE=1;
while [ "$PROGRAME_ACTIVE" != "0" ]
do
wait
status
echo $PROGRAME_ACTIVE program is running
done
fi
start $1
wait
echo 'task accomplished'
}

case $1 in
start)
start $2
;;
stop)
stop $2
;;
restart)
restart $2
;;
status)
status
;;
*)
usage
;;
esac

本文标题:进程启停自定义脚本

文章作者:shuke

发布时间:2020年04月20日 - 15:04

最后更新:2020年04月20日 - 15:04

原始链接:https://shuke163.github.io/2020/04/20/%E8%BF%9B%E7%A8%8B%E5%90%AF%E5%81%9C%E8%87%AA%E5%AE%9A%E4%B9%89%E8%84%9A%E6%9C%AC/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------本文结束感谢您的阅读-------------

本文标题:进程启停自定义脚本

文章作者:shuke

发布时间:2020年04月20日 - 15:04

最后更新:2020年04月20日 - 15:04

原始链接:https://shuke163.github.io/2020/04/20/%E8%BF%9B%E7%A8%8B%E5%90%AF%E5%81%9C%E8%87%AA%E5%AE%9A%E4%B9%89%E8%84%9A%E6%9C%AC/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

0%