#!/bin/sh
#=================================================================
# Begin nagios
#
# Description :  Nagios is a service monitoring system
# chkconfig: - 85 15
#
#=================================================================

### BEGIN INIT INFO
# Provides:            nagios
# Required-Start:      network 
# Should-Start:
# Default-Start:         3 4 5
# Default-Stop:        0 1 2 6
# Short-Description:   Starts nagios daemon.
# Description:         Starts nagios daemon.
### END INIT INFO

. /lib/lsb/init-functions

# Some functions to make the below more readable
PROG=nagios
doexec="/usr/bin/$PROG"
config="/etc/nagios/nagios.cfg"
PID_FILE="/run/nagios.lock"
user=$PROG

[ -e /etc/sysconfig/$PROG ] && . /etc/sysconfig/$PROG

check_config()

{
$exec -v $config > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -ne 0 ] ; then
  log_info_msg "$PROG Configuration validation failed"
  /bin/false
  evaluate_retval
  exit 1
  fi
}

case "$1" in
    start)
        log_info_msg "Starting $PROG Server..."
        start_daemon -f $doexec -d $config
        evaluate_retval
        ;;

    stop)
        log_info_msg "Stopping $PROG Server..."
        killproc -p $PID_FILE $doexec
        evaluate_retval
        ;;

    reload)
        log_info_msg "Reloading $PROG Server..."
        pid=`cat $PID_FILE 2>/dev/null`

        if [ -n "${pid}" ]; then
           kill -HUP "${pid}"
        else
           (exit 1)
        fi

        evaluate_retval
        ;;

    restart)
        $0 stop
        sleep 1
        $0 start
        ;;

    condrestart)
        pid=`cat $PID_FILE 2>/dev/null`
        if [ -n "${pid}"  -a -d /proc/$pid ]; then
	  $0 restart
	  fi
        ;;

    status)
        statusproc $doexec
        ;;

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

