-
Notifications
You must be signed in to change notification settings - Fork 19
/
admin.sh
68 lines (57 loc) · 959 Bytes
/
admin.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
#!/bin/bash
SERVER="apiserver"
BASE_DIR=$PWD
INTERVAL=2
# 命令行参数,需要手动指定
ARGS=""
function start()
{
if [ "`pgrep $SERVER -u $UID`" != "" ];then
echo "$SERVER already running"
exit 1
fi
nohup $BASE_DIR/$SERVER $ARGS server &>/dev/null &
echo "sleeping..." && sleep $INTERVAL
# check status
if [ "`pgrep $SERVER -u $UID`" == "" ];then
echo "$SERVER start failed"
exit 1
fi
}
function status()
{
if [ "`pgrep $SERVER -u $UID`" != "" ];then
echo $SERVER is running
else
echo $SERVER is not running
fi
}
function stop()
{
if [ "`pgrep $SERVER -u $UID`" != "" ];then
kill -9 `pgrep $SERVER -u $UID`
fi
echo "sleeping..." && sleep $INTERVAL
if [ "`pgrep $SERVER -u $UID`" != "" ];then
echo "$SERVER stop failed"
exit 1
fi
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
stop && start
;;
*)
echo "usage: $0 {start|stop|restart|status}"
exit 1
;;
esac