#!/bin/sh
#
# nfs4          This shell script takes care of starting and stopping
#               the NFS4 services.
#
# chkconfig: - 60 20
# description: NFS is a popular protocol for file sharing across TCP/IP \
#              networks. This service provides NFS server functionality, \
#              which is configured via the /etc/exports file.
# probe: true

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

# Source networking configuration.
if [ ! -f /etc/sysconfig/network ]; then
    exit 0
fi

. /etc/sysconfig/network

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

[ -x /usr/sbin/exportfs4 ] || exit 0
[ -x /usr/sbin/gssd ] || exit 0
[ -s /etc/exports ] || exit 0

# See how we were called.
case "$1" in
  start)
	# Loads the modules.  XXX have no idea if this is correct.
	insmod sunrpc
	insmod cryptoapi
	insmod auth_rpcgss
	insmod nfs4
	insmod nfsd4
        /usr/sbin/gssd -n & # need to figure out how to not have this output anything
	# Start gssd
	#action "Starting GSSD: " /usr/sbin/gssd
        # Start daemons.
        action "Starting NFS services: " /usr/sbin/exportfs4
        #echo
	echo
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down NFS daemon: "
        killproc nfsd4
        killproc nfs4_laundromat
        echo
        echo -n "Shutting down gssd: "
        killproc gssd
        echo
	rmmod nfsd4
	rmmod nfs4
	rmmod auth_rpcgss
	rmmod cryptoapi
	rmmod sunrpc
	;;
  status)
        status nfsd4
        status gssd
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  reload)
	# XXX not supported yet
        /usr/sbin/exportfs -r
        touch /var/lock/subsys/nfs
        ;;
  probe)
	# XXX I have no idea on this
        if [ ! -f /var/lock/subsys/nfs ] ; then
          echo start; exit 0
        fi
        /sbin/pidof rpc.mountd >/dev/null 2>&1; MOUNTD="$?"
        /sbin/pidof nfsd >/dev/null 2>&1; NFSD="$?"
        if [ $MOUNTD = 1 -o $NFSD = 1 ] ; then
          echo restart; exit 0
        fi
        if [ /etc/exports -nt /var/lock/subsys/nfs ] ; then
          echo reload; exit 0
        fi
        ;;
  *)
        echo "Usage: nfs {start|stop|status|restart|reload}"
        exit 1
esac

exit 0




