#!/bin/sh
#
# ypbind:       Starts the ypbind Daemon
#
# Version:      @(#) /etc/rc.d/init.d/ypbind.init 1.1
#
# chkconfig: 345 17 83
# description: This is a daemon which runs on NIS/YP clients and binds them \
#              to a NIS domain. It must be running for systems based on glibc \
#              to work as NIS clients, but it should not be enabled on systems \
#              which are not using NIS.
# processname: ypbind
# config: /etc/yp.conf
#
### BEGIN INIT INFO
# Provides: ypbind
# Required-Start: $remote_fs $portmap
# Required-Stop: $remote_fs $portmap
# Should-Start: ypserv slpd
# Should-Stop: ypserv slpd
# Default-Start: 3 4 5
# Short-Description: The ypbind daemon (for NIS/YP clients)
# Description: This is a daemon which runs on NIS/YP clients and binds them
#              to a NIS domain. It must be running for systems based on glibc
#              to work as NIS clients, but it should not be enabled on systems
#              which are not using NIS.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

RETVAL=0

# See how we were called.
case "$1" in
  start)
	gprintf "Binding to the NIS domain... "
	daemon ypbind
	echo
        # the following fixes problems with the init scripts continuing
	# even when we are really not bound yet to a server, and then things
	# that need NIS fail.
	pid=`pidofproc ypbind`
	if [ -n "$pid" ]; then
	  gprintf "Listening for an NIS domain server: "
	  times=0
	  until ypwhich > /dev/null 2>&1 || [ "$times" = "10" ]
	  do
             gprintf "." ;
	     sleep 1
	     times=$[$times+1]
	  done
          ypwhich
	fi
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ypbind
	;;
  stop)
	gprintf "Shutting down NIS services: "
	killproc ypbind
	RETVAL=$?
	if [ $RETVAL -eq 0 ] ; then
	  rm -f /var/lock/subsys/ypbind
	  # if  we used brute force (like kill -9) we don't want those around
	  rm -f /var/yp/binding/$(domainname)*
	fi
	echo
	;;
  status)
	status ypbind
	RETVAL=$?
	;;
  condrestart)
        if [ -f /var/lock/subsys/ypbind ]; then
	    $0 stop
	    $0 start
	    RETVAL=$?
	fi
	;;
  restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  *)
	gprintf "*** Usage: ypbind {start|stop|status|restart}\n"
	exit 1
esac

exit $RETVAL

