forked from lingyia/kangml4.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shvpn
166 lines (154 loc) · 3.87 KB
/
shvpn
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
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
action=$1
sh_ver="0.3"
Green="\033[32m"
Red="\033[31m"
Blue="\033[36m"
Font="\033[0m"
Info="${Green}[信息]${Font}"
Error="${Red}[警告]${Font}"
Tip="${Blue}[注意]${Font}"
AD=`pwd`
kangml_Install(){
if [ -f "/bin/shvpn" ];then
echo -e "${Error} kangml守护已安装! "
echo "更新请先卸载原脚本"
sleep 1
exit
fi
echo "正在安装kangml守护脚本" && echo
cp ${AD}/shvpn /bin/shvpn
chmod 0777 /bin/shvpn
echo ' while true
do
Date=`date +%Y年%m月%d日%H时%M分%S秒`
#UDP
ps -ef | grep openvpn | grep server-udp.conf &>/dev/null
if [ "$?" -ne "0" ];then
echo "$Date kangml守护: OpenVPN-UDP异常退出 尝试启动~" >> /root/shvpn.log
systemctl restart openvpn@server-udp >/dev/null 2>&1
sleep 2
ps -ef | grep openvpn | grep server-udp.conf &>/dev/null
if [ "$?" -eq "0" ];then
echo "$Date OpenVPN-UDP进程 启动成功~">> /root/shvpn.log
else
echo "$Date OpenVPN-UDP启动失败 30秒后将重试">> /root/shvpn.log
fi
fi
#TCP
ps -ef | grep openvpn | grep server-tcp.conf &>/dev/null
if [ "$?" -ne "0" ];then
echo "$Date kangml守护: OpenVPN-TCP异常退出 尝试启动~" >> /root/shvpn.log
systemctl restart openvpn@server-tcp >/dev/null 2>&1
sleep 2
ps -ef | grep openvpn | grep server-tcp.conf &>/dev/null
if [ "$?" -eq "0" ];then
echo "$Date OpenVPN-TCP进程 启动成功~">> /root/shvpn.log
else
echo "$Date OpenVPN-TCP启动失败 30秒后将重试">> /root/shvpn.log
fi
fi
sleep 30
done' > /bin/sh_openvpn
chmod 0777 /bin/sh_openvpn
echo "kangml守护脚本安装完成" && echo
}
kangml_Uninstall(){
echo -n -e "${Error}确定卸载kangml流控守护脚本? Y/n: "
read choose
if [ "$choose" == "Y" ] || [ "$choose" == "y" ]
then
rm -rf ${AD}/shvpn
rm -rf /bin/shvpn
rm -rf /bin/sh_openvpn
kill -9 $(ps -ef|grep sh_openvpn|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ') >/dev/null 2>&1
echo " ----kangml守护脚本卸载完成"
exit
else
echo "取消"
fi
}
kangml_Run(){
ps -ef | grep sh_openvpn | grep -v "grep" &>/dev/null
if [ "$?" = "0" ];then
echo -e "$Error kangml守护已在运行 无法多次运行"
sleep 2
exit
fi
echo "----Run OpenVPN Monitor Please Wait" && echo
bash /bin/sh_openvpn &
ps -ef | grep sh_openvpn | grep -v "grep" &>/dev/null
if [ "$?" -ne "0" ];then
echo -e "${Tip} kangml OpenVPN守护 启动失败 请检查" && echo
else
echo -e "${Info} kangml OpenVPN守护 启动成功" && echo
fi
Date=`date +%Y年%m月%d日%H时%M分%S秒`
echo "${Date} Run OpenVPN Monitor" >> /root/shvpn.log
}
kangml_Stop(){
echo -n -e "${Error}确定停止kangml守护? Y/n: "
read choose
if [ "$choose" == "Y" ] || [ "$choose" == "y" ]
then
echo -e "${Info} kangml守护已停止" && echo
kill -9 $(ps -ef|grep sh_openvpn|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ') >/dev/null 2>&1
else
echo "取消"
fi
}
kangml_LOG(){
cat /root/shvpn.log
}
kangml_Update(){
echo -e "${Error} kangml守护为最新版"
}
case $action in
1)
kangml_Install
exit 0;
;;
3)
kangml_Run
exit 0;
;;
*)
echo
;;
esac
echo -e " kangml守护脚本 ${Red}[v${sh_ver}]${Font}
${Green}1.${Font} 安装 kangml守护
${Green}2.${Font} 卸载 kangml守护
————————————
${Green}3.${Font} 启动 kangml守护
${Green}4.${Font} 停止 kangml守护
${Green}5.${Font} 查看 kangml守护日志
————————————
${Green}6.${Font} 更新 kangml守护
————————————" && echo
stty erase '^H' && read -p " 请输入数字 [1-6]:" num
case "$num" in
1)
kangml_Install
;;
2)
kangml_Uninstall
;;
3)
kangml_Run
;;
4)
kangml_Stop
;;
5)
kangml_LOG
;;
6)
kangml_Update
;;
*)
echo "请输入正确数字 [1-6]"
;;
esac