#!/bin/sh
### BEGIN INIT INFO
# Provides:          pound
# Required-Start:    $remote_fs $named $syslog
# Required-Stop:     $syslog
# Default-Start:     3 4 5
# Default-Stop:      0 1 2 6
# Short-Description: Reverse proxy, load balancer and HTTPS front-end
# Description:       Reverse proxy, load balancer and HTTPS front-end 
#		for web-servers
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

SourceIfNotEmpty /etc/sysconfig/pound

PIDFILE=/var/run/pound.pid
LOCKFILE=/var/lock/subsys/pound
RETVAL=0

start()
{
	if is_no "$CONFIGURED"; then
	    action "Checking if pound is configured:" false
	    echo -n 'Please configure; afterwards, set CONFIGURED=Yes in /etc/sysconfig/pound'
	    echo
	    exit 1
	fi
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user _pound -- pound
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user _pound pound
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}


# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload|force-reload)
	restart
	;;
  status)
	status --pidfile "$PIDFILE" --expect-user _pound -- pound
	RETVAL=$?
	;;
  condstop)
	if [ -e "$LOCKFILE" ]; then
		stop
	fi
	;;
  condrestart)
	if [ -e "$LOCKFILE" ]; then
		restart
	fi
	;;
  condreload)
	if [ -e "$LOCKFILE" ]; then
		reload
	fi
	;;
  *)
	msg_usage "${0##*/} {start|stop|restart|reload|force-reload|condstop|condrestart|condreload|status}"
	RETVAL=1
esac

exit $RETVAL
