#!/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 "$" in
Start
Base= "/usr/local/haproxy/sbin/haproxy"
haproxy= ' Netstat-lntp|grep haproxy|wc-l '
If [$haproxy-gt 0];then
echo "is being instrumented, please wait ..."
Sleep 3
echo "-----------------------------haproxy load Balancing cluster---------------------------------------"
echo "| |"
echo "| is already in run state, no need to start | "
echo "| |"
echo "-----------------------------haproxy load Balancing cluster---------------------------------------"
Else
For Haproxy In/usr/local/haproxy/etc/haproxy.cfg
Todo
$BASE-F $haproxy >/dev/null 2>&1
Done
echo "Haproxy load balancing is starting ..."
Sleep 3
echo "-------------------------------haproxy load-balancing cluster has started to complete-------------------------------------------"
Netstat-lntp|grep Haproxy
echo "-------------------------------haproxy load Balancing cluster list---------------------------------------------------"
Fi
;;
Stop
Base= "/usr/local/haproxy/sbin/haproxy"
haproxy= ' Netstat-lntp|grep haproxy|wc-l '
if [$haproxy = = $?]; Then
echo "is being instrumented, please wait ..."
Sleep 2
echo "Haproxy is closed, no need to close again"
echo "Haproxy is closed, no need to close again"
Else
echo "Haproxy load Balancing Service is shutting down, please later ..."
Sleep 2
For Pidfile In/usr/local/haproxy/haproxy.pid
Todo
Kill $ (Cat $PIDFILE) >/dev/null 2>&1
Done
echo "The Haproxy load Balancing Cluster service has been shut down .... done.". Do it.
Sleep 1
Fi
;;
Status
haproxy= ' Netstat-lntp|grep haproxy|wc-l '
If [$haproxy-gt 0];then
echo "Haproxy is running ........... OK "
Else
echo "Haproxy is already turned off ...... ... stop."-Stops.
Fi
;;
Restart)
Base=/usr/local/haproxy/sbin/haproxy
Conffile=/usr/local/haproxy/etc/haproxy.cfg
echo "Haproxy is rebooting, please wait a moment ... ..... ..... ..... ..... ..... ..... ....... ...
For Pidfile In/usr/local/haproxy/haproxy.pid
Todo
$BASE-F $CONFFILE-sf $ (cat $PIDFILE) >/dev/null
Done
echo "The Haproxy load Balancing Service has been restarted successfully, please view ... ...". ..... ..... ..... ...
Sleep 2
echo "-------------------------------------------------------- Number of processes after haproxy reboot------------------------------------------------------------------------------------------------------ "
Ps-ef|grep Haproxy
echo "-------------------------------------------------------- Haproxy Process List-------------------------------------------------------------------------------------------------"
;;
*)
echo "Usage: $haproxy {Start|stop|status|restart}"
Retval=3
;;
Esac
Exit $RETVAL
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/zs/