#!/bin/sh
#PKG krb5-server
#INIT 70
. /etc/rc.conf

case $1 in
autostop) ;;
autostart)
	test x"${kdc:-NO}" = x"NO" && exit 0
	test x"$kdc" = x"DAEMON" && test -x /bin/mksh && exec mksh -T- $0 start
	exec sh $0 start
	;;
start)
	if [[ ! -f /etc/krb5kdc/principal ]];then
		echo "You need to create a database first!"
		echo "Use kdb5_util create -s"
		exit 1
	fi
	/usr/sbin/krb5kdc
	/usr/sbin/kadmind &
	;;
stop)
	kill $(pgrep -f /usr/sbin/krb5kdc)
	kill $(pgrep -f /usr/sbin/kadmind)
	;;
restart)
	sh $0 stop
	sh $0 start
	;;
*)
	echo "Usage: $0 {start | stop | restart}"
	exit 1
	;;
esac
exit $?
