#! /bin/sh
#
# varnish	Control the varnish HTTP accelerator
#
# chkconfig: 345 90 10
# description: HTTP accelerator
# processname: varnishd
# config: /etc/varnish.conf
# pidfile: /var/run/varnish/varnishd.pid

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

. /etc/sysconfig/varnish

if [ -z "$DAEMON" ]; then
	DAEMON=/usr/sbin/varnishd
fi

start() {
	if [ ! -f /var/lock/subsys/varnishd ]; then
		msg_starting "Varnish HTTP accelerator"
		daemon $DAEMON "$DAEMON_OPTS"
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/varnishd
	else
		msg_already_running "Varnish HTTP accelerator"
	fi
}

stop() {
	if [ -f /var/lock/subsys/varnishd ]; then
		msg_stopping "Varnish HTTP accelerator"
		killproc $DAEMON
		rm -f /var/lock/subsys/varnishd
	else
		msg_not_running "Varnish HTTP accelerator"
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  status)
	status varnishd
	RETVAL=$?
	;;
  restart|reload)
  	stop
	start
	;;
  *)
	msg_usage "$0 {start|stop|status|restart}"
	exit 3
esac

exit $RETVAL
