#!/bin/sh
#
# idmapd        Start up and shut down RPC name to UID/GID mapper.
#
# chkconfig:    345 19 69
# description:  NFSv4-related daemon that maps usernames to UID/GID numbers
#               and vice versa
# processname:  rpc.idmapd
# pidfile:      /var/run/rpc.idmapd.pid

WITHOUT_RC_COMPAT=1

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

# Source networking configuration.
# Check that networking is up.
SourceIfNotEmpty /etc/sysconfig/network && [ "$NETWORKING" != no ] || exit

IDMAPD=/sbin/rpc.idmapd
RPCPIPEFS=/var/lib/nfs/rpc_pipefs

[ -x "$IDMAPD" ] || exit

PIDFILE=/var/run/rpc.idmapd.pid
LOCKFILE=/var/lock/subsys/idmapd
RETVAL=0

# noop under 2.4 kernels
[ -d /sys/class ] || exit 0

mount_rpcpipefs()
{
    [ -d "$RPCPIPEFS/nfs" ] || {
	modprobe sunrpc ||:
	mount -t rpc_pipefs rpc_pipefs "$RPCPIPEFS"
    }
}

start()
{
    mount_rpcpipefs
    RETVAL=$?
    [ $RETVAL -eq 0 ] || return

    start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root $IDMAPD
    RETVAL=$?
    return $RETVAL
}

stop()
{
    stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root $IDMAPD
    RETVAL=$?
    return $RETVAL
}

restart()
{
    stop
    start
}

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart|reload)
	restart
	;;
    condstop)
	if [ -e "$LOCKFILE" ]; then
	    stop
	fi
	;;
    condrestart|condreload)
	if [ -e "$LOCKFILE" ]; then
	    restart
	fi
	;;
    status)
	status --pidfile "$PIDFILE" --expect-user root $IDMAPD
	RETVAL=$?
	;;
    *)
	msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
	RETVAL=1
esac

exit $RETVAL
