Skip to content

Commit

Permalink
# v1.0.7 修复 部分系统 停止Haproxy异常的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Toyo authored Aug 12, 2017
1 parent b1b7321 commit 932bb79
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions haproxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export PATH
#=================================================
# System Required: CentOS/Debian/Ubuntu
# Description: HaProxy
# Version: 1.0.6
# Version: 1.0.7
# Author: Toyo
# Blog: https://doub.io/wlzy-19/
#=================================================
Expand Down Expand Up @@ -63,7 +63,6 @@ Set_iptables(){
}
# 安装HaProxy
installHaProxy(){
# 判断是否安装HaProxy
HaProxy_exist=`haproxy -v`
if [[ ${HaProxy_exist} != "" ]]; then
echo -e "\033[41;37m [错误] \033[0m 已经安装HaProxy,请检查 !" && exit 1
Expand All @@ -74,7 +73,6 @@ installHaProxy(){
apt-get update && apt-get install -y vim haproxy
fi
chmod +x /etc/rc.local
#判断HaProxy是否安装成功
HaProxy_exist=`haproxy -v`
if [[ ${HaProxy_exist} = "" ]]; then
echo -e "\033[41;37m [错误] \033[0m 安装HaProxy失败,请检查 !" && exit 1
Expand All @@ -97,15 +95,11 @@ installHaProxy(){
fi
}
setHaProxy(){
# 判断是否安装HaProxy
check_HaProxy
# 设置本地监听端口
stty erase '^H' && read -p "请输入 HaProxy 的 本地监听端口(转发端口) [1-65535](支持端口段: 2333-6666): " HaProxyport
[[ -z "${HaProxyport}" ]] && echo "取消..." && exit 1
# 设置欲转发 IP
stty erase '^H' && read -p "请输入 HaProxy 欲转发的 IP:" HaProxyip
[[ -z "${HaProxyip}" ]] && echo "取消..." && exit 1
#最后确认
echo
echo "——————————————————————————————"
echo " 请检查 HaProxy 配置是否有误 !"
Expand Down Expand Up @@ -141,20 +135,13 @@ frontend ss-in1
backend ss-out1
server server1 ${HaProxyip} maxconn 20480
EOF

PID=`ps -ef | grep "haproxy" | grep -v grep | grep -v "haproxy.sh" | awk '{print $2}'`
if [[ ! -z $PID ]]; then
stopHaProxy
fi
startHaProxy
restartHaProxy
}
# 查看HaProxy列表
viewHaProxy(){
# 检查是否安装
check_HaProxy
HaProxy_port=`cat ${HaProxy_cfg_file} | sed -n "12p" | cut -c 12-23`
HaProxy_ip=`cat ${HaProxy_cfg_file} | sed -n "16p" | awk '{print $3}'`
# 获取IP
ip=`wget -qO- -t1 -T2 ipinfo.io/ip`
[[ -z $ip ]] && ip="VPS_IP"
echo
Expand All @@ -171,9 +158,7 @@ viewHaProxy(){
}
# 启动aProxy
startHaProxy(){
# 检查是否安装
check_HaProxy
# 判断进程是否存在
PID=`ps -ef | grep "haproxy" | grep -v grep | grep -v "haproxy.sh" | awk '{print $2}'`
[[ ! -z $PID ]] && echo -e "\033[41;37m [错误] \033[0m 发现 HaProxy 正在运行,请检查 !" && exit 1
if [[ ${release} == "centos" ]]; then
Expand Down Expand Up @@ -204,12 +189,19 @@ startHaProxy(){
}
# 停止aProxy
stopHaProxy(){
# 检查是否安装
check_HaProxy
# 判断进程是否存在
PID=`ps -ef | grep "haproxy" | grep -v grep | grep -v "haproxy.sh" | awk '{print $2}'`
[[ -z $PID ]] && echo -e "\033[41;37m [错误] \033[0m 发现 HaProxy 没有运行,请检查 !" && exit 1
kill -9 ${PID}
if [[ ${release} == "centos" ]]; then
cat /etc/redhat-release |grep 7\..*|grep -i centos>/dev/null
if [[ $? = 0 ]]; then
systemctl stop haproxy.service
else
/etc/init.d/haproxy stop
fi
else
/etc/init.d/haproxy stop
fi
HaProxy_port_1=`cat ${HaProxy_cfg_file} | sed -n "12p" | cut -c 12-23 | grep "-"`
HaProxy_port=`cat ${HaProxy_cfg_file} | sed -n "12p" | cut -c 12-23`
if [[ ${HaProxy_port_1} = "" ]]; then
Expand Down Expand Up @@ -237,9 +229,7 @@ restartHaProxy(){
startHaProxy
}
statusHaProxy(){
# 检查是否安装
check_HaProxy
# 判断进程是否存在
PID=`ps -ef | grep "haproxy" | grep -v grep | grep -v "haproxy.sh" | awk '{print $2}'`
if [[ ! -z $PID ]]; then
echo -e "\033[42;37m [信息] \033[0m HaProxy 正在运行,PID: ${PID} !"
Expand All @@ -248,7 +238,6 @@ statusHaProxy(){
fi
}
uninstallHaProxy(){
# 检查是否安装
check_HaProxy
echo "确定要卸载 HaProxy ? [y/N]"
stty erase '^H' && read -p "(默认: n):" unyn
Expand Down

0 comments on commit 932bb79

Please sign in to comment.