#!/bin/sh
#PKG nfs-utils-server
#INIT 70
. /etc/rc.conf

case $1 in
autostop) ;;
autostart)
	test x"${rpcbind:-NO}" = x"NO" && exit 0
	test x"${nfsd:-NO}" = x"NO" && exit 0
	test x"$nfsd" = x"DAEMON" && test -x /bin/mksh && exec mksh -T- $0 start
	exec sh $0 start
	;;
start)
	mkdir -p /var/lib/nfs/v4recovery
	touch /var/lib/nfs/rmtab
	touch /var/lib/nfs/etab
	touch /var/lib/nfs/xtab
	touch /var/lib/nfs/sm
	mount -t nfsd nfsd /proc/fs/nfsd
	chown nfs:nfs /var/lib/nfs/sm
	/usr/sbin/nfsd 4
	/usr/sbin/mountd
	exportfs -a
	if [ ${nfs_server_version} -eq 4 ];then
		mkdir -p /var/lib/nfs/rpc_pipefs
		mount -t rpc_pipefs rpc_pipefs /var/lib/nfs/rpc_pipefs
		/usr/sbin/idmapd
		/usr/sbin/svcgssd
	fi
	;;
stop)
	kill $(pgrep -f /usr/sbin/mountd)
	umount /proc/fs/nfsd
	if [ ${nfs_server_version} -eq 4 ];then
		kill $(pgrep -f /usr/sbin/idmapd)
		kill $(pgrep -f /usr/sbin/svcgssd)
		umount /var/lib/nfs/rpc_pipefs
	fi
	;;
restart)
	sh $0 stop
	sh $0 start
	;;
*)
	echo "Usage: $0 {start | stop | restart}"
	exit 1
	;;
esac
exit $?
