#!/bin/sh -e
#
# flowscan	Transforms Cisco netflow files into rrd files.
#
# chkconfig:	345 20 20
#
# description:	Start / stop the netflow recorder

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 "Reloading $DESC: "
	startstop --stop --oknodo --quiet
	startstop --start
	echo "${DAEMON##*/}."
	;;
  *)
	echo "Usage: $0 {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
