-
Notifications
You must be signed in to change notification settings - Fork 5
/
admin.sh
executable file
·173 lines (140 loc) · 2.62 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
FILE_NAME="cbsignal"
if [ -n "$2" ]; then
SERVER=$2
else
SERVER="signald"
fi
SERVICE="$SERVER.service"
PREFIX="/lib/systemd/system"
BASE_DIR=$PWD
INTERVAL=2
EXEC_COMMAND="$BASE_DIR/$SERVER"
if [ -n "$3" ]; then
EXEC_COMMAND="$EXEC_COMMAND -c $3"
fi
echo "$EXEC_COMMAND"
# 命令行参数,需要手动指定
ARGS=""
function generateServiceFile()
{
echo "[Unit]
Description=cbsignal
[Service]
Type=simple
LimitCORE=infinity
LimitNOFILE=1000000
LimitNPROC=1000000
WorkingDirectory=$BASE_DIR
ExecStart=$EXEC_COMMAND
StandardOutput=null
StandardError=null
Restart=on-failure
ExecStop=
[Install]
WantedBy=multi-user.target" > ./$SERVICE
}
function deploy()
{
if [ "$SERVER" != "$FILE_NAME" ]; then
sudo cp $FILE_NAME $SERVER
fi
echo "Generate Service File"
generateServiceFile
sudo mv $SERVICE $PREFIX
sudo systemctl daemon-reload
sudo systemctl enable $SERVICE
}
function start()
{
chmod +x $FILE_NAME
sudo sysctl -w net.core.somaxconn=65535
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=8192
sudo sysctl -w fs.file-max=6000000
sudo sysctl -w fs.nr_open=6000000
ulimit -n 6000000
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"
rm -f $SERVER
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
echo "sleeping..." && sleep $INTERVAL
if [ "`pgrep $SERVER`" != "" ];then
echo "$SERVER stop failed"
exit 1
fi
rm -f $SERVER
echo "$SERVER stop succeed"
else
echo "$SERVER is not running"
fi
}
function restart()
{
stop
start
}
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 &>/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