#!/bin/sh
#
# chkconfig: 345 94 07
# description: collectord (Network Intelligence collector daemon) \
#	This daemon gathers Netflow Exports and passes them to the \
#	Network Intelligence central server.
#

functions=/etc/rc.d/init.d/functions

# Functions will be available for some Linux variants but not all

if [ -f $functions ]
then
    . $functions
fi


# If the install follows the filesystem hierarchy
# standard, we follow it too

if [ -f /opt/ni/bin/collectord ]
then
    progfile=/opt/ni/bin/collectord
else
    progfile=/usr/local/bin/collectord
fi

pidfile=/var/run/collectord.pid

if [ -d /var/lock/subsys ]
then
    lockfile=/var/lock/subsys/collectord
else
    lockfile=/var/lock/collectord
fi

if [ ! -f $progfile ]
then
  echo "Missing executable file $progfile."
  exit 0;
fi

case "$1" in
  start)
    echo -n "Starting collectord: "
    if [ -f $functions ]
    then
	daemon $progfile
    else
	$progfile
    fi
    echo
    touch $lockfile
    ;;

  stop)
    echo -n "Stopping collectord: "
    if [ -f $functions ]
    then
	killproc $progfile -INT
    else
	kill -INT `cat $pidfile`
    fi
    echo
    rm -f $pidfile
    rm -f $lockfile
    ;;

  status)
    if [ -f $functions ]
    then
	status collectord
    fi
    ;;

  reload)
    echo -n "Reloading collectord config: "
    if [ -f $functions ]
    then
	killproc $progfile -HUP
    else
	kill -HUP `cat $pidfile`
    fi
    echo
    ;;

  restart)
    $0 stop
    # Pause briefly for all sockets to be freed, and all threads to finish
    sleep 5
    $0 start
    ;;

  *)
    echo "Usage: $0 {start|stop|status|restart|reload}"
    exit 1
esac

exit 0
