0f6eab5
#!/bin/sh
0f6eab5
#
0f6eab5
# haproxy
0f6eab5
#
0f6eab5
# chkconfig:   - 85 15
0f6eab5
# description:  HAProxy is a free, very fast and reliable solution \
0f6eab5
#               offering high availability, load balancing, and \
0f6eab5
#               proxying for TCP and  HTTP-based applications
0f6eab5
# processname: haproxy
0f6eab5
# config:      /etc/haproxy/haproxy.cfg
0f6eab5
# pidfile:     /var/run/haproxy.pid
0f6eab5
0f6eab5
# Source function library.
0f6eab5
. /etc/rc.d/init.d/functions
0f6eab5
0f6eab5
# Source networking configuration.
0f6eab5
. /etc/sysconfig/network
0f6eab5
0f6eab5
# Check that networking is up.
0f6eab5
[ "$NETWORKING" = "no" ] && exit 0
0f6eab5
0f6eab5
exec="/usr/sbin/haproxy"
0f6eab5
prog=$(basename $exec)
0f6eab5
0f6eab5
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
0f6eab5
0f6eab5
lockfile=/var/lock/subsys/haproxy
0f6eab5
0f6eab5
check() {
0f6eab5
    $exec -c -V -f /etc/$prog/$prog.cfg
0f6eab5
}
0f6eab5
0f6eab5
start() {
0f6eab5
    $exec -c -q -f /etc/$prog/$prog.cfg
0f6eab5
    if [ $? -ne 0 ]; then
0f6eab5
        echo "Errors in configuration file, check with $prog check."
0f6eab5
        return 1
0f6eab5
    fi
0f6eab5
 
0f6eab5
    echo -n $"Starting $prog: "
0f6eab5
    # start it up here, usually something like "daemon $exec"
0f6eab5
    daemon $exec -D -f /etc/$prog/$prog.cfg -p /var/run/$prog.pid
0f6eab5
    retval=$?
0f6eab5
    echo
0f6eab5
    [ $retval -eq 0 ] && touch $lockfile
0f6eab5
    return $retval
0f6eab5
}
0f6eab5
0f6eab5
stop() {
0f6eab5
    echo -n $"Stopping $prog: "
0f6eab5
    # stop it here, often "killproc $prog"
0f6eab5
    killproc $prog 
0f6eab5
    retval=$?
0f6eab5
    echo
0f6eab5
    [ $retval -eq 0 ] && rm -f $lockfile
0f6eab5
    return $retval
0f6eab5
}
0f6eab5
0f6eab5
restart() {
0f6eab5
    $exec -c -q -f /etc/$prog/$prog.cfg
0f6eab5
    if [ $? -ne 0 ]; then
0f6eab5
        echo "Errors in configuration file, check with $prog check."
0f6eab5
        return 1
0f6eab5
    fi
0f6eab5
    stop
0f6eab5
    start
0f6eab5
}
0f6eab5
0f6eab5
reload() {
0f6eab5
    $exec -c -q -f /etc/$prog/$prog.cfg
0f6eab5
    if [ $? -ne 0 ]; then
0f6eab5
        echo "Errors in configuration file, check with $prog check."
0f6eab5
        return 1
0f6eab5
    fi
0f6eab5
    echo -n $"Reloading $prog: "
0f6eab5
    $exec -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid)
0f6eab5
    retval=$?
0f6eab5
    echo
0f6eab5
    return $retval
0f6eab5
}
0f6eab5
0f6eab5
force_reload() {
0f6eab5
    restart
0f6eab5
}
0f6eab5
0f6eab5
fdr_status() {
0f6eab5
    status $prog
0f6eab5
}
0f6eab5
0f6eab5
case "$1" in
0f6eab5
    start|stop|restart|reload)
0f6eab5
        $1
0f6eab5
        ;;
0f6eab5
    force-reload)
0f6eab5
        force_reload
0f6eab5
        ;;
0f6eab5
    check)
0f6eab5
        check
0f6eab5
        ;;
0f6eab5
    status)
0f6eab5
        fdr_status
0f6eab5
        ;;
0f6eab5
    condrestart|try-restart)
0f6eab5
  	[ ! -f $lockfile ] || restart
0f6eab5
	;;
0f6eab5
    *)
0f6eab5
        echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
0f6eab5
        exit 2
0f6eab5
esac