File dansguardian-init.sh of Package dansguardian

#!/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 $time
# X-UnitedLinux-Should-Start:	squid
# Required-Stop:		$local_fs $remote_fs $network
# X-UnitedLinux-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


CONFFILELOCATION=/etc/dansguardian/
BINARYLOCATION=/usr/sbin/
PIDDIR=/var/run/
SQUID_BIN=/usr/sbin/squid
SQUID_PID=/var/run/squid.pid

. /etc/rc.status
RC_OPTIONS='-v'
rc_reset


# File includes changes by Thomas Jarosch
function wait_for_pid()
{
    local PID=$1
    local RET=0
    
    if [ $PID -eq 0 ] ; then
        return $RET
    fi
    
    # give 60 secs then KILL
    local COUNTDOWN=60

    while [ -d /proc/${PID} ] && [ $COUNTDOWN -gt 0 ] ; do
        sleep 1
        COUNTDOWN=$[$COUNTDOWN-1]
    done

    if [ -d /proc/${PID} ]; then
        COMMAND=`ps h -o command ${PID}`
        logger "dansguardian: timeout waiting for PID ${PID}: ${COMMAND}; sending SIGKILL"
        kill -KILL $PID >/dev/null 2>&1
        RET=1
    fi
    
    return $RET
}

# See how we were called.

case "$1" in
start)  if [ -e $SQUID_PID ] ; then 
         if [ -f ${BINARYLOCATION}dansguardian ] &&
           [ -f ${CONFFILELOCATION}dansguardian.conf ]; then
                echo -n "Starting dansguardian: "
                if ${BINARYLOCATION}dansguardian 2> /dev/null; then
                 rc_status $RC_OPTIONS
                 [ -d /var/lock/subsys ] && touch /var/lock/subsys/dansguardian
                 else
                 rc_failed
		 rc_status -v
		 rc_exit                
		fi
         fi
	else 
	   echo -n "- Warning: squid not running! DansGuardian requires squid!"
	   rc_failed 7
	fi
        ;;
stop)
        echo -n "Shutting down dansguardian: "
        WAITPID=0
        if [ -f ${PIDDIR}dansguardian.pid ] ; then
            WAITPID=`cat ${PIDDIR}dansguardian.pid`
        fi
        if ${BINARYLOCATION}dansguardian -q 2> /dev/null; then
                if wait_for_pid $WAITPID ; then
                  rc_status $RC_OPTIONS 
                else
                 rc_failed
		 rc_status -v
		 rc_exit  
                fi
                /bin/rm -f ${PIDDIR}dansguardian.pid
                /bin/rm -f /tmp/.dguardianipc
                [ -d /var/lock/subsys ] && /bin/rm -f /var/lock/subsys/dansguardian
        else
                rc_failed
		rc_status -v
		rc_exit
        fi
        ;;
restart)
        $0 stop
		sleep 2
        $0 start
        ;;
#status)
#        if [ -f ${BINARYLOCATION}dansguardian ]; then
#                ${BINARYLOCATION}dansguardian -s
#        fi
#        ;;
 status)
        echo -n "Checking for dansguardian "
        checkproc ${BINARYLOCATION}dansguardian
        rc_status -v
        ;;       
*)

        echo "Usage: $0 {start|stop|restart|status}" >&2
        ;;
esac

exit 0
openSUSE Build Service is sponsored by