#!/bin/sh
#
# incrond	This shell script enables the incrond daemon
#
# chkconfig:	2345 40 60
#
# description:  This is a daemon which works like cron, but handles filesystem events \
#               instead of time periods and can send notifications via mail, DBus or syslog.
#
# processname:	incrond
# config:	/etc/incron.conf
# pidfile:	/var/run/incrond.pid


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

# Get service config
[ -f /etc/sysconfig/incron ] && . /etc/sysconfig/incron

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/incrond ]; then
		msg_already_running incrond
		return
	fi

	msg_starting incrond
	daemon /usr/sbin/incrond
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/incrond
}

stop() {
	# Stop daemons.
	if [ ! -f /var/lock/subsys/incrond ]; then
		msg_not_running incrond
	fi

	msg_stopping incrond
	killproc incrond
	rm -f /var/lock/subsys/incrond >/dev/null 2>&1
}

condrestart() {
	if [ ! -f /var/lock/subsys/incrond ]; then
		msg_not_running incrond
		RETVAL=$1
		return
	fi

	stop
	start
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status incrond
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
