#!/bin/sh
#
# Startup script for dansguardian
# Modified extensively for SUSE Linux by Don Vosburg <don@vosburgs.org>
#
# chkconfig: 35 92 8
# description: A web content filtering plugin for web \
#              proxies, developed to filter using lists of \
#              banned phrases, MIME types, filename \
#              extensions and PICS labelling.
# processname: dansguardian
# pidfile: /var/run/dansguardian.pid
# config: /etc/dansguardian/dansguardian.conf

### BEGIN INIT INFO
# Provides:			    dansguardian
# Required-Start:		$local_fs $remote_fs $network $named squid 
# Should-Start:	
# Required-Stop:		$local_fs $remote_fs $network
# Should-Stop:	
# Default-Start:		3 5
# Default-Stop:			0 1 2 6
# Short-Description:	DansGuardian web content filter
# Description:			Start the DansGuardian web content filter
#	providing HTTP and other filtering services in conjunction with squid
### END INIT INFO

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
DG_BINARY=/usr/sbin/dansguardian
test -x $DG_BINARY || { echo "$DG_BINARY not installed";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

# Check for existence of needed config file 
DG_CONFIG=/etc/dansguardian/dansguardian.conf
test -r $DG_CONFIG || { echo "$DG_CONFIG not existing";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 6; fi; }

DG_PIDFILE=/var/run/dansguardian.pid

. /etc/rc.status
rc_reset

# See how we were called.

case "$1" in
start)
        echo -n "Starting dansguardian "
        startproc ${DG_BINARY}
        rc_status -v
        ;;
stop)
        echo -n "Shutting down dansguardian "
        killproc -TERM -p ${DG_PIDFILE} ${DG_BINARY}
        rc_status -v
        ;;
try-restart|condrestart)
        ## Do a restart only if the service was active before.
        ## Note: try-restart is now part of LSB (as of 1.9).
        ## RH has a similar command named 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
        # Remember status and be quiet
        rc_status
        ;;
restart)
        $0 stop
        $0 start
        # Remember status and be quiet
        rc_status
        ;;
force-reload)
        echo -n "Reload service dansguardian "
        /sbin/killproc -HUP $DG_BINARY
        touch ${DG_PIDFILE}
        rc_status -v
        ;;
reload)
        echo -n "Reload service dansguardian "
        /sbin/killproc -HUP $DG_BINARY
        touch ${DG_PIDFILE}
        rc_status -v
        ;;
status)
        echo -n "Checking for dansguardian "
        checkproc ${DG_BINARY}
        rc_status -v
        ;;       
probe)
        test $DG_CONFIG -nt ${DG_PIDFILE} && echo reload
        ;;
*)
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" 
        exit 1
        ;;
esac
rc_exit
