标签:haproxy 启动脚本
#vi /etc/init.d/haproxy
!/bin/bash
#chkconfig:- 85 15 #-:表示所有级别,85:表示启动顺序,15:关闭顺序
#description:haproxy server
HA_PAT=/usr/local/haproxy
HA_NAM=haproxy
HA_STA=$(netstat-antup | grep :80)
RETUR=0
start()
{
if [ -z "$HA_STA" ];then
echo -en "Starting$HA_NAM....\t\t"
$HA_PAT/sbin/haproxy -f $HA_PAT/conf/${HA_NAM}.cfg
echo -e "\e[0;32m[OK]\e[0m" #设置OK颜色
else
echo "$HA_NAM is alreadyrunning"
RETUR=0
fi
}
stop()
{
if [ -n "$HA_STA" ];then
HA_PID=$(pidof haproxy)
echo -en "Stopping$HA_NAM....\t\t\t"
kill ${HA_PID}
echo -e "\e[0;32m[OK]\e[0m"
RETUR=65
else
echo "$HA_NAM is alreadystopped"
fi
}
status()
{
if [ -n "$HA_STA" ];then
echo "$HA_NAM is running"
else
echo "$HA_NAM is stopped"
RETUR=66
fi
}
restart()
{
echo -en "restarting $HA_PAT.....\t\t\t"
usr/local/sbin/$HA_NAM -f$HA_PAT/conf/${HA_NAM}.cfg -st `pidof haproxy`
echo -e "\e[0;32m[OK]\e[0m"
RETUR=67
}
case"$1" in
start)
start;;
stop)
stop;;
status)
status;;
restart)
restart;;
*)
echo "Uasge /usr/local/sbin/haproxy {start | stop | restart | status }"
RETUR=68
esac
exit $REUR # exit:表示退出脚本,默认反回值是0,这里指定反回值
然后:添加权限和加入自启动
# chmod +x /etc/init.d/haproxy
# chkconfig --add haproxy
# chkconfig haproxy on
# chkconfig --list haproxy
再然后就可以如下操作了:
# service haproxy start | stop | status| restart
本文出自 “Dave-技术博客” 博客,请务必保留此出处http://davewang.blog.51cto.com/6974997/1855903
标签:haproxy 启动脚本
原文地址:http://davewang.blog.51cto.com/6974997/1855903