-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartup.sh
executable file
·78 lines (70 loc) · 1.29 KB
/
startup.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
#!/bin/bash
LOG_DIR="./temp/"
BIN_DIR="./build/"
createLogDir()
{
if [ ! -d $LOG_DIR ]; then
mkdir $LOG_DIR
fi
}
# 结束指定进程名称的进程
shutdownProc()
{
result=`pidof $1`
if [ $? -eq 0 ]; then
kill -9 $result
fi
}
# 关闭所有服务器
stopAllServer()
{
shutdownProc "ws_connections_server" && \
shutdownProc "center_server" && \
shutdownProc "match_server" && \
shutdownProc "login_server"
}
# 启动服务
startServer()
{
cmd=$BIN_DIR$1
${cmd} >> $LOG_DIR$1".log" 2>&1 &
}
# 启动所有服务
startAllServer()
{
createLogDir
startServer "login_server"
startServer "match_server"
startServer "center_server"
startServer "ws_connections_server"
}
# 监控所有服务
monitorServer()
{
cmd="top"
for procname in "$@"
do
result=`pidof $procname`
if [ $? -eq 0 ]; then
cmd=$cmd" -p "$result
fi
done
${cmd}
}
if [ $# -ne 1 ]; then
echo "./startup.sh [start | stop | restart | monitor | clear]\n"
else
if [ $1 = "start" ]; then
startAllServer
elif [ $1 = "stop" ]; then
stopAllServer
elif [ $1 = "restart" ]; then
(stopAllServer && startAllServer)
elif [ $1 = 'monitor' ]; then
monitorServer "login_server" "match_server" "center_server" "ws_connections_server"
elif [ $1 = 'clear' ]; then
rm -rf $LOG_DIR
else
echo "not found cmd:" $1
fi
fi