#!/bin/sh
#
# innwatch	Monitor the state of INN and the system
#
# chkconfig: - 96 04
# description:	Monitor the state of INN and the system
# processname: innwatch
# config: /etc/innwatch.conf
# pidfile: /var/run/innwatch.pid

### BEGIN INIT INFO
# Provides:             innwatch
# Required-Start:       $network
# Required-Stop:        $network
# Default-Start:
# Default-Stop:
# Short-Description:    Start innwatch at boot time
# Description:          Enable innwatch service.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

# Source config (contains $INNWATCH variable).
SourceIfNotEmpty /usr/libexec/inn/innshellvars

PIDFILE=/var/run/news/innwatch.pid
LOCKFILE=/var/lock/subsys/innwatch
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --background --expect-user root  -- $INNWATCH -i 60
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root --displayname innwatch /bin/sh
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	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 root --displayname innwatch /bin/sh
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
