summaryrefslogtreecommitdiff
path: root/packages/nfs-utils/files/nfsserver
blob: 3536f0db12c6f520377f97df7b8a4729f25a7c07 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/sh
#
# Startup script for nfs-utils
#
# The nfsd kernel module must exist along with its dependencies
modprobe -n nfsd || exit 0
#
# The environment variable NFS_SERVERS may be set in /etc/default/nfsd
# Other control variables may be overridden here too
test -r /etc/default/nfsd && . /etc/default/nfsd
#
# Location of exectuables:
test -x "$NFS_MOUNTD" || NFS_MOUNTD=/usr/sbin/mountd
test -x "$NFS_NFSD" || NFS_NFSD=/usr/sbin/nfsd
#
# The user mode program must also exist (it just starts the kernel
# threads using the kernel module code).
test -x "$NFS_MOUNTD" || exit 0
test -x "$NFS_NFSD" || exit 0
#
# Default is 8 threads, value is settable between 1 and the truely
# ridiculous 99
test "$NFS_SERVERS" -gt 0 && "$NFS_SERVERS" -lt 100 || NFS_SERVERS=8
#
#----------------------------------------------------------------------
# Startup and shutdown functions.
#  Actual startup/shutdown is at the end of this file.
#mountd
start_mountd(){
	echo -n 'starting mountd: '
	start-stop-daemon --start --exec "$NFS_MOUNTD" -- "$@"
	echo done
}
stop_mountd(){
	echo -n 'stopping mountd: '
	start-stop-daemon --stop --quiet --exec "$NFS_MOUNTD"
	echo done
}
#
#nfsd
start_nfsd(){
	echo -n 'starting $1 nfsd kernel threads: '
	start-stop-daemon --start --exec "$NFS_NFSD" -- "$@"
	echo done
}
delay_nfsd(){
	for delay in 0 1 2 3 4 5 6 7 8 9 
	do
		if pidof nfsd >/dev/null
		then
			echo -n .
			sleep 1
		else
			return 0
		fi
	done
	return 1
}
stop_nfsd(){
	# WARNING: this kills any process with the executable
	# name 'nfsd'.
	echo -n 'stopping nfsd: '
	start-stop-daemon --stop --quiet --signal 1 --name nfsd
	if delay_nfsd || {
		echo failed
		echo ' using signal 9: '
		start-stop-daemon --stop --quiet --signal 9 --name nfsd
		delay_nfsd
	}
	then
		echo done
		# This will remove, recursively, dependencies
		echo -n 'removing nfsd kernel module: '
		if modprobe -r nfsd
		then
			echo done
		else
			echo failed
		fi
	else
		echo failed
	fi
}
#----------------------------------------------------------------------
#
# supported options:
#  start
#  stop
#  reload: reloads the exports file
#  restart: stops and starts mountd
#FIXME: need to create the /var/lib/nfs/... directories
case "$1" in
start)	start_nfsd "$NFS_SERVERS"
	start_mountd
	test -r /etc/exports && exportfs -a;;
stop)	exportfs -ua
	stop_mountd
	stop_nfsd;;
reload)	test -r /etc/exports && exportfs -r;;
restart)exportfs -ua
	stop_mountd
	# restart does not restart the kernel threads,
	# only the user mode processes
	start_mountd
	test -r /etc/exports && exportfs -a;;
esac