#! /bin/sh

set -e

PATH=/bin:/usr/bin:/sbin:/usr/sbin
OPTIONS=

test -x $DAEMON || exit 0

# Starting the daemons in the background with output redirected to /dev/null
# means that you really need to have the master password stashed.
# To manually enter the password edit this file to not do these things.

case "$1" in
  start)
    echo -n "Starting Kerberos KDC services:"
    echo -n \ kerberos ; start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/kerberos -- $OPTIONS >/dev/null 2>/dev/null &
    echo -n \ kadmind  ; start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/kadmind  -- $OPTIONS >/dev/null 2>/dev/null &
    echo .
    ;;
  stop)
    echo -n "Stopping Kerberos KDC services:"
    echo -n \ kerberos ; start-stop-daemon --stop --quiet --oknodo --exec /usr/sbin/kerberos
    echo -n \ kadmind  ; start-stop-daemon --stop --quiet --oknodo --exec /usr/sbin/kadmind
    echo .
    ;;
  restart|force-reload)
    echo -n "Stopping Kerberos KDC services:"
    echo -n \ kerberos ; start-stop-daemon --stop --quiet --oknodo --exec /usr/sbin/kerberos 
    echo -n \ kadmind  ; start-stop-daemon --stop --quiet --oknodo --exec /usr/sbin/kadmind  
    echo .
    sleep 1
    echo -n "Starting Kerberos KDC services:"
    echo -n \ kerberos ; start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/kerberos -- $OPTIONS >/dev/null 2>/dev/null & 
    echo -n \ kadmind  ; start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/kadmind  -- $OPTIONS >/dev/null 2>/dev/null &
    echo .
    ;;
  *)
    echo "Usage: /etc/init.d/kerberos4-kdc {start|stop|restart|force-reload}"
    exit 1
    ;;
esac

exit 0
