#!/bin/sh
#
# ypserv:       Starts the NIS server and rpc.yppasswdd
#
# Version:      $Id: ypserv.init,v 1.6 1997/12/21 16:48:10 kukuk Exp $
#
# Author:       Thorsten Kukuk <kukuk@vt.uni-paderborn.de>
#
# chkconfig: 345 65 35
# description: ypserv is an implementation of the standard NIS/YP networking \
#              protocol. It allows network-wide distribution of hostname, \
#              username, and other information databases. This is the NIS \
#              server, and is not needed on NIS clients. rpc.yppasswdd should \
#              be run on NIS master servers which need to allow users on NIS \
#              clients to change their passwords. It does not need to be run \
#              on NIS clients or NIS slave servers.

# Source function library.
. /etc/rc.d/init.d/functions
# getting the YP-Domainname (NISDOMAIN)
. /etc/sysconfig/network

# See how we were called.
case "$1" in
  start)
	echo -n "Starting YP server services: "
	daemon ypserv
	daemon rpc.ypxfrd
	/usr/lib/yp/makedbm -u /var/yp/$NISDOMAIN/passwd.byname | \
       	grep YP_MASTER_NAME | while read key server; do
		if [ "`hostname`" = "$server" ]; then
		    daemon rpc.yppasswdd -D /etc/yp
		    touch /var/lock/subsys/rpc.yppasswdd
		fi
	    done
	echo
	touch /var/lock/subsys/ypserv
	;;
  stop)
	echo -n "Stopping YP server services: "
	killproc rpc.ypxfrd
	killproc ypserv
	if [ -f /var/lock/subsys/rpc.yppasswdd ]; then
	    killproc rpc.yppasswdd
	    rm -f /var/lock/subsys/rpc.yppasswdd
	fi
	rm -f /var/lock/subsys/ypserv
        echo
	;;
  status)
	status ypserv
	status rpc.ypxfrd
	status rpc.yppasswdd
	;;
  restart)
        $0 stop
        $0 start
	;;
  *)
	echo "Usage: ypserv.init {start|stop|status|restart}"
	exit 1
esac

exit 0
