#!/bin/sh
# Begin $rc_base/init.d/nfs-server

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org

#$LastChangedBy: dj $
#$Date: 2004-10-11 23:10:06 -0600 (Mon, 11 Oct 2004) $

. /etc/sysconfig/rc
. $rc_functions
. /etc/sysconfig/nfs-server

case "$1" in
	start)
		echo "Starting NFS mountd..."
		loadproc /usr/sbin/rpc.mountd

		echo "Starting NFS nfsd..."
		loadproc /usr/sbin/rpc.nfsd -p $PORT $PROCESSES

		echo "Starting NFS statd..."
		loadproc /usr/sbin/rpc.statd

		if [ "$QUOTAS" == "yes" ]; then
			echo "Starting NFS rquotad..."
			loadproc /usr/sbin/rpc.rquotad
		fi
		
		# NFSD support only in 2.6 kernel
		/bin/uname -r | /bin/grep "2.6" 2>&1 > /dev/null
		if [ $? == 0 ]; then
			echo "Mounting nfsd virtual filesystem..."
			/bin/mount -t nfsd none /proc/fs/nfsd 2>&1 > /dev/null
			evaluate_retval
		fi

		# Make ceratin that the list is refreshed on 
		# a restart.
		echo "Exporting NFS Filesystems..."
		/usr/sbin/exportfs -ra 2>&1 > /dev/null
		evaluate_retval
		;;

	stop)
		echo "Stopping NFS statd..."
		killproc /usr/sbin/rpc.statd

		echo "Stopping NFS nfsd..."
		# nfsd needs HUP....
		TEMPSTOPSIG="$STOPSIG"
		STOPSIG="HUP"
		## Special case for nfsd with no full path
		killproc nfsd
		# return STOPSIG to it's orginal value...
		STOPSIG="$TEMPSTOPSIG"

		echo "Stopping NFS mountd..."
		killproc /usr/sbin/rpc.mountd

		if [ "$QUOTAS" == "yes" ]; then
			echo "Stopping NFS rquotad..."
			killproc /usr/sbin/rpc.rquotad
		fi

		echo "Refreshing NFS Exported Filesystems..."
		/usr/sbin/exportfs -au 2>&1 > /dev/null
		evaluate_retval

		# NFSD support only in 2.6 kernel
                /bin/uname -r | /bin/grep "2.6" 2>&1 > /dev/null
                if [ $? == 0 ]; then
			echo "Unmounting NFS Virtual Filesystem..."
			/bin/umount /proc/fs/nfsd 2>&1 > /dev/null
			evaluate_retval
		fi
		;;

	reload)
		echo "Reloading NFS Server..."
		/usr/sbin/exportfs -ra
		evaluate_retval
		;;

	restart)
		$0 stop
		sleep 1
		$0 start
		;;

	status)
		statusproc /usr/sbin/rpc.mountd
		## Special case for nfsd with no full path
		statusproc nfsd
		statusproc /usr/sbin/rpc.statd
		if [ "$QUOTA" == "yes" ]; then
			statusproc rpc.rquotad
		fi
		;;

	*)
		echo "Usage: $0 {start|stop|reload|restart|status}"
		exit 1
		;;
esac

# End $rc_base/init.d/nfs-server
