#!/bin/bash
#
#     This library is free software; you can redistribute it and/or modify it
#     under the terms of the GNU Lesser General Public License as published by
#     the Free Software Foundation; either version 2.1 of the License, or (at
#     your option) any later version.
#			      
#     This library is distributed in the hope that it will be useful, but
#     WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#     Lesser General Public License for more details.
#      
#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software
#     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# /etc/init.d/request-tracker
# 
### BEGIN INIT INFO
# Provides:          request-tracker
# Required-Start:    $remote_fs $syslog apache2
# Should-Start:      smtp $time mysql postgresql
# Required-Stop:     $remote_fs $syslog apache2
# Should-Stop:       smtp $time mysql postgresql
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Preparing script for Request Tracker
# Description:       This script prepares the needed spool- and 
#	cache directories for Request Tracker during boot of the machine.
### END INIT INFO

RT_LOCALSTATEDIR='__RT_LOCALSTATEDIR__'
# File with user defined values
RT_SYSCONFIG='/etc/sysconfig/request-tracker'

if [ -r "$RT_SYSCONFIG" ]; then
    . "$RT_SYSCONFIG"
else
    echo "$RT_SYSCONFIG does not exist. Using $RT_LOCALSTATEDIR as localstate directory."
fi

. /etc/rc.status
rc_reset

case "$1" in
    start)
	echo -n "Preparing environment for Request Tracker "
	/usr/sbin/request-tracker-prepare.sh
	rc_status -v
	;;
    stop)
	echo -n "Environment for Request Tracker cleaned up "
	rc_status -v
	;;
    try-restart|condrestart)
	if test "$1" = "condrestart"; then
		echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
	fi
	$0 status
	if test $? = 0; then
		$0 restart
	else
		rc_reset	# Not running is not a failure.
	fi
	rc_status
	;;
    restart|reload)
	$0 stop
	$0 start
	rc_status
	;;
    force-reload)
	$0 try-restart
	rc_status
	;;
    status)
	echo -n "Chechking environment for Request Tracker "
	if [ -d "$RT_LOCALSTATEDIR" ]; then
		rc_failed 0
	else
		rc_failed 3
	fi
    rc_status -v	
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
	exit 1
	;;
esac
rc_exit
