haproxy/haproxy.init

120 lines
2.2 KiB
Bash

#!/bin/sh
#
# haproxy TCP/HTTP reverse proxy for high availability environments
#
# chkconfig: - 85 15
# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \
# for high availability environments.
# processname: haproxy
# config: /etc/haproxy/haproxy.conf
# pidfile: /var/run/haproxy.pid
### BEGIN INIT INFO
# Provides: haproxy
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start:
# Default-Stop:
# Short-Description: fast and reliable load balancing reverse proxy
# Description: This file should be used to start and stop haproxy.
### END INIT INFO
# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1
# Source function library.
. /etc/init.d/functions
NAME=haproxy
PIDFILE=/run/${NAME}.pid
CONFIG=/etc/${NAME}/${NAME}.cfg
CFGDIR=/etc/${NAME}/conf.d
EXTRAOPTS="" #"-S /run/haproxy-master.sock"
LOCKFILE=/var/lock/subsys/${NAME}
BINARY=/usr/sbin/${NAME}
RETVAL=0
SourceIfNotEmpty /etc/sysconfig/${NAME}
check()
{
action "Checking configuration sanity for $name: " \
$BINARY -f ${CONFIG} -f $CFGDIR -c -q $EXTRAOPTS
RETVAL=$?
return $RETVAL
}
start()
{
check || exit
start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user _haproxy -- $BINARY \
-D -f ${CONFIG} -f $CFGDIR -p ${PIDFILE} ${EXTRAOPTS}
RETVAL=$?
return $RETVAL
}
stop()
{
stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user _haproxy -- $BINARY
RETVAL=$?
return $RETVAL
}
restart()
{
check || exit
stop
start
}
reload()
{
check || exit
msg_reloading $NAME
$BINARY -p "$PIDFILE" -f $CONFIG -f $CFGDIR ${EXTRAOPTS} -sf `cat $PIDFILE`
RETVAL=$?
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
condstop)
if [ -e "$LOCKFILE" ]; then
stop
fi
;;
condrestart)
if [ -e "$LOCKFILE" ]; then
restart
fi
;;
condreload)
if [ -e "$LOCKFILE" ]; then
reload
fi
;;
check)
check
;;
status)
status --pidfile "$PIDFILE" --expect-user _haproxy -- haproxy
RETVAL=$?
;;
*)
msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status|check}"
RETVAL=1
esac
exit $RETVAL