#! /bin/sh
# Copyright (c) 1995-2002 SuSE LINUX Products GmbH, Nuernberg, Germany.
# All rights reserved.
#
# Author: Michael Calmer <Michael.Calmer@suse.de>
#
# /etc/init.d/krb5kdc
#
### BEGIN INIT INFO
# Provides:          krb5kdc
# Required-Start:    $syslog $remote_fs $network
# Should-Start: $time
# Required-Stop:     $syslog $remote_fs $network
# Should-Stop: $time
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Start and stop the Kerberos 5 servers.
# Description:       Kerberos 5 is a trusted third-party authentication system.
#              This script starts and stops the server that Kerberos IV and 5
#              clients need to connect to in order to obtain credentials
### END INIT INFO

#
# krb5kdc      Start and stop the Kerberos 5 servers.
#
# chkconfig:   - 35 65
# description: Kerberos 5 is a trusted third-party authentication system.  \
#	       This script starts and stops the server that Kerberos IV and 5 \
#	       clients need to connect to in order to obtain credentials.
# processname: krb5kdc
#

RETVAL=0
prog="Kerberos 5 KDC"
krb5kdc=/usr/lib/mit/sbin/krb5kdc
krbdir=/var/lib/kerberos/krb5kdc

. /etc/rc.status

# Reset status of this service
rc_reset


# Shell functions to cut down on useless shell instances.
start() {
  	if [ ! -f $krbdir/principal ] ; then
	    echo "No principal database found, exiting."
	    echo
	    exit 0
	fi
	echo -n "Starting $prog"
	startproc ${krb5kdc}

        # Remember status and be verbose
        rc_status -v

}
stop() {
	echo -n  "Shutting down $prog"
	killproc -TERM ${krb5kdc}

        # Remember status and be verbose
        rc_status -v

}
reload() {
	echo -n "Reload service $prog"
	killproc ${krb5kdc} -HUP

        rc_status -v
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  try-restart)
        $0 status
        if test $? = 0; then
                $0 restart
        else
                rc_reset        # Not running is not a failure.
        fi
        # Remember status and be quiet
        rc_status
        ;;

  restart)
	$0 stop
	$0 start

        # Remember status and be quiet
        rc_status
	;;
  reload|force-reload)
        reload
        ;;
  status)
        echo -n "Checking for service $prog"
	checkproc ${krb5kdc}
        rc_status -v
	;;
  *)
	echo "Usage: $0 {start|stop|status|reload|force-reload|restart|try-restart}"
        exit 1
	;;
esac
rc_exit
