#! /bin/sh
# Copyright (c) 1999 SuSE GmbH Nuernberg, Germany.  All rights reserved.
#
# Author: Thorsten Kukuk <kukuk@suse.de>, 1999
#
# /sbin/init.d/nisplus
#

. /etc/rc.config

base=${0##*/}
link=${base#*[SK][0-9][0-9]}

if [ "$NIS_EMULYP" = yes ]
then
    EMULYP=-Y
fi

return=$rc_done
case "$1" in
    start)
        echo -n "Starting NIS+ services:"
        ## Start daemon with startproc(8). If this fails
        ## the echo return value is set appropriate.

	startproc /usr/sbin/keyserv && echo -n " keyserv" || return=$rc_failed
        if [ -f /var/nis/NIS_COLD_START -a -f /usr/sbin/nis_cachemgr ]
        then
            startproc /usr/sbin/nis_cachemgr && echo -n " nis_cachemgr" || return=$rc_failed
        fi
        if [ -d /var/nis/data -a -f /usr/sbin/rpc.nisd ]
        then
           startproc /usr/sbin/rpc.nisd $EMULYP && echo -n " nisd" || return=$rc_failed
           startproc /usr/sbin/rpc.nispasswdd && echo -n " nispasswdd" || return=$rc_failed
        fi

        echo -e "$return"
        ;;
    stop)
        echo -n "Shutting down NIS+ services"
        ## Stop daemon with killproc(8) and if this fails
        ## set echo the echo return value.

        if [ -d /var/nis/data -a -f /usr/sbin/rpc.nisd ]
        then
           killproc -TERM /usr/sbin/rpc.nispasswdd && echo -n " nispasswdd" || return=$rc_failed
           killproc /usr/sbin/rpc.nisd && echo -n " nisd" || return=$rc_failed
        fi
        if [ -f /var/nis/NIS_COLD_START -a -f /usr/sbin/nis_cachemgr ]
        then
            killproc -TERM /usr/sbin/nis_cachemgr && echo -n " nis_cachemgr" || return=$rc_failed
        fi
	killproc -TERM /usr/sbin/keyserv && echo -n " keyserv" || return=$rc_failed

        echo -e "$return"
        ;;
    restart)
        ## If first returns OK call the second, if first or
        ## second command fails, set echo return value.
        $0 stop  &&  $0 start  ||  return=$rc_failed
        ;;
    reload)
        ## Choose ONE of the following two cases:

        ## First possibility: A few services accepts a signal
        ## to reread the (changed) configuration.

        #echo -n "Reload service foo"
        #killproc -HUP /usr/sbin/foo || return=$rc_failed
        #echo -e "$return"

        ## Exclusive possibility: Some services must be stopped
        ## and started to force a new load of the configuration.

        $0 stop  &&  $0 start  ||  return=$rc_failed
        ;;
    status)
        echo -n "Checking for NIS+ services: "
        ## Check status with checkproc(8), if process is running
        ## checkproc will return with exit status 0.

        checkproc /usr/sbin/keyserv && echo OK || echo No process
        ;;

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

test "$return" = "$rc_done" || exit 1
exit 0
