#!/bin/sh
# 
#



case "$1" in
start)

	if [ -z "`lsmod | grep "^nfsd "`" 2> /dev/null ]; then
    		modprobe nfsd
  	fi

	if grep nfsd /proc/filesystems 2> /dev/null; then
      		if grep nfsd /proc/mounts 2> /dev/null; then
        		mount -t nfsd nfsd /proc/fs/nfs 2> /dev/null
      		fi
    	fi
	
	if [ -x /usr/local/sbin/rpc.mountd ] && [ -x /usr/local/sbin/rpc.nfsd ]; then
		start-stop-daemon --start --exec /usr/local/sbin/portmap
		start-stop-daemon --start --exec /usr/local/sbin/rpc.statd
		start-stop-daemon --start --exec /usr/local/sbin/rpc.mountd 
		[ $(pidof nfsd) ] || /usr/local/sbin/rpc.nfsd 8 2> /dev/null
		/usr/local/sbin/sm-notify -q 2> /dev/null
		/usr/local/sbin/exportfs -a 2> /dev/null
		echo "nfs-server utilities are started."
	else
		echo "You do not have nfs-utils installed. Install nfs-utils."
	fi

	
;;

stop)
	killall -9 nfsd
	start-stop-daemon --stop --exec /usr/local/sbin/rpc.mountd
	rmmod nfsd
	rmmod exportfs
;;

restart)
  	$0 stop
  	$0 start
;;

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

