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
#
5b1bacb
# chkconfig: - 30 60
0ce3b8d
# description: NFS is a popular protocol for file sharing across networks.
0ce3b8d
#              This service provides NFS server functionality, which is \
0ce3b8d
#              configured via the /etc/exports file.
cvsdist c905793
# probe: true
cvsdist e53021f
# config: /etc/sysconfig/nfs
cvsdist c905793
0ce3b8d
### BEGIN INIT INFO
0ce3b8d
# Provides: nfs
10702da
# Required-Start: $local_fs $network $syslog $rpcbind
10702da
# Required-Stop: $local_fs $network $syslog $rpcbind
0ce3b8d
# Default-Stop: 0 1 6
0ce3b8d
# Short-Description: Start up the NFS server sevice
0ce3b8d
# Description: NFS is a popular protocol for file sharing across networks \
0ce3b8d
#              This service provides NFS server functionality, \
0ce3b8d
#              which is configured via the /etc/exports file.
0ce3b8d
### END INIT INFO
0ce3b8d
0ce3b8d
cvsdist c905793
# Source function library.
cvsdist c905793
. /etc/rc.d/init.d/functions
cvsdist c905793
cvsdist c905793
# Source networking configuration.
adb2afe
[ -f /etc/sysconfig/network ] &&  . /etc/sysconfig/network
cvsdist c905793
0fcb349
# Check for and source configuration file otherwise set defaults
0fcb349
[ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs
0fcb349
0fcb349
# Remote quota server
0fcb349
[ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`
0fcb349
adb2afe
RETVAL=0
0fb3f74
uid=`id | cut -d\( -f1 | cut -d= -f2`
cvsdist c905793
adb2afe
# See how we were called.
adb2afe
case "$1" in
adb2afe
  start)
cvsdist c905793
adb2afe
	# Check that networking is up.
adb2afe
	[ "${NETWORKING}" != "yes" ] && exit 6
cvsdist 1c22dc7
adb2afe
	[ -x /usr/sbin/rpc.nfsd ] || exit 5
adb2afe
	[ -x /usr/sbin/rpc.mountd ] || exit 5
adb2afe
	[ -x /usr/sbin/exportfs ] || exit 5
cvsdist c905793
adb2afe
	# Make sure the rpc.mountd is not already running.
adb2afe
	if status rpc.mountd > /dev/null ; then
adb2afe
		exit 0
adb2afe
	fi
cvsdist e53021f
0fb3f74
	# Only root can start the service
0fb3f74
	[ $uid -ne 0 ] && exit 4
0fb3f74
adb2afe
	# Don't fail if /etc/exports doesn't exist; create a bare-bones 
adb2afe
	# version and continue.
adb2afe
	[ -r /etc/exports ] || \
adb2afe
    	{ touch /etc/exports && chmod u+rw,g+r,o+r /etc/exports ; } || \
adb2afe
    	{ echo "/etc/exports does not exist" ; exit 0 ; }
cvsdist e53021f
adb2afe
	[ -z "$MOUNTD_NFS_V2" ] && MOUNTD_NFS_V2=default
adb2afe
	[ -z "$MOUNTD_NFS_V3" ] && MOUNTD_NFS_V3=default
cvsdist e53021f
adb2afe
	# Number of servers to be started by default
adb2afe
	[ -z "$RPCNFSDCOUNT" ] && RPCNFSDCOUNT=8
adb2afe
cvsdist c905793
	# Start daemons.
3f418c2
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd start
3f418c2
9a95968
	# Set the ports lockd should listen on
9a95968
	if [ -n "$LOCKD_TCPPORT" -o -n "$LOCKD_UDPPORT" ]; then 
9a95968
		[ -x /sbin/modprobe ] && /sbin/modprobe lockd $LOCKDARG
9a95968
		[ -n "$LOCKD_TCPPORT" ] && \
9a95968
			/sbin/sysctl -w fs.nfs.nlm_tcpport=$LOCKD_TCPPORT >/dev/null 2>&1
9a95968
		[ -n "$LOCKD_UDPPORT" ] && \
9a95968
			/sbin/sysctl -w fs.nfs.nlm_udpport=$LOCKD_UDPPORT >/dev/null 2>&1
9a95968
	fi
9a95968
60a7929
	# Load the nfsd module so /proc/fs/nfsd will exist
f517c36
	[ "$NFSD_MODULE" != "noload" -a -x /sbin/modprobe ] && {
f517c36
		/sbin/modprobe nfsd
f517c36
		[ -n "$RDMA_PORT" ] && /sbin/modprobe svcrdma
60a7929
	}
423f02d
423f02d
	# Set v4 grace period if requested  
423f02d
	[ -n "$NFSD_V4_GRACE" ] && {
423f02d
		echo "$NFSD_V4_GRACE" > /proc/fs/nfsd/nfsv4gracetime
423f02d
	}
cvsdist 4bc0e7f
	action $"Starting NFS services: " /usr/sbin/exportfs -r
cvsdist 9d8f355
cvsdist e53021f
	if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
cvsdist 9d8f355
	    echo -n $"Starting NFS quotas: "
44d986f
		[ -n "$RQUOTAD_PORT" ] \
44d986f
			&& RPCRQUOTADOPTS="$RPCRQUOTADOPTS -p $RQUOTAD_PORT"
44d986f
	    daemon rpc.rquotad $RPCRQUOTADOPTS
f4efa10
		RETVAL=$?
cvsdist 7a8b656
	    echo
cvsdist 7a8b656
	fi
bf258f5
cvsdist 0f7bdca
	echo -n $"Starting NFS daemon: "
50d268c
	daemon rpc.nfsd $RPCNFSDARGS $RPCNFSDCOUNT
f4efa10
	RETVAL=$?
cvsdist 0f7bdca
	echo
f4efa10
	[ $RETVAL -ne 0 ] && exit $RETVAL
cvsdist e53021f
f517c36
	[ -n "$RDMA_PORT" ] && echo "rdma $RDMA_PORT" > /proc/fs/nfsd/portlist
f517c36
cvsdist e53021f
	[ -n "$MOUNTD_PORT" ] \
cvsdist e53021f
	&& RPCMOUNTDOPTS="$RPCMOUNTDOPTS -p $MOUNTD_PORT"
cvsdist e53021f
cvsdist e53021f
	case $MOUNTD_NFS_V2 in
cvsdist e53021f
	no|NO)
cvsdist 70faca5
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 2" ;;
cvsdist e53021f
	esac
cvsdist e53021f
cvsdist e53021f
	case $MOUNTD_NFS_V3 in
cvsdist e53021f
	no|NO)
cvsdist 70faca5
	    RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3" ;;
cvsdist e53021f
	esac
cvsdist e53021f
cvsdist e53021f
	echo -n $"Starting NFS mountd: "
cvsdist e53021f
	daemon rpc.mountd $RPCMOUNTDOPTS
f4efa10
	RETVAL=$?
cvsdist e53021f
	echo
0fb3f74
	touch /var/lock/subsys/rpc.mountd
5f9e463
	touch /var/lock/subsys/nfs
cvsdist 4bc0e7f
3f418c2
	# Let rpc.idmapd know that rpc.mountd just started
cvsdist 4bc0e7f
	[ -x /usr/sbin/rpc.idmapd ] && /sbin/service rpcidmapd condstart
cvsdist 4bc0e7f
cvsdist c905793
	;;
cvsdist c905793
  stop)
0fb3f74
	# Only root can stop the service
0fb3f74
	[ $uid -ne 0 ] && exit 4
0fb3f74
cvsdist c905793
	# Stop daemons.
cvsdist e53021f
	echo -n $"Shutting down NFS mountd: "
cvsdist c905793
	killproc rpc.mountd
0fb3f74
	RETVAL=$?
cvsdist c905793
	echo
cvsdist e53021f
	echo -n $"Shutting down NFS daemon: "
46b1090
	killproc nfsd -2
0fb3f74
	rval=$?
0fb3f74
	[ $RETVAL -eq 0 ] && RETVAL=$rval
cvsdist c905793
	echo
cc01757
	if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
cvsdist 9d8f355
		echo -n $"Shutting down NFS quotas: "
cvsdist e53021f
		killproc rpc.rquotad
0fb3f74
		rval=$?
0fb3f74
		[ $RETVAL -eq 0 ] && RETVAL=$rval
cvsdist e53021f
		echo
cvsdist 7a8b656
	fi
cvsdist 9d8f355
	# Reset the lockd ports if they were set
cvsdist 4bc0e7f
	if [ -n "$LOCKD_TCPPORT" ]; then
cvsdist 9d8f355
	    /sbin/sysctl -w fs.nfs.nlm_tcpport=0 >/dev/null 2>&1
cvsdist 9d8f355
	fi
cvsdist 4bc0e7f
	if [ -n "$LOCKD_UDPPORT" ]; then
cvsdist 9d8f355
	    /sbin/sysctl -w fs.nfs.nlm_udpport=0 >/dev/null 2>&1
cvsdist 9d8f355
	fi
cvsdist e53021f
	# Do it the last so that clients can still access the server
cvsdist e53021f
	# when the server is running.
f4efa10
	cnt=`/usr/sbin/exportfs -v | /usr/bin/wc -l`	
f4efa10
	if [ $cnt -gt 0 ]; then 
f4efa10
		action $"Shutting down NFS services: " /usr/sbin/exportfs -au
0fb3f74
		rval=$?
0fb3f74
		[ $RETVAL -eq 0 ] && RETVAL=$rval
f4efa10
	fi
cafae3a
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd stop
5f9e463
	rm -f /var/lock/subsys/nfs
0fb3f74
	rm -f /var/lock/subsys/rpc.mountd
cvsdist c905793
	;;
cvsdist c905793
  status)
3f418c2
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd status
cvsdist c905793
	status rpc.mountd
0fb3f74
	RETVAL=$?
cvsdist c905793
	status nfsd
0fb3f74
	rval=$?
0fb3f74
	[ $RETVAL -eq 0 ] && RETVAL=$rval
cc01757
	if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
cvsdist e53021f
		status rpc.rquotad
0fb3f74
		rval=$?
0fb3f74
		[ $RETVAL -eq 0 ] && RETVAL=$rval
cvsdist 7a8b656
	fi
cvsdist c905793
	;;
cvsdist c905793
  restart)
cvsdist e53021f
	$0 stop
cvsdist e53021f
	$0 start
cvsdist c905793
	;;
0fb3f74
  reload | force-reload)
cvsdist c905793
	/usr/sbin/exportfs -r
5f9e463
	touch /var/lock/subsys/nfs
cvsdist c905793
	;;
cvsdist c905793
  probe)
5f9e463
	if [ ! -f /var/lock/subsys/nfs ] ; then
cvsdist e53021f
	  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 e53021f
	  echo $"restart"; exit 0
cvsdist c905793
	fi
5f9e463
	if [ /etc/exports -nt /var/lock/subsys/nfs ] ; then
cvsdist e53021f
	  echo $"reload"; exit 0
cvsdist c905793
	fi
cvsdist c905793
	;;
0fb3f74
  condrestart | try-restart)
3f418c2
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd condrestart
5f9e463
  	[ -f /var/lock/subsys/nfs ] && {
cvsdist 9d8f355
		$0 stop
cvsdist 9d8f355
		$0 start
1ae9fb3
		RETVAL=$?
1ae9fb3
	}
1ae9fb3
	;;
1ae9fb3
  condstop)
1ae9fb3
	[ -x /usr/sbin/rpc.svcgssd ] && /sbin/service rpcsvcgssd condstop
5f9e463
  	[ -f /var/lock/subsys/nfs ] && {
1ae9fb3
		$0 stop
1ae9fb3
		RETVAL=$?
cvsdist 9d8f355
	}
cvsdist 9d8f355
	;;
cvsdist c905793
  *)
0fb3f74
	echo $"Usage: nfs {start|stop|status|restart|reload|force-reload|condrestart|try-restart|condstop}"
0fb3f74
	RETVAL=2
cafae3a
	;;
cvsdist c905793
esac
cvsdist c905793
cafae3a
exit $RETVAL