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