#!/bin/sh
#
# rpcidmapd     Start up and shut down RPC name to UID/GID mapper
#
# chkconfig: 345 18 68
# description: Starts user-level daemon for NFSv4 that maps user \
#              names to UID and GID numbers.
#
### BEGIN INIT INFO
# Provides: rpcidmapd
# Required-Start: $network $portmap
# Required-Stop: $network $portmap
# Default-Start: 3 4 5
# Short-Description: RPC name to UID/GID daemon
# Description: Starts user-level daemon for NFSv4 that maps user
#              names to UID and GID numbers.
### END INIT INFO

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

# Set defaults and read configuration
NAME=rpc.idmapd
BINARY=$NAME
LOCKFILE=/var/lock/subsys/$NAME
RPCIDMAPD_OPTIONS=
[ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs

start() {
    res=0
    if [ ! -f $LOCKFILE ]; then
	echo -n "Starting $NAME:"

	# Load sunrpc which mounts the rpc_pipes fs.
	/sbin/modprobe sunrpc || exit 1

	# Start daemon.
	daemon $BINARY $RPCIDMAPD_OPTIONS
	res=$?
	echo
	[ $res -eq 0 ] && touch $LOCKFILE
    fi
    return $res
}

stop() {
    echo -n "Stopping $NAME: "
    killproc $BINARY
    res=$?
    echo
    [ $res -eq 0 ] && rm -f $LOCKFILE
    return $res
}

reload() {
    echo -n "Reloading $NAME: "
    killproc $BINARY -HUP
    res=$?
    echo
    return $res
}


case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
	status $BINARY
	;;
    reload)
	reload
	;;
    restart)
	stop
	start
	;;
    condrestart)
	if [ -f $LOCKFILE ]; then
	    stop
	    start
	fi
	;;
    *)
	echo "Usage: $0 {start|stop|status|reload|restart|condrestart}"
	exit 1
	;;
esac

exit $?
