#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          flowscan
# Required-Start:    $local_fs $remote_fs $syslog $time
# Required-Stop:     $local_fs $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: transforms Cisco netflow files into rrd files
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/flowscan
CONFIG=/etc/flowscan/flowscan.cf
DESC="netflow recorder"

test -f $DAEMON || exit 0
test -f $CONFIG || exit 0

startstop() {
  local background=
  [ "$1" != "--start" ] || background="--background"
  start-stop-daemon "$@" $background --make-pidfile --name ${DAEMON##*/} \
    --pidfile="/var/run/${DAEMON##*/}.pid" --startas "$DAEMON"
}

case "$1" in
  start)
	echo -n "Starting $DESC: "
	startstop --start
	echo "${DAEMON##*/}."
	;;
  stop)
	echo -n "Stopping $DESC: "
	startstop --stop
	echo "${DAEMON##*/}."
	;;
  restart|force-reload)
	echo -n "Restarting $DESC: "
	startstop --stop --oknodo --quiet
	sleep 3
	startstop --start
	echo "${DAEMON##*/}."
	;;
  *)
	echo "Usage: $0 {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0