-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathadmin.sh
157 lines (123 loc) · 2.3 KB
/
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
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
#!/bin/bash
SERVER="gosignaler"
SERVICE="$SERVER.service"
PREFIX="/lib/systemd/system"
BASE_DIR=$PWD
INTERVAL=2
# 命令行参数,需要手动指定
ARGS=""
function generateServiceFile()
{
echo "[Unit]
Description=Signaler
[Service]
Type=simple
LimitCORE=infinity
LimitNOFILE=1000000
LimitNPROC=1000000
WorkingDirectory=$BASE_DIR
ExecStart=$BASE_DIR/$SERVER
StandardOutput=null
StandardError=null
Restart=on-failure
ExecStop=
[Install]
WantedBy=multi-user.target" > ./$SERVICE
}
function deploy()
{
ulimit -n 1000000
echo "Generate Service File"
generateServiceFile
sudo cp $SERVICE $PREFIX
sudo systemctl daemon-reload
sudo systemctl enable $SERVICE
}
function start()
{
deploy
if [ "`pgrep $SERVER`" != "" ];then
echo "$SERVER already running"
exit 1
fi
sudo systemctl start $SERVICE
echo "sleeping..." && sleep $INTERVAL
# check status
if [ "`pgrep $SERVER`" == "" ];then
echo "$SERVER start failed"
exit 1
fi
echo "$SERVER start succeed"
}
function status()
{
if [ "`pgrep $SERVER`" != "" ];then
echo $SERVER is running
else
echo $SERVER is not running
fi
}
function stop()
{
if [ "`pgrep $SERVER`" != "" ];then
sudo systemctl stop $SERVICE
fi
echo "sleeping..." && sleep $INTERVAL
if [ "`pgrep $SERVER`" != "" ];then
echo "$SERVER stop failed"
exit 1
fi
echo "$SERVER stop succeed"
}
function restart()
{
sudo systemctl restart $SERVICE
echo "sleeping..." && sleep $INTERVAL
if [ "`pgrep $SERVER`" == "" ];then
echo "$SERVER start failed"
exit 1
fi
echo "$SERVER start succeed"
}
function test()
{
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
echo "$SERVER stop succeed"
ulimit -n 1000000
nohup $BASE_DIR/$SERVER -c conf/test_config.yaml &>/dev/null &
echo "sleeping..." && sleep $INTERVAL
# check status
if [ "`pgrep $SERVER -u $UID`" == "" ];then
echo "$SERVER start failed"
exit 1
fi
echo "$SERVER start succeed"
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
restart
;;
'test')
test
;;
*)
echo "usage: $0 {start|stop|restart|status}"
exit 1
;;
esac