#!/bin/bash
# Begin $rc_base/init.d/heimdal

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org

#$LastChangedBy: bdubbs $
#$Date: 2005-08-01 14:29:19 -0500 (Mon, 01 Aug 2005) $

. /etc/sysconfig/rc
. $rc_functions

case "$1" in
	start)  
		boot_mesg -n "Starting KDC Server Daemon..."
		if test -f "/var/run/kdc.pid"
		then
			boot_mesg "kdc already running!" ${WARNING}
			echo_warning
		else
			/usr/sbin/kdc &
			sleep 1
			if test -f "/var/run/kdc.pid"
			then
				echo ""
				echo_ok
			else
				echo ""
				echo_failure
			fi
		fi
		boot_mesg -n "Starting KDC kpasswdd Daemon..."
		if test -f "/var/run/kpasswdd.pid"
		then
			boot_mesg "kpasswdd already running!" ${WARNING}
			echo_warning
		else
			/usr/sbin/kpasswdd &
			sleep 1
			if test -f "/var/run/kpasswdd.pid"
			then
				echo ""
				echo_ok
			else
				echo ""
				echo_failure
			fi
		fi
		boot_mesg -n "Starting KDC kadmind Daemon..."
		if test -f "/var/run/kadmind.pid"
		then
			boot_mesg "kadmind already running!" ${WARNING}
			echo_warning
		else
			/usr/sbin/kadmind &
			sleep 1
			if test -f "/var/run/kadmind.pid"
			then
				echo ""
				echo_ok
			else
				echo ""
				echo_failure
			fi
		fi
		;;

	stop)   
		boot_mesg "Stopping KDC kadmind Daemon..."
		killproc /usr/sbin/kadmind
		boot_mesg "Stopping KDC kpasswdd Daemon..."
		killproc /usr/sbin/kpasswdd
		boot_mesg "Stopping KDC Server Daemon..."
		killproc /usr/sbin/kdc
		;;

	restart)
		$0 stop
		sleep 1
		$0 start
		;;

	status)
		statusproc /usr/sbin/kdc
		statusproc /usr/sbin/kpasswdd
		statusproc /usr/sbin/kadmind
		;;

	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 1
		;;
esac

# End $rc_base/init.d/heimdal
