Create a Haproxy startup script

Source: Internet
Author: User

Vim/etc/init.d/haproxy

#!/bin/bash

#

# Haproxy

#

# chkconfig:35 85 15

# Description:haproxy is a free, very fast and reliable solution \

# offering high availability, load balancing, and \

# proxying for TCP and http-based applications

# Processname:haproxy

# config:/etc/haproxy.cfg

# Pidfile:/var/run/haproxy.pid


# Source function library.

. /etc/rc.d/init.d/functions


# Source Networking configuration.

. /etc/sysconfig/network


# Check that networking are up.

["$NETWORKING" = "no"] && exit 0


Config= "/etc/haproxy.cfg"

Exec= "/usr/local/haproxy/sbin/haproxy"

prog=$ (basename $exec)


[-e/etc/sysconfig/$prog] &&. /etc/sysconfig/$prog


Lockfile=/var/lock/subsys/haproxy


Check () {

$exec-C-v-f $config

}


Start () {

$exec-C-q-f $config

If [$?-ne 0]; Then

echo "Errors in the configuration file, check with $prog check."

Return 1

Fi

Echo-n $ "Starting $prog:"

# start it up here, usually something like "daemon $exec"

Daemon $exec-D-F $config-P/var/run/$prog. PID

Retval=$?

Echo

[$retval-eq 0] && Touch $lockfile

Return $retval

}


Stop () {

Echo-n $ "Stopping $prog:"

# Stop it here, often "Killproc $prog"

Killproc $prog

Retval=$?

Echo

[$retval-eq 0] && rm-f $lockfile

Return $retval

}


Restart () {

$exec-C-q-f $config

If [$?-ne 0]; Then

echo "Errors in the configuration file, check with $prog check."

Return 1

Fi

Stop

Start

}


Reload () {

$exec-C-q-f $config

If [$?-ne 0]; Then

echo "Errors in the configuration file, check with $prog check."

Return 1

Fi

Echo-n $ "Reloading $prog:"

$exec-D-F $config-P/var/run/$prog. PID-SF $ (cat/var/run/$prog. pid)

Retval=$?

Echo

Return $retval

}


Force_reload () {

Restart

}


Fdr_status () {

Status $prog

}


Case "$" in

Start|stop|restart|reload)

$

;;

Force-reload)

Force_reload

;;

Checkconfig)

Check

;;

Status

Fdr_status

;;

Condrestart|try-restart)

[!-F $lockfile] | | Restart

;;

*)

echo $ "Usage: $ {start|stop|status|checkconfig|restart|try-restart|reload|force-reload}"

Exit 2

Esac


This article is from the "My Ops Time" blog, so be sure to keep this source http://aaronsa.blog.51cto.com/5157083/1741519

Create a Haproxy startup script

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.