#!/bin/bash
#
# Startup script for the Audit daemon
#
# chkconfig: - 98 24
# description: SNARE Squid Log Monitor System
# processname: snaresquid

# Change these variables (or the ones in /etc/sysconfig/snaresquid)
DESTSERVER="localhost"
SYSLOGDEST="local1.info"
LOGPATH="/var/log/squid/access.log"

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

# Any additional config options
if [ -f /etc/sysconfig/snaresquid ]; then
	. /etc/sysconfig/snaresquid
fi

if [ ! -z $SYSLOGDEST ]; then
	OPTIONS="-s $SYSLOGDEST $DESTSERVER SquidLog"
else
	OPTIONS="$DESTSERVER SquidLog"
fi

# Path to the snaresquid binary.
snaresquid=/usr/bin/snaresquid
RETVAL=0

start() {
        umask 077
        echo -n $"Starting $snaresquid: "
        /usr/bin/tail --follow=name $LOGPATH | $snaresquid $OPTIONS >/dev/null 2>&1 &
        RETVAL=$?
        [ $RETVAL = 0 ] && touch /var/lock/subsys/snaresquid
	[ $RETVAL = 0 ] && echo_success
        [ $RETVAL != 0 ] && echo_failure
	echo
        return $RETVAL
}
stop() {
        echo -n $"Stopping $snaresquid: "
        killproc $snaresquid
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/snaresquid
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $snaresquid
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo $"Usage: snaresquid {start|stop|restart|status}"
        exit 1
esac

exit $RETVAL

