#!/bin/bash
#
# htcacheclean - This shell script takes care of starting and stopping htcacheclean
#
# chkconfig: - 92 8
# description: htcacheclean - Clean up the disk cache. Used in conjunction \
# with mod_disk_cache and mod_proxy.
# processname: htcacheclean
# config: /etc/sysconfig/htcacheclean

### BEGIN INIT INFO
# Provides: htcacheclean
# Required-Start: $network httpd
# Required-Stop: $network httpd
# Short-Description: htcacheclean - Clean up the disk cache.
# Description: htcacheclean - Clean up the disk cache. Used in conjunction with mod_disk_cache and mod_proxy.
### END INIT INFO

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

# Source networking configuration.
. /etc/sysconfig/network


[ -d /run/httpd/htcacheclean ] || mkdir -p /run/httpd/htcacheclean
[ -d /var/cache/httpd/mod_proxy ] || mkdir -p /var/cache/httpd/mod_proxy

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

[ -f /usr/sbin/htcacheclean ] || exit 0

[ -f /etc/sysconfig/htcacheclean ] && . /etc/sysconfig/htcacheclean

# See how we were called.
case "$1" in
start)
	gprintf "Starting htcacheclean: "
	daemon /usr/sbin/htcacheclean -n -t -i \
	-d ${INTERVAL:-"120"} \
	-p ${CACHEROOT:-"/var/cache/httpd/mod_proxy"} \
	-l ${SIZE:-"100M"}
	echo
	touch /var/lock/subsys/htcacheclean
	;;
stop)
	gprintf "Shutting down htcacheclean: "
	killproc htcacheclean
	echo
	rm -f /var/lock/subsys/htcacheclean
	;;
status)
	status htcacheclean
	/usr/sbin/htcacheclean -D -v -t \
	-p ${CACHEROOT:-"/var/cache/httpd/mod_proxy"} \
	-l ${SIZE:-"100M"}
	;;
restart|reload)
	$0 stop
	$0 start
	;;
condrestart)
	[ -f /var/lock/subsys/htcacheclean ] && restart
	;;
	*)
	gprintf "Usage: %s {start|stop|status|restart|condrestart|reload}\n" "$0"
	exit 1
esac

exit 0
