summaryrefslogtreecommitdiffstats
path: root/net/nfs-kernel-server/files/nfsd.v4.init
blob: af2c0f57fbf2c7f52ba1a80151b1f65b99b3d11c (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/sh /etc/rc.common
# NFSV4 init script for OpenWrt
# Copyright (C) 2025 OpenWrt.org

START=99
STOP=60
USE_PROCD=1

NFS_D=/var/lib/nfs
RPC_PIPEFS_D=/var/lib/nfs/rpc_pipefs

start_service() {
	logger -t "nfsd" -p notice "Starting the NFSV4 daemon"
	mkdir -p "$RPC_PIPEFS_D" "$NFS_D"
	chown nfs:nfs "$NFS_D"

	grep -q /proc/fs/nfsd /proc/mounts || mount -t nfsd nfsd /proc/fs/nfsd
	grep -q "$RPC_PIPEFS_D" /proc/mounts || mount -t rpc_pipefs sunrpc "$RPC_PIPEFS_D"

	procd_open_instance
	procd_set_param command /usr/sbin/nfsv4.exportd -f -L
	procd_set_param respawn
	procd_close_instance

	procd_open_instance
	procd_set_param command /usr/sbin/rpc.idmapd -f
	procd_set_param respawn
	procd_close_instance

	procd_open_instance
	procd_set_param command /usr/sbin/nfsdcld
	procd_close_instance

	/usr/sbin/exportfs -r

	procd_open_instance
	procd_set_param command /usr/sbin/rpc.nfsd -N 3 -V 4.0
	procd_close_instance
}

stop_service() {
	/usr/sbin/rpc.nfsd 0
	/usr/sbin/exportfs -au
	/usr/sbin/exportfs -f
	/usr/bin/killall nfsdcld 2>/dev/null
	(
		sleep 1s
		grep -q "$RPC_PIPEFS_D" /proc/mounts && umount "$RPC_PIPEFS_D"
		grep -q /proc/fs/nfsd /proc/mounts && umount /proc/fs/nfsd
		) &
}

status_service() {
	local n_running=0
	local n_total=3
	pgrep -x nfsv4.exportd > /dev/null && n_running=$((n_running + 1))
	pgrep -x rpc.idmapd   > /dev/null && n_running=$((n_running + 1))
	pgrep -x nfsdcld      > /dev/null && n_running=$((n_running + 1))
	if [ "$n_running" -eq "$n_total" ]; then
		echo "running"
		return 0
	elif [ "$n_running" -gt 0 ]; then
		echo "running ($n_running/$n_total)"
		return 0
	else
		echo "not running"
		return 1
	fi
}

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