#!/bin/sh -e
#
# Original version by Robert Leslie
# <rob@mars.org>, edited by iwj and cs
# Modified for fwlowatch by Alberto Gonzalez Iniesta <agi@agi.as>

test $DEBIAN_SCRIPT_DEBUG && set -v -x

DAEMON=/usr/sbin/fwlogwatch
CONFIG=/etc/fwlogwatch/fwlogwatch.config

test -x $DAEMON || exit 0

test -f $CONFIG || exit 0

# If realtime mode is not configured, don't start daemon
grep "^realtime_response" $CONFIG 1> /dev/null || exit 0

PIDFILE=`grep "^pidfile" $CONFIG | sed 's/.*=[\t ]*//' `

case "$1" in
start)
  echo -n "Starting firewall log watcher: fwlogwatch"
  start-stop-daemon --start --quiet \
	--exec $DAEMON 
  echo "."
  ;;
stop)
  echo -n "Stopping firewall log watcher: fwlogwatch"
  start-stop-daemon --stop --quiet --oknodo \
	--exec $DAEMON --pidfile $PIDFILE
  echo "."
  ;;
restart|force-reload)
  echo -n "Restarting firewall log watcher: fwlogwatch"
  start-stop-daemon --stop --quiet --oknodo \
	--exec $DAEMON --pidfile $PIDFILE
  start-stop-daemon --start --quiet \
  	--exec $DAEMON
  echo "."
  ;;
*)
  echo "Usage: /etc/init.d/fwlogwatch {start|stop|restart|force-reload}" >&2
  exit 1
  ;;
esac

exit 0

