1#!/bin/sh
2#
3#
4
5# PROVIDE: nfsd
6# REQUIRE: mountcritremote mountd hostname gssd nfsuserd
7# KEYWORD: nojailvnet shutdown
8
9. /etc/rc.subr
10
11name="nfsd"
12desc="Remote NFS server"
13rcvar="nfs_server_enable"
14command="/usr/sbin/${name}"
15nfs_server_vhost=""
16
17: ${nfsd_svcj_options:="net_basic nfsd"}
18
19load_rc_config $name
20# precmd is not compatible with svcj
21nfsd_svcj="NO"
22start_precmd="nfsd_precmd"
23sig_stop="USR1"
24
25nfsd_precmd()
26{
27	local	_vhost
28	rc_flags="${nfs_server_flags}"
29
30	# Load the modules now, so that the vfs.nfsd sysctl
31	# oids are available.
32	load_kld nfsd || return 1
33
34	if [ -n "${nfs_server_maxio}" ] && ! check_jail jailed; then
35		if ! sysctl vfs.nfsd.srvmaxio=${nfs_server_maxio} >/dev/null; then
36			warn "Failed to set server max I/O"
37		fi
38	fi
39
40	if checkyesno nfs_reserved_port_only; then
41		echo 'NFS on reserved port only=YES'
42		sysctl vfs.nfsd.nfs_privport=1 > /dev/null
43	else
44		sysctl vfs.nfsd.nfs_privport=0 > /dev/null
45	fi
46
47	if checkyesno nfs_server_managegids; then
48		force_depend nfsuserd || err 1 "Cannot run nfsuserd"
49	fi
50
51	if checkyesno nfsv4_server_enable; then
52		sysctl vfs.nfsd.server_max_nfsvers=4 > /dev/null
53	elif ! checkyesno nfsv4_server_only; then
54		echo 'NFSv4 is disabled'
55		sysctl vfs.nfsd.server_max_nfsvers=3 > /dev/null
56	fi
57
58	if ! checkyesno nfsv4_server_only; then
59		force_depend rpcbind || return 1
60	fi
61
62	force_depend mountd || return 1
63	if [ -n "${nfs_server_vhost}" ]; then
64		command_args="-V \"${nfs_server_vhost}\""
65	fi
66}
67
68run_rc_command "$1"
69