#!/bin/sh

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

# Uncomment and add daemons for kerberos support.
#sv check rpcidmapd >/dev/null || exit 1
#sv check rpcsvgssd >/dev/null || exit 1

# Uncomment and add daemon for pNFS support.
#sv check rpcblkmapd >/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

# Check/mount rpc_pipefs (loads sunrpc kernel module)
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

# Check/mount nfsd (loads nfsd kernel module)
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

sm-notify

exec rpc.mountd --foreground
