#!/bin/sh
#
# rpcbind	Start/Stop RPC universal addresses to RPC program number mapper
#
# chkconfig:	345 11 89
#
# description:	The rpcbind utility is a server that converts RPC program \
#		numbers into universal addresses.  It must be running on \
#		the host to be able to make RPC calls on a server on that \
#		machine.
# processname:	rpcbind


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

# Get network config
. /etc/sysconfig/network

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

# 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 rpcbind
		exit 1
	fi
else
	exit 0
fi

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/rpcbind ]; then
		msg_already_running rpcbind
		return
	fi

	msg_starting rpcbind
	daemon /sbin/rpcbind -w $RPCBIND_OPTIONS
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/rpcbind
}

stop() {
	if [ ! -f /var/lock/subsys/rpcbind ]; then
		msg_not_running rpcbind
		return
	fi

	msg_stopping rpcbind
	killproc rpcbind
	rm -f /var/lock/subsys/rpcbind
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  cleanup)
	stop
	start
	;;
  restart|force-reload)
	stop
	start
	;;
  status)
	status rpcbind
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|cleanup|status}"
	exit 3
esac

exit $RETVAL
