#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          rpcbind
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      1
# Short-Description: Start the rpcbind daemon
# Description:       rpcbind is a daemon that converts RPC program numbers
#                    into universal addr
### END INIT INFO

DAEMON=/usr/bin/rpcbind
PATH=/sbin:/bin:/usr/sbin:/usr/bin

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

rpcbind_start () {
	log_begin_msg "Starting rpcbind Daemon"
	start-stop-daemon --name rpcbind --exec $DAEMON --start --
	status=$?
	log_end_msg ${status}
}

rpcbind_stop () {
	log_begin_msg "Stopping rpcbind Daemon"
	start-stop-daemon --name rpcbind --exec $DAEMON --stop --retry 5 || echo -n "... rpcbind is not running"
	log_end_msg $?
}

case "$1" in
	start|stop)
		rpcbind_${1}
		;;
	restart|reload|force-reload)
		rpcbind_stop
		rpcbind_start
		;;
	force-stop)
		rpcbind_stop
		killall rpcbind || true
		sleep 2
		killall -9 rpcbind || true
		;;
	status)
		status_of_proc $DAEMON rpcbind
		exit $?
		;;
	*)
		echo "Usage: /etc/init.d/rpcbind {start|stop|force-stop|restart|reload|force-reload|status}"
		exit 1
		;;
esac

exit 0
