-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.sh
executable file
·82 lines (68 loc) · 1.26 KB
/
server.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
#!/bin/bash
SERVER="High-Performance-Online-Bookstore"
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" &>/dev/null &
echo "running in background, please check ./blog/server.log for running log"
echo "Waiting for server status check..." && sleep $INTERVAL
# check status
if [ "$(pgrep $SERVER -u $UID)" == "" ];then
echo "$SERVER start failed"
exit 1
fi
echo "$SERVER start successfully"
}
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 "Waiting for server status check..." && sleep $INTERVAL
if [ "$(pgrep $SERVER -u $UID)" != "" ];then
echo "$SERVER stop failed"
exit 1
fi
echo "$SERVER stopped successfully"
}
function version()
{
ARGS="-v"
"$BASE_DIR"/$SERVER $ARGS
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
stop && start
;;
'version')
version
;;
*)
echo "usage: $0 {start|stop|restart|status|version}"
exit 1
;;
esac