#!/bin/sh

# Make sure the statd service is running.
sv check statd >/dev/null || exit 1

# Get the nfs service parameters from the LFS standard file
# this sets some envars.
if [ -e /etc/conf.d/nfs-server.conf ]; then
	. /etc/conf.d/nfs-server.conf
fi

modprobe sunrpc || exit 1
modprobe nfs || exit 1
modprobe nfsd || exit 1
if ! mountpoint -q /var/lib/nfs/rpc_pipefs; then
	mount -t rpc_pipefs rpc_pipefs /var/lib/nfs/rpc_pipefs -o defaults || exit 1
fi

# Uncomment this and add the two daemons if you need kerberos support.
# sv check idmapd gssd >/dev/null || exit 1

if ! mountpoint -q /proc/fs/nfsd; then
	mount -t nfsd nfsd /proc/fs/nfsd || exit 1
fi
exportfs -ra > /dev/null || exit 1
rpc.nfsd -- ${PROCESSES:=4} || exit 1

exec rpc.mountd --foreground
