#!/bin/sh
#
# ndo2db-3x		Nagios Data Output Daemon for Nagios(R) 3.x
#
# chkconfig: - 98 02
# description:	This standalone daemon reads input (that was produced \
#		by the NDOMOD broker module) from a TCP or Unix domain \
#		socket, parses that data, and then dumps it into one or \
#		more MySQL databases.  The daemon is capable of handling \
#		multiple client connections simultaneously, so you can \
#		have multiple instances of the NDOMOD module writing to \
#		the same TCP or Unix domain socket at the same time.
# processname: ndo2db-3x
# config: /etc/nagios/ndo2db.cfg
# pidfile: /var/run/nagios/ndo2db.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

NGUSER=nagios
DAEMON=/usr/sbin/ndo2db-3x
CFGFILE=/etc/nagios/ndo2db.cfg
PIDFILE=/var/run/nagios/ndo2db.pid
LOCKFILE=/var/lock/subsys/ndo2db
RETVAL=0

start()
{
#	touch "$PIDFILE"
#	chown "$NGUSER":"$NGUSER" "$PIDFILE"
    start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$NGUSER" -- "$DAEMON" -c "$CFGFILE"
    RETVAL=$?
    return $RETVAL

}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$NGUSER" -- "$DAEMON"
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading ndo2db-3x
	stop
	start
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user "$NGUSER" -- "$DAEMON"
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
