#!/bin/bash
#-------------------------Haproxy Server Management Shell script------------------------------------------------
#Authors are from JC
#time:2012-10-10
#QQ:408822635
#from the region Beijng.China.
#-------------------------Haproxy Server Management Shell script------------------------------------------------
case "$1" in
start)
BASE="/usr/local/haproxy/sbin/haproxy"
haproxy=`netstat -lntp|grep haproxy|wc -l`
if [ $haproxy -gt 0 ];then
echo "正在檢測中,請稍候......"
sleep 3
echo "-----------------------------Haproxy負載平衡叢集---------------------------------------"
echo "| |"
echo "| 已經在運行狀態中,無需要啟動 |"
echo "| |"
echo "-----------------------------Haproxy負載平衡叢集---------------------------------------"
else
for haproxy in /usr/local/haproxy/etc/haproxy.cfg
do
$BASE -f $haproxy >/dev/null 2>&1
done
echo "Haproxy負載平衡正在啟動......"
sleep 3
echo "-------------------------------Haproxy負載平衡叢集已經啟動完成-------------------------------------------"
netstat -lntp|grep haproxy
echo "-------------------------------Haproxy負載平衡叢集列表---------------------------------------------------"
fi
;;
stop)
BASE="/usr/local/haproxy/sbin/haproxy"
haproxy=`netstat -lntp|grep haproxy|wc -l`
if [ $haproxy == $? ];then
echo "正在檢測中,請稍候......"
sleep 2
echo "Haproxy已經關閉,無需要再關閉"
echo "Haproxy已經關閉,無需要再關閉"
else
echo "Haproxy負載平衡服務正在關閉,請稍後.........."
sleep 2
for PIDFILE in /usr/local/haproxy/haproxy.pid
do
kill $(cat $PIDFILE) >/dev/null 2>&1
done
echo "Haproxy負載平衡叢集服務已經關閉完成.....................done"
sleep 1
fi
;;
status)
haproxy=`netstat -lntp|grep haproxy|wc -l`
if [ $haproxy -gt 0 ];then
echo "Haproxy正在運行中..................OK"
else
echo "Haproxy已經是關閉狀態...................stop"
fi
;;
restart)
BASE=/usr/local/haproxy/sbin/haproxy
CONFFILE=/usr/local/haproxy/etc/haproxy.cfg
echo "Haproxy正在重新啟動,請稍等......................................."
for PIDFILE in /usr/local/haproxy/haproxy.pid
do
$BASE -f $CONFFILE -sf $(cat $PIDFILE) >/dev/null
done
echo "Haproxy負載平衡服務已經重新啟動成功,請查看............................"
sleep 2
echo "--------------------------------------------------------Haproxy重新啟動後的進程數------------------------------------------------------------------------------------------------------"
ps -ef|grep haproxy
echo "--------------------------------------------------------Haproxy進程列表-------------------------------------------------------------------------------------------------"
;;
*)
echo "Usage: $haproxy {start|stop|status|restart}"
RETVAL=3
;;
esac
exit $RETVAL
查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/Servers/zs/