forked from FunctionClub/SSR-Bash-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.sh
288 lines (271 loc) · 8.61 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#Check Root
[ $(id -u) != "0" ] && { echo "Error: You must be root to run this script"; exit 1; }
#CheckOS
if [ -n "$(grep 'Aliyun Linux release' /etc/issue)" -o -e /etc/redhat-release ];then
OS=CentOS
[ -n "$(grep ' 7\.' /etc/redhat-release)" ] && CentOS_RHEL_version=7
[ -n "$(grep ' 6\.' /etc/redhat-release)" -o -n "$(grep 'Aliyun Linux release6 15' /etc/issue)" ] && CentOS_RHEL_version=6
[ -n "$(grep ' 5\.' /etc/redhat-release)" -o -n "$(grep 'Aliyun Linux release5' /etc/issue)" ] && CentOS_RHEL_version=5
elif [ -n "$(grep 'Amazon Linux AMI release' /etc/issue)" -o -e /etc/system-release ];then
OS=CentOS
CentOS_RHEL_version=6
elif [ -n "$(grep bian /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Debian' ];then
OS=Debian
[ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; }
Debian_version=$(lsb_release -sr | awk -F. '{print $1}')
elif [ -n "$(grep Deepin /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Deepin' ];then
OS=Debian
[ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; }
Debian_version=$(lsb_release -sr | awk -F. '{print $1}')
elif [ -n "$(grep Ubuntu /etc/issue)" -o "$(lsb_release -is 2>/dev/null)" == 'Ubuntu' -o -n "$(grep 'Linux Mint' /etc/issue)" ];then
OS=Ubuntu
[ ! -e "$(which lsb_release)" ] && { apt-get -y update; apt-get -y install lsb-release; clear; }
Ubuntu_version=$(lsb_release -sr | awk -F. '{print $1}')
[ -n "$(grep 'Linux Mint 18' /etc/issue)" ] && Ubuntu_version=16
else
echo "Does not support this OS, Please contact the author! "
kill -9 $$
fi
servercheck(){
echo "你要做什么?"
echo ""
echo "1.启动服务"
echo "2.停止服务"
echo "3.重启服务"
echo "4.查看日志"
echo "5.重新配置"
while :; do echo
read -p "请选择: " serverch
[ -z "$serverch" ] && break
if [[ ! $serverch =~ ^[1-5]$ ]]; then
echo "输入错误! 请输入正确的数字!"
else
break
fi
done
if [[ $serverch == 1 ]];then
PID=$(ps -ef |grep -v grep | grep "bash" | grep "servercheck.sh" | grep "run" | awk '{print $2}')
if [[ ! -z ${PID} ]];then
echo "该服务已经启动,无需操作"
servercheck
else
nohup bash /usr/local/SSR-Bash-Python/servercheck.sh run 2>/dev/null &
echo "服务已启动"
servercheck
fi
fi
if [[ $serverch == 2 ]];then
PID=$(ps -ef |grep -v grep | grep "bash" | grep "servercheck.sh" | grep "run" | awk '{print $2}')
if [[ -z ${PID} ]];then
echo "该进程不存在,你无法停止服务"
servercheck
else
bash /usr/local/SSR-Bash-Python/servercheck.sh stop
servercheck
fi
fi
if [[ $serverch == 3 ]];then
PID=$(ps -ef |grep -v grep | grep "bash" | grep "servercheck.sh" | grep "run" | awk '{print $2}')
if [[ -z ${PID} ]];then
echo "该进程不存在,你无法重启服务"
servercheck
else
bash /usr/local/SSR-Bash-Python/servercheck.sh stop
nohup bash /usr/local/SSR-Bash-Python/servercheck.sh run 2>/dev/null &
echo "重启大成功"
servercheck
fi
fi
if [[ $serverch == 4 ]];then
if [[ -e /usr/local/SSR-Bash-Python/check.log ]];then
cat /usr/local/SSR-Bash-Python/check.log
servercheck
else
echo "没有找到配置文件!"
servercheck
fi
fi
if [[ $serverch == 5 ]];then
echo "你将丢弃所有的日志记录数据,并进行重新配置[Y/N]"
read yn
if [[ $yn == [yY] ]];then
PID=$(ps -ef |grep -v grep | grep "bash" | grep "servercheck.sh" | grep "run" | awk '{print $2}')
if [[ ! -z ${PID} ]];then
kill -9 ${PID}
fi
bash /usr/local/SSR-Bash-Python/servercheck.sh reconf
echo "完毕请启动服务"
echo ""
servercheck
fi
fi
}
echo ""
echo "1.启动服务"
echo "2.停止服务"
echo "3.重启服务"
echo "4.查看日志"
echo "5.运行状态"
echo "6.修改DNS"
echo "7.开启用户WEB面板"
echo "8.关闭用户WEB面板"
echo "9.开/关服务端开机启动"
echo "10.服务器自动巡检系统"
echo "11.服务器网络与IO测速"
echo "直接回车返回上级菜单"
while :; do echo
read -p "请选择: " serverc
[ -z "$serverc" ] && ssr && break
if [[ ! $serverc =~ ^[1-9]$ ]]; then
if [[ $serverc == 10 ]]||[[ $serverc == 11 ]]; then
break
fi
echo "输入错误! 请输入正确的数字!"
else
break
fi
done
if [[ $serverc == 1 ]];then
bash /usr/local/shadowsocksr/logrun.sh
iptables-restore < /etc/iptables.up.rules
clear
echo "ShadowsocksR服务器已启动"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 2 ]];then
bash /usr/local/shadowsocksr/stop.sh
echo "ShadowsocksR服务器已停止"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 3 ]];then
bash /usr/local/shadowsocksr/stop.sh
bash /usr/local/shadowsocksr/logrun.sh
iptables-restore < /etc/iptables.up.rules
clear
echo "ShadowsocksR服务器已重启"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 4 ]];then
trap 'bash /usr/local/SSR-Bash-Python/server.sh' 2
bash /usr/local/shadowsocksr/tail.sh
fi
if [[ $serverc == 5 ]];then
ps aux|grep server.py
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 6 ]];then
read -p "输入主要 DNS 服务器: " ifdns1
read -p "输入次要 DNS 服务器: " ifdns2
echo "nameserver $ifdns1" > /etc/resolv.conf
echo "nameserver $ifdns2" >> /etc/resolv.conf
echo "DNS 服务器已设置为 $ifdns1 $ifdns2"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 7 ]];then
P_V=`python -V 2>&1 | awk '{print $2}'`
P_V1=`python -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1}'`
if [[ ${P_V1} == 3 ]];then
echo "你当前的python版本不支持此功能"
echo "当前版本:${P_V} ,请降级至2.x版本"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
exit 1
fi
while :; do echo
read -p "请输入自定义的WEB端口:" cgiport
if [[ "$cgiport" =~ ^(-?|\+?)[0-9]+(\.?[0-9]+)?$ ]];then
break
else
echo 'Input Error!'
fi
done
#Set Firewalls
if [[ ${OS} =~ ^Ubuntu$|^Debian$ ]];then
iptables-restore < /etc/iptables.up.rules
clear
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport $cgiport -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport $cgiport -j ACCEPT
iptables-save > /etc/iptables.up.rules
fi
if [[ ${OS} == CentOS ]];then
if [[ $CentOS_RHEL_version == 7 ]];then
iptables-restore < /etc/iptables.up.rules
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport $cgiport -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport $cgiport -j ACCEPT
iptables-save > /etc/iptables.up.rules
else
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport $cgiport -j ACCEPT
iptables -I INPUT -m state --state NEW -m udp -p udp --dport $cgiport -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
fi
fi
#Get IP
ip=`curl -m 10 -s http://members.3322.org/dyndns/getip`
clear
chmod -R 777 /usr/local/SSR-Bash-Python
cd /usr/local/SSR-Bash-Python/www
screen -dmS webcgi python -m CGIHTTPServer $cgiport
echo "WEB服务启动成功,请访问 http://${ip}:$cgiport"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 8 ]];then
cgipid=$(ps -ef|grep 'webcgi' |grep -v grep |awk '{print $2}')
kill -9 $cgipid
screen -wipe
clear
echo "WEB服务已关闭!"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 9 ]];then
if [[ ${OS} == Ubuntu || ${OS} == Debian ]];then
cat >/etc/init.d/ssr-bash-python <<EOF
#!/bin/sh
### BEGIN INIT INFO
# Provides: SSR-Bash_python
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SSR-Bash-Python
# Description: SSR-Bash-Python
### END INIT INFO
iptables-restore < /etc/iptables.up.rules
bash /usr/local/shadowsocksr/logrun.sh
EOF
chmod 755 /etc/init.d/ssr-bash-python
chmod +x /etc/init.d/ssr-bash-python
cd /etc/init.d
update-rc.d ssr-bash-python defaults 95
fi
if [[ ${OS} == CentOS ]];then
echo "
iptables-restore < /etc/iptables.up.rules
bash /usr/local/shadowsocksr/logrun.sh
" > /etc/rc.d/init.d/ssr-bash-python
chmod +x /etc/rc.d/init.d/ssr-bash-python
echo "/etc/rc.d/init.d/ssr-bash-python" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
fi
echo "开机启动设置完成!"
echo ""
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 10 ]];then
servercheck
bash /usr/local/SSR-Bash-Python/server.sh
fi
if [[ $serverc == 11 ]];then
bash /usr/local/SSR-Bash-Python/ZBench-CN.sh
bash /usr/local/SSR-Bash-Python/server.sh
fi