#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

PID=`pidof -o %PPID /usr/sbin/nsca`

start() {
  stat_busy "Starting NSCA"
  [ -z "$PID" ] && /usr/sbin/nsca -c /etc/nsca/nsca.cfg --daemon
  if [ $? -gt 0 ]; then
    stat_fail
  else
    add_daemon nsca
    stat_done
  fi
}

stop() {
  stat_busy "Stopping NSCA"
  [ ! -z "$PID" ]  && kill $PID &> /dev/null
  if [ $? -gt 0 ]; then
    stat_fail
  else
    rm_daemon nsca
    stat_done
  fi
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    sleep 3
    start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"  
esac
exit 0
