#!/bin/sh
#
# htcacheclean	Apache disk cache cleaner
#
# chkconfig:	345 86 14
# description:	htcacheclean keeps the mod_cache_disk cache below a size limit.
# processname:	htcacheclean
# pidfile:	/var/run/httpd/htcacheclean.pid
# config:	/etc/sysconfig/htcacheclean

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

# Get service config
. /etc/sysconfig/htcacheclean

PIDFILE=/var/run/httpd/htcacheclean.pid

start() {
	if [ -f /var/lock/subsys/htcacheclean ]; then
		msg_already_running htcacheclean
		return
	fi

	msg_starting htcacheclean
	daemon --user http --pidfile $PIDFILE /usr/sbin/htcacheclean -P $PIDFILE \
		-d $HTCACHECLEAN_INTERVAL -p $HTCACHECLEAN_PATH -l $HTCACHECLEAN_LIMIT $HTCACHECLEAN_OPTIONS
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/htcacheclean
}

stop() {
	if [ ! -f /var/lock/subsys/htcacheclean ]; then
		msg_not_running htcacheclean
		return
	fi

	msg_stopping htcacheclean
	killproc --pidfile $PIDFILE htcacheclean
	rm -f /var/lock/subsys/htcacheclean $PIDFILE
}

condrestart() {
	if [ ! -f /var/lock/subsys/htcacheclean ]; then
		msg_not_running htcacheclean
		RETVAL=$1
		return
	fi

	stop
	start
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status --pidfile $PIDFILE htcacheclean
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
