Shell programming realizes haproxy load balanced cluster's startup and shutdown management

Source: Internet
Author: User
Tags sleep haproxy

#!/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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.