#!/bin/sh
#
# /etc/init.d/c-icap
#   and its symbolic link
# /usr/sbin/rcc-icap
#
### BEGIN INIT INFO
# Provides:          c-icap
# Required-Start:    $syslog $remote_fs
# Should-Start:
# Required-Stop:     $syslog $remote_fs
# Should-Stop:
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: c-icap redirector for squid and clamav
# Description:       Start c-icap to provide clamav virus
#	scanner	interface for Squid.
### END INIT INFO

CICAP_BIN=/usr/sbin/c-icap
test -x $CICAP_BIN || { echo "$CICAP_BIN not installed"; 
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }

CICAP_CONFIG=/etc/sysconfig/c-icap
test -r $CICAP_CONFIG || { echo "$CICAP_CONFIG not existing";
	if [ "$1" = "stop" ]; then exit 0;
	else exit 6; fi; }

. $CICAP_CONFIG

if [ "$USE_CICAP" == "no" ]; then
    echo "c-icap disabled in $CICAP_CONFIG. To enable c-icap, set USE_CICAP=\"yes\" in $CICAP_CONFIG"
    exit 6
fi

. /etc/rc.status

rc_reset

case "$1" in
    start)
	echo -n "Starting c-icap "
	/sbin/startproc $CICAP_BIN
	rc_status -v
	;;
    stop)
	echo -n "Shutting down c-icap "
	/sbin/killproc -TERM $CICAP_BIN
	rc_status -v
	;;
    try-restart|condrestart)
	if test "$1" = "condrestart"; then
		echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
	fi
	$0 status
	if test $? = 0; then
		$0 restart
	else
		rc_reset	# Not running is not a failure.
	fi
	rc_status
	;;
    restart)
	$0 stop
	$0 start
	rc_status
	;;
    force-reload)
	echo -n "Reload service c-icap "
	/sbin/killproc -HUP $CICAP_BIN
	rc_status -v
	;;
    reload)
	echo -n "Reload service c-icap "
	/sbin/killproc -HUP $CICAP_BIN
	rc_status -v
	;;
    status)
	echo -n "Checking for service c-icap "
	/sbin/checkproc $CICAP_BIN
	rc_status -v
	;;
    probe)
	test /etc/c_icap/c-icap.conf -nt /var/run/c-icap.pid && echo reload
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 1
	;;
esac
rc_exit
