Sophie

Sophie

distrib > Mandriva > 2009.1 > x86_64 > by-pkgid > 10db112dac66a69e0c4937f5be9be3bc > files > 3

nfs-utils-1.1.5-1mdv2009.1.src.rpm

#!/bin/sh

# chkconfig: 345 14 86
# description: NFS support files common to client and server

### BEGIN INIT INFO
# Provides:          nfs-common
# Required-Start:    $portmap
# Required-Stop:     $portmap
# Default-Start:     3 4 5 S
# Default-Stop:      0 1 6
# Short-Description: NFS support files common to client and server
# Description:       NFS is a popular protocol for file sharing across
#		     TCP/IP networks. This service provides various
#                    support functions for NFS mounts.
### END INIT INFO

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

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

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

# Read config
NAME="NFS common utilities"
LOCKFILE=/var/lock/subsys/nfs-common
NEED_STATD=
NEED_IDMAPD=
NEED_GSSD=
PIPEFS_MOUNTPOINT=/var/lib/nfs/rpc_pipefs
[ -f /etc/sysconfig/nfs-common ] && . /etc/sysconfig/nfs-common

# Parse the fstab file, and determine whether we need idmapd and gssd.
# (The /etc/sysconfig settings, if any, will override our autodetection)
AUTO_NEED_IDMAPD=no
AUTO_NEED_GSSD=no

while read DEV MTPT FSTYPE OPTS REST; do
    if [ "$FSTYPE" = "nfs4" ]; then
        AUTO_NEED_IDMAPD=yes
    fi
    case "$OPTS" in
        sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5i,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
	    AUTO_NEED_GSSD=yes
	;;
    esac
done < /etc/fstab

# We also need idmapd if we run an NFSv4 server. It's fairly difficult
# to autodetect whether there are NFSv4 exports or not, and idmapd is not a
# particularily heavy daemon, so we auto-enable it if we find an /etc/exports
# file. This does not mean that there are NFSv4 or other mounts active (or
# even that nfs-server is installed), but it matches what the "start"
# condition in nfs-server's init script does, which has a value in itself.
if [ -f /etc/exports ]; then
    AUTO_NEED_IDMAPD=yes
fi

case "$NEED_STATD" in
    yes|no)
        ;;
    *)
        NEED_STATD=yes
        ;;
esac

case "$NEED_IDMAPD" in
    yes|no)	
        ;;
    *)
        NEED_IDMAPD=$AUTO_NEED_IDMAPD
	;;
esac

case "$NEED_GSSD" in
    yes|no)	
        ;;
    *)
        NEED_GSSD=$AUTO_NEED_GSSD
	;;
esac

do_modprobe() {
    if [ -x /sbin/modprobe -a -f /proc/modules ]; then
        modprobe -q "$1" || true
    fi
}

do_mount() {
    if ! grep -E -qs "$1\$" /proc/filesystems; then
	return 1
    fi
    if ! mountpoint -q "$2"; then
	mount -t "$1" "$1" "$2"
	return
    fi
    return 0
}

do_umount() {
    if mountpoint -q "$1"; then
	umount "$1"
    fi
    return 0
}

start()  {
    if [ ! -f $LOCKFILE ]; then
	echo "Starting $NAME"

	# Set the ports lockd should listen on
	if [ -n "$LOCKD_TCPPORT" ]; then
	    /sbin/sysctl -w fs.nfs.nlm_tcpport=$LOCKD_TCPPORT >/dev/null 2>&1
	fi
	if [ -n "$LOCKD_UDPPORT" ]; then
	    /sbin/sysctl -w fs.nfs.nlm_udpport=$LOCKD_UDPPORT >/dev/null 2>&1
	fi

	if [ "$NEED_STATD" = yes ]; then
	    echo -n "Starting rpc.statd"
	    daemon rpc.statd $STATD_OPTIONS
	    rc=$?
	    echo
	    if [ $rc != 0 ]; then
		return $rc
	    fi
	fi

	if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]; then
	    do_modprobe nfs
	    do_modprobe nfs4
	    if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT; then
		if [ "$NEED_IDMAPD" = yes ]; then
		    echo -n "Starting rpc.idmapd"
		    daemon rpc.idmapd $RPCIDMAPD_OPTIONS
		    rc=$?
		    echo
		    if [ $rc != 0 ]; then
			return $rc
		    fi
		fi
		if [ "$NEED_GSSD" = yes ]; then
		    do_modprobe rpcsec_gss_krb5

		    echo -n "Starting rpc.gssd"
		    daemon rpc.gssd $RPCGSSD_OPTIONS
		    rc=$?
		    echo
		    if [ $rc != 0 ]; then
			return $rc
		    fi
		fi
	    fi
	fi

	touch $LOCKFILE
    fi
    return 0
}

stop()  {
    echo "Stopping $NAME"

    if [ "$NEED_GSSD" = yes ]; then
	echo -n "Stopping rpc.gssd: "
	killproc rpc.gssd
	rc=$?
	echo
	if [ $rc != 0 ]; then
	    return $rc
	fi
    fi
    if [ "$NEED_IDMAPD" = yes ]; then
	echo -n "Stopping rpc.idmapd: "
	killproc rpc.idmapd
	rc=$?
	echo
	if [ $rc != 0 ]; then
	    return $rc
	fi
    fi
    if status lockd >/dev/null; then
	echo -n "Stopping kernel lockd: "
	killproc lockd -KILL
	echo
    fi
    if [ "$NEED_STATD" = yes ]; then
	echo -n "Stopping rpc.statd: "
	killproc rpc.statd
	rc=$?
	echo
	if [ $rc != 0 ]; then
	    return $rc
	fi
    fi
    do_umount $PIPEFS_MOUNTPOINT 2>/dev/null || true

    # Reset the lockd ports if they were set
    if [ -n "$LOCKD_TCPPORT" ]; then
	/sbin/sysctl -w fs.nfs.nlm_tcpport=0 >/dev/null 2>&1
    fi
    if [ -n "$LOCKD_UDPPORT" ]; then
	/sbin/sysctl -w fs.nfs.nlm_udpport=0 >/dev/null 2>&1
    fi

    rm -f $LOCKFILE
    return 0
}

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
	if [ "$NEED_STATD" = yes ]; then
	    status rpc.statd
	fi

	if [ "$NEED_GSSD" = yes ]; then
	    status rpc.gssd
	fi

	if [ "$NEED_IDMAPD" = yes ]; then
	    status rpc.idmapd
	fi
	;;
    restart|reload)
	stop
	sleep 1
	start
	;;
    *)
	echo "Usage: $0 {start|stop|restart|reload|status}"
	exit 1
	;;
esac

exit 0