#!/bin/sh
#
# ypserv:	Starts the yp-server
#
# chkconfig:	345 41 64
#
# 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.
#
# processname:	ypserv
# config:	/etc/ypserv.conf


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

# Get network config
. /etc/sysconfig/network

# Get service config
[ -f /etc/sysconfig/ypserv-ypserv ] && . /etc/sysconfig/ypserv-ypserv

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down ypserv
		exit 1
	fi
else
	exit 0
fi

check_nisdomain()
{
	if [ -n "$NISDOMAIN" ]; then
		return 0
	else
		nls "Setup /etc/sysconfig/network::NISDOMAIN before use %s." ypserv >&2
		exit 6
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	check_nisdomain
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/ypserv ]; then
		msg_starting "NIS server"
		daemon ypserv
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ypserv
	else
		msg_already_running ypserv
	fi
	;;
  stop)
	check_nisdomain
	if [ -f /var/lock/subsys/ypserv ]; then
		msg_stopping "NIS server"
		killproc ypserv
		rm -f /var/lock/subsys/ypserv
	else
		msg_not_running "NIS server"
	fi
	;;
  status)
	check_nisdomain
	status ypserv
	exit $?
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
