#!/bin/sh
#
# chkconfig: - 345 92 34
# description: Starts and stops the subversion repository creation service
#	       start after smb and stop before
#

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Avoid using root's TMPDIR
unset TMPDIR
[[ ! -d "/tmp/empty" ]] && mkdir "/tmp/empty"
cd /tmp/empty


#
SVNRepoRoot="/export/svnroot"

#
ThisCMD=`basename $0`
LogFile="/var/log/$ThisCMD"
PIDFile="/var/run/$ThisCMD"

case "$1" in
	start)
		echo -n "Starting subversion repository creation service " | tee -a "$LogFile"
		exec /usr/var/utilscripts/CreateRepo.py "$SVNRepoRoot" >> "$LogFile" 2>&1 &
		echo $! > $PIDFile
		echo
	;;
	stop)
		echo -n "Stopping subversion repository creation service" | tee -a "$LogFile"
		kill -USR2 "$(cat "$PIDFile")" && rm -f $PIDFile
		echo
	;;
	reset)
		echo -n "Resetting subversion repository creation service" | tee -a "$LogFile"
		kill -USR1 "$(cat "$PIDFile")"
		echo
	;;
	pause)
		echo -n "Suspending subversion repository creation service " | tee -a "$LogFile"
		kill -STOP "$(cat "$PIDFile")"
		echo
	;;
	resume)
		echo -n "Resuming subversion repository creation service " | tee -a "$LogFile"
		kill -CONT "$(cat "$PIDFile")"
		echo
	;;
	restart)
		echo -n "Restarting subversion repository creation service " | tee -a "$LogFile"
		kill -USR2 "$(cat "$PIDFile")" && rm -f $PIDFile
		exec /usr/var/utilscripts/CreateRepo.py "$SVNRepoRoot" >> "$LogFile" 2>&1 &
		echo $! > $PIDFile
		echo
	;;
	*)
		echo $"Usage: $0 {start|stop|reset|pause|resume|restart}" \
		exit 1
esac

exit $?
