#!/bin/sh
#
# slug_watch	daemon to update Refs list
#
# chkconfig:	345 99 01
#
# description:	daemon for PLD gitolite setup
#
# processname:	slug_watch
# pidfile: /var/run/slug_watch.pid
#
# $Id$

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

# Source slug_watch configuration
. /etc/sysconfig/slug_watch


pidfile="/var/run/slug_watch.pid"

if [ ! -n "$WATCHDIR"  -o ! -n "$REFREPODIR" ]; then
	echo "WATCHDIR or REFREPODIR variable not set"
	exit 1
fi

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

	msg_starting "slug_watch"
	daemon /usr/bin/slug_watch -u git -w "$WATCHDIR" -r "$REFREPODIR" $OTHER_OPTIONS -d start 
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/slug_watch
}

stop() {
	if [ ! -f /var/lock/subsys/slug_watch ]; then
		msg_not_running "slug_watch"
		return
	fi

	# Stop daemons.
	msg_stopping "slug_watch"
	killproc slug_watch
	rm -f /var/lock/subsys/slug_watch
}


RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  status)
	status --pidfile $pidfile slug_watch
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|status}"
	exit 3
esac

exit $RETVAL
