-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfas_bak
executable file
·135 lines (123 loc) · 3.24 KB
/
fas_bak
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
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
sh_ver="1.0"
Green="\033[32m"
Red="\033[31m"
Blue="\033[36m"
Font="\033[0m"
Info="${Green}[信息]${Font}"
Error="${Red}[警告]${Font}"
Tip="${Blue}[注意]${Font}"
AD=`pwd`
Fas_Install(){
if [ -f "/bin/fas" ];then
echo -e "${Error} FAS守护已安装! "
echo "更新请先卸载原脚本"
sleep 1
exit
fi
echo " ----正在安装FAS守护脚本" && echo
cp ${AD}/fas /bin/fas
chmod 0777 /bin/fas
echo ' while true
do
netstat -lnup | grep openvpn &>/dev/null
if [ "$?" -ne "0" ];then
Date=`date +%Y年%m月%d日%H时%M分%S秒`
echo "$Date FAS守护: OpenVPN异常退出 尝试启动~" >> /root/fas.log
systemctl restart openvpn@server-udp >/dev/null 2>&1
sleep 2
netstat -lnup | grep openvpn &>/dev/null
if [ "$?" -eq "0" ];then
Date=`date +%Y年%m月%d日%H时%M分%S秒`
echo "$Date FAS守护: OpenVPN进程 启动成功~">> /root/fas.log
else
Date=`date +%Y年%m月%d日%H时%M分%S秒`
echo "$Date FAS守护: OpenVPN启动失败 10秒后将重试">> /root/fas.log
fi
fi
sleep 10
done' > /bin/fas_openvpn
}
Fas_Uninstall(){
echo -n -e "${Error}确定卸载FAS流控守护脚本? Y/n: "
read choose
if [ "$choose" == "Y" ] || [ "$choose" == "y" ]
then
kill -9 $(ps -ef|grep fas_openvpn|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ') >/dev/null 2>&1
kill -9 $(ps -ef|grep fas_mysql|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ') >/dev/null 2>&1
rm -rf ${AD}/fas
rm -rf /bin/fas
rm -rf /bin/fas_openvpn
rm -rf /bin/fas_mysql
echo " ----Fas守护脚本卸载完成"
exit
else
echo "取消"
fi
}
Fas_Run(){
ps -ef | grep fas_openvpn | grep -v "grep" &>/dev/null
if [ "$?" = "0" ];then
echo -e "$Error FAS守护已在运行 无法多次运行"
sleep 2
exit
fi
echo "----Run OpenVPN Monitor Please Wait" && echo
bash /bin/fas_openvpn &
ps -ef | grep fas_openvpn &>/dev/null
if [ "$?" -ne "0" ];then
echo -e "${Tip} FAS OpenVPN守护 启动失败 请检查" && echo
else
echo -e "${Info} FAS OpenVPN守护 启动成功" && echo
fi
Date=`date +%Y年%m月%d日%H时%M分%S秒`
echo "${Date} Run OpenVPN" >> /root/fas.log
}
Fas_Stop(){
echo -n -e "${Error}确定停止FAS守护? Y/n: "
read choose
if [ "$choose" == "Y" ] || [ "$choose" == "y" ]
then
echo -e "${Info} FAS守护已停止" && echo
kill -9 $(ps -ef|grep fas_openvpn|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ') >/dev/null 2>&1
kill -9 $(ps -ef|grep fas_mysql|gawk '$0 !~/grep/ {print $2}' |tr -s '\n' ' ') >/dev/null 2>&1
else
echo "取消"
fi
}
Fas_LOG(){
cat /root/fas.log
}
echo
echo -e " FAS守护维护脚本 ${Red}[v${sh_ver}]${Font}
---- Ms | www.qvnidaye.com ----
${Green}1.${Font} 安装 FAS守护
${Green}2.${Font} 卸载 FAS守护
————————————
${Green}3.${Font} 启动 FAS守护
${Green}4.${Font} 停止 FAS守护
${Green}5.${Font} 查看 FAS守护日志
————————————" && echo
stty erase '^H' && read -p " 请输入数字 [1-6]:" num
case "$num" in
1)
Fas_Install
;;
2)
Fas_Uninstall
;;
3)
Fas_Run
;;
4)
Fas_Stop
;;
5)
Fas_LOG
;;
*)
echo "请输入正确数字 [1-6]"
;;
esac