#!/bin/sh
#
# iwatch	Realtime filesystem monitor.
#
# chkconfig: - 90 10
# description:	iWatch is a realtime filesystem monitoring program. Its purpose is to monitor \
#		any changes in a specific directory or file and send email notification \
#		immediately after the change. This can be very useful to watch a sensible file \
#		or directory against any changes, like files /etc/passwd,/etc/shadow or \
#		directory /bin or to monitor the root directory of a website against \
#		any unwanted changes.
# processname:	iwatch
# config: /etc/iwatch.xml
# pidfile: /var/run/iwatch.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

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

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- iwatch -d -p "$PIDFILE"
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --displayname iwatch --name iwatch --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- perl
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading iwatch
	stop_daemon --displayname iwatch --name iwatch --pidfile "$PIDFILE" --expect-user root -HUP -- perl
	RETVAL=$?
	return $RETVAL
} 

# 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 --displayname iwatch --name iwatch --pidfile "$PIDFILE" --expect-user root -- perl
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
