walters / rpms / nfs-utils

Forked from rpms/nfs-utils 6 years ago
Clone
cvsdist c905793
#!/bin/sh
cvsdist c905793
#
cvsdist c905793
# nfs           This shell script takes care of starting and stopping
cvsdist c905793
#               the NFS services.
cvsdist c905793
#
cvsdist c905793
# chkconfig: - 60 20
cvsdist c905793
# description: NFS is a popular protocol for file sharing across TCP/IP \
cvsdist c905793
#              networks. This service provides NFS server functionality, \
cvsdist c905793
#              which is configured via the /etc/exports file.
cvsdist c905793
# probe: true
cvsdist 6ae4499
# config: /etc/sysconfig/nfs
cvsdist c905793
cvsdist c905793
# Source function library.
cvsdist c905793
. /etc/rc.d/init.d/functions
cvsdist c905793
cvsdist c905793
# Source networking configuration.
cvsdist c905793
if [ ! -f /etc/sysconfig/network ]; then
cvsdist c905793
    exit 0
cvsdist c905793
fi
cvsdist c905793
cvsdist c905793
. /etc/sysconfig/network
cvsdist c905793
cvsdist c905793
# Check that networking is up.
cvsdist c905793
[ ${NETWORKING} = "no" ] && exit 0
cvsdist c905793
cvsdist c905793
[ -x /usr/sbin/rpc.nfsd ] || exit 0
cvsdist c905793
[ -x /usr/sbin/rpc.mountd ] || exit 0
cvsdist c905793
[ -x /usr/sbin/exportfs ] || exit 0
cvsdist 1c22dc7
cvsdist 1c22dc7
# Don't fail if /etc/exports doesn't exist; create a bare-bones version and continue.
cvsdist 1c22dc7
[ -s /etc/exports ] || \
cvsdist 1c22dc7
    { echo "#" > /etc/exports && chmod u+rw,g+r,o+r /etc/exports ; } || \
cvsdist 1c22dc7
    { echo "/etc/exports does not exist" ; exit 0 ; }
cvsdist c905793
cvsdist 6ae4499
# Check for and source configuration file otherwise set defaults
cvsdist 6ae4499
# TUNE_QUEUE: controls whether to up the size of input queues
cvsdist 6ae4499
[ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs
cvsdist 6ae4499
cvsdist 6ae4499
[ -z "$MOUNTD_NFS_V2" ] && MOUNTD_NFS_V2=auto
cvsdist 6ae4499
[ -z "$MOUNTD_NFS_V3" ] && MOUNTD_NFS_V3=auto
cvsdist 6ae4499
cvsdist 71d63d6
# Number of servers to be started by default
cvsdist 6ae4499
[ -z "$RPCNFSDCOUNT" ] && RPCNFSDCOUNT=8
cvsdist c905793
cvsdist 6ae4499
# Remote quota server
cvsdist 6ae4499
[ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`
cvsdist 6ae4499
cvsdist 6ae4499
# Get the initial values for the input sock queues
cvsdist 6ae4499
# at the time of running the script.
cvsdist 6ae4499
if [ "$TUNE_QUEUE" = "yes" ]; then
cvsdist 6ae4499
    RMEM_DEFAULT=`/sbin/sysctl -n net.core.rmem_default`
cvsdist 6ae4499
    RMEM_MAX=`/sbin/sysctl -n net.core.rmem_max`
cvsdist 6ae4499
    # 256kb recommended minimum size based on SPECsfs NFS benchmarks
cvsdist 6ae4499
    [ -z "$NFS_QS" ] && NFS_QS=262144
cvsdist 7a8b656
fi
cvsdist 7a8b656
cvsdist c905793
# See how we were called.
cvsdist c905793
case "$1" in
cvsdist c905793
  start)
cvsdist c905793
	# Start daemons.
cvsdist 6ae4499
	# Apply input queue increase for nfs server
cvsdist 6ae4499
	if [ "$TUNE_QUEUE" = "yes" ]; then
cvsdist 6ae4499
 	    /sbin/sysctl -w net.core.rmem_default=$NFSD_QS >/dev/null 2>&1
cvsdist 6ae4499
	    /sbin/sysctl -w net.core.rmem_max=$NFSD_QS >/dev/null 2>&1
cvsdist 6ae4499
	fi
cvsdist 4f69ea4
	action $"Starting NFS services: " /usr/sbin/exportfs -r
cvsdist 6ae4499
	if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
cvsdist 6ae4499
	    echo -n "Starting NFS quotas: "
cvsdist 7a8b656
	    daemon rpc.rquotad
cvsdist 7a8b656
	    echo
cvsdist 7a8b656
	fi
cvsdist 4f69ea4
	echo -n $"Starting NFS daemon: "
cvsdist c905793
	daemon rpc.nfsd $RPCNFSDCOUNT
cvsdist c905793
	echo
cvsdist 6ae4499
cvsdist 6ae4499
	[ -n "$MOUNTD_PORT" ] \
cvsdist 6ae4499
	&& RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
cvsdist 6ae4499
cvsdist 6ae4499
	case $MOUNTD_NFS_V2 in
cvsdist 6ae4499
	auto|AUTO)
cvsdist 6ae4499
	    # Let's see if we support NFS version 2.
cvsdist 6ae4499
	    /usr/sbin/rpcinfo -u localhost nfs 2 &>/dev/null
cvsdist 6ae4499
	    if [ $? -ne 0 ]; then
cvsdist 6ae4499
		RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 2"
cvsdist 6ae4499
	    fi
cvsdist 6ae4499
	    ;;
cvsdist 6ae4499
	no|NO)
cvsdist 6ae4499
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 2"
cvsdist 6ae4499
	    ;;
cvsdist 6ae4499
	yes|YES)
cvsdist 6ae4499
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --nfs-version 2"
cvsdist 6ae4499
	    ;;
cvsdist 6ae4499
	esac
cvsdist 6ae4499
cvsdist 6ae4499
	case $MOUNTD_NFS_V3 in
cvsdist 6ae4499
	auto|AUTO)
cvsdist 6ae4499
	    # Let's see if we support NFS version 3.
cvsdist 6ae4499
	    /usr/sbin/rpcinfo -u localhost nfs 3 &>/dev/null
cvsdist 6ae4499
	    if [ $? -ne 0 ]; then
cvsdist 6ae4499
		RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3"
cvsdist 6ae4499
	    fi
cvsdist 6ae4499
	    ;;
cvsdist 6ae4499
	no|NO)
cvsdist 6ae4499
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3"
cvsdist 6ae4499
	    ;;
cvsdist 6ae4499
	yes|YES)
cvsdist 6ae4499
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --nfs-version 3"
cvsdist 6ae4499
	    ;;
cvsdist 6ae4499
	esac
cvsdist 6ae4499
cvsdist 6ae4499
	echo -n $"Starting NFS mountd: "
cvsdist 6ae4499
	daemon rpc.mountd $RPCMOUNTDOPTS
cvsdist 6ae4499
	echo
cvsdist c905793
	touch /var/lock/subsys/nfs
cvsdist 6ae4499
	# reset input queue for rest of network services
cvsdist 6ae4499
	if [ "$TUNE_QUEUE" = "yes" ]; then
cvsdist 6ae4499
	    /sbin/sysctl -w net.core.rmem_default=$RMEM_DEFAULT >/dev/null 2>&1
cvsdist 6ae4499
	    /sbin/sysctl -w net.core.rmem_max=$RMEM_MAX >/dev/null 2>&1
cvsdist 6ae4499
	fi
cvsdist c905793
	;;
cvsdist c905793
  stop)
cvsdist c905793
	# Stop daemons.
cvsdist 6ae4499
	echo -n $"Shutting down NFS mountd: "
cvsdist c905793
	killproc rpc.mountd
cvsdist c905793
	echo
cvsdist 6ae4499
	echo -n $"Shutting down NFS daemon: "
cvsdist c905793
	killproc nfsd
cvsdist c905793
	echo
cvsdist 6ae4499
	if [ -n "$RQUOTAD" ]; then
cvsdist 6ae4499
		echo -n "Shutting down NFS quotas: "
cvsdist 6ae4499
		killproc rpc.rquotad
cvsdist 6ae4499
		echo
cvsdist 7a8b656
	fi
cvsdist 6ae4499
	# Do it the last so that clients can still access the server
cvsdist 6ae4499
	# when the server is running.
cvsdist 6ae4499
	action $"Shutting down NFS services: " /usr/sbin/exportfs -au
cvsdist c905793
	rm -f /var/lock/subsys/nfs
cvsdist c905793
	;;
cvsdist c905793
  status)
cvsdist c905793
	status rpc.mountd
cvsdist c905793
	status nfsd
cvsdist 6ae4499
	if [ -n "$RQUOTAD" ]; then
cvsdist 6ae4499
		status rpc.rquotad
cvsdist 7a8b656
	fi
cvsdist c905793
	;;
cvsdist c905793
  restart)
cvsdist 6ae4499
	$0 stop
cvsdist 6ae4499
	$0 start
cvsdist c905793
	;;
cvsdist c905793
  reload)
cvsdist c905793
	/usr/sbin/exportfs -r
cvsdist c905793
	touch /var/lock/subsys/nfs
cvsdist c905793
	;;
cvsdist c905793
  probe)
cvsdist c905793
	if [ ! -f /var/lock/subsys/nfs ] ; then
cvsdist 6ae4499
	  echo $"start"; exit 0
cvsdist c905793
	fi
cvsdist c905793
	/sbin/pidof rpc.mountd >/dev/null 2>&1; MOUNTD="$?"
cvsdist c905793
	/sbin/pidof nfsd >/dev/null 2>&1; NFSD="$?"
cvsdist c905793
	if [ $MOUNTD = 1 -o $NFSD = 1 ] ; then
cvsdist 6ae4499
	  echo $"restart"; exit 0
cvsdist c905793
	fi
cvsdist c905793
	if [ /etc/exports -nt /var/lock/subsys/nfs ] ; then
cvsdist 6ae4499
	  echo $"reload"; exit 0
cvsdist c905793
	fi
cvsdist c905793
	;;
cvsdist 6ae4499
  condrestart)
cvsdist 6ae4499
  	[ -f /var/lock/subsys/nfs ] && {
cvsdist 6ae4499
		$0 stop
cvsdist 6ae4499
		$0 start
cvsdist 6ae4499
	}
cvsdist 6ae4499
	;;
cvsdist c905793
  *)
cvsdist 6ae4499
	echo $"Usage: nfs {start|stop|status|restart|reload|condrestart}"
cvsdist c905793
	exit 1
cvsdist c905793
esac
cvsdist c905793
cvsdist c905793
exit 0