#!/bin/sh
#
# Startup script for dansguardian
#
# chkconfig: - 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:       squid
# Should-Start:
# Required-Stop:        squid
# Should-Stop:
# Default-Start:        none
# Default-Stop: 0 1 2 6
# Short-Description:    Dansguardian web content filter
# Description:  Dansguardian web content filter
### END INIT INFO

# File includes changes by Thomas Jarosch
. /etc/init.d/functions

PROCESSNAME=dansguardian
PIDFILE=/var/run/$PROCESSNAME.pid
LOCKFILE=/var/lock/subsys/$PROCESSNAME


if [ ! -f "/usr/sbin/$PROCESSNAME" ] || [ ! -f "/etc/dansguardian/dansguardian.conf" ];then 
     exit 0
fi

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- $PROCESSNAME
	RETVAL=$?
        return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user dansguardian -- $PROCESSNAME
	RETVAL=$?
        return $RETVAL
}

restart()
{
    stop
    start
}

case "$1" in
start)
	start
        ;;
stop)
        if [ -e "$LOCKFILE" ]; then
	    stop
    	fi
        ;;
restart)
    	restart
        ;;
condstop)
        if [ -e "$LOCKFILE" ]; then
    	    stop
    	fi
	;;
status)
    "   $PROCESSNAME" -s
        ;;
condrestart)
	if [ -e "$LOCKFILE" ]; then
		restart
	fi
	;;        
*)

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

exit 0
