#!/bin/sh
#
# chkconfig: 345 94 07
# description: networkintelligenced (Network Intelligence server daemon)
#	This daemon gathers statistics from the Network Intelligence
#       collectors and forms the central part of the Network
#       Intelligence software.
#

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/networkintelligenced ]
then
    progfile=/opt/ni/bin/networkintelligenced
else
    progfile=/usr/local/bin/networkintelligenced
fi

pidfile=/var/run/networkintelligenced.pid

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

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

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

  stop)
    echo -n "Stopping networkintelligenced: "
    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 networkintelligenced
    fi
    ;;

  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}"
    exit 1
esac

exit 0
