#! /bin/sh
#
# portmap       Start/Stop RPC portmapper
#
# chkconfig: 345 13 87
# description: The portmapper manages RPC connections, which are used by \
#		protocols such as NFS and NIS. The portmap server must be \
#		running on machines which act as servers for protocols which \
#		make use of the RPC mechanism.
# processname: portmap

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

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" != no -a -x /sbin/portmap ] || exit

LOCKFILE=/var/lock/subsys/portmap
RETVAL=0

start()
{
	echo -n "Starting portmapper: "
	daemon portmap
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch "$LOCKFILE"
}

stop()
{
	echo -n "Stopping portmap services: "
	killproc portmap
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f "$LOCKFILE"
}

restart()
{
	pmap_dump >/var/run/portmap.state
	stop
	start
	pmap_set < /var/run/portmap.state
	rm -f /var/run/portmap.state
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status portmap
		RETVAL=$?
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|reload|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
