当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 1 Fork 2

我爸/dmkuai
暂停

forked from Zy143L/dmkuai 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
fas 4.59 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#================================
#版本: 2018-7-23
#作者: Zy143L
#===============================
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
chmod 0777 /bin/fas_openvpn
echo ' while true
do
source /etc/openvpn/auth_config.conf
#调用MySQL数据库密码
mysql -uroot -p${mysql_pass} -e "select version();" &>/dev/null
#MySQL状态检查
if [ "$?" -ne "0" ];then
Date=`date +%Y年%m月%d日%H时%M分%S秒`
echo "$Date FAS守护: MySQL数据库异常 尝试启动~" >> /root/fas.log
systemctl stop mariadb.service
sleep 2
systemctl start mariadb.service
sleep 3
mysql -uroot -p${mysql_pass} -e "select version();" &>/dev/null
if [ "$?" -eq "0" ];then
Date=`date +%Y年%m月%d日%H时%M分%S秒`
echo "$Date FAS守护: MySQL数据库启动成功~" >> /root/fas.log
else
Date=`date +%Y年%m月%d日%H时%M分%S秒`
echo "$Date FAS守护: MySQL启动失败 15秒后将重试" >> /root/fas.log
fi
fi
sleep 10
done' > /bin/fas_mysql
chmod 0777 /bin/fas_mysql
echo " ----FAS守护脚本安装完成" && echo
echo " ----输入fas即可管理脚本" && echo
echo " ----手动运行fas启动脚本" && echo
}
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
bash /bin/fas_mysql &
ps -ef | grep fas_mysql &>/dev/null
if [ "$?" -ne "0" ];then
echo -e "${Tip} FAS MySQL守护 启动失败 请检查" && echo
else
echo -e "${Info} FAS MySQL守护 启动成功" && echo
fi
Date=`date +%Y年%m月%d日%H时%M分%S秒`
echo "${Date} Run OpenVPN & MySQL Monitor" >> /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}
---- Zy143L | dmkuai.cn ----
${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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/svnc/dmg.git
git@gitee.com:svnc/dmg.git
svnc
dmg
dmkuai
master

搜索帮助