summaryrefslogtreecommitdiffstats
path: root/net/nfs-kernel-server/files/nfsd.v3.init
blob: 1527a85fb1693881c6d5cc8bac3f0a6390ceda3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh /etc/rc.common
# NFSV3 init script for OpenWrt
# Copyright (C) 2025 OpenWrt.org

START=99
STOP=60
USE_PROCD=1

NFS_D=/var/lib/nfs
LOCK_D=/var/lib/nfs/sm

start_service() {
	logger -t "nfsd" -p notice "Starting the NFSv3 daemon"
	grep -q /proc/fs/nfsd /proc/mounts || \
		mount -t nfsd nfsd /proc/fs/nfsd
	mkdir -p "$NFS_D" "$LOCK_D"
	chown nfs:nfs "$NFS_D"
	touch "$NFS_D/rmtab"

	sysctl -w fs.nfs.nlm_tcpport=32777 fs.nfs.nlm_udpport=32777 > /dev/null

	procd_open_instance "statd"
	procd_set_param command /usr/sbin/rpc.statd -p 32778 -o 32779 -F
	procd_set_param respawn
	procd_close_instance

	/usr/sbin/exportfs -r
	/usr/sbin/nfsdctl autostart || /usr/sbin/rpc.nfsd --grace-time 10 \
		--no-nfs-version 4 --no-nfs-version 4.1 --no-nfs-version 4.2

	procd_open_instance "mountd"
	procd_set_param command /usr/sbin/rpc.mountd -p 32780 -F
	procd_set_param respawn
	procd_close_instance
}

stop_service() {
	/usr/sbin/nfsdctl threads 0 || /usr/sbin/rpc.nfsd 0 2>/dev/null
	/usr/sbin/exportfs -au
	/usr/sbin/exportfs -f
	grep -q /proc/fs/nfsd /proc/mounts && umount /proc/fs/nfsd
}

reload_service() {
	/usr/sbin/exportfs -r
}

service_triggers() {
	local export_dir
	for export_dir in $(awk 'NF && !/^#/ {print $1}' /etc/exports); do
		procd_add_reload_mount_trigger "$export_dir"
	done
}