blob: 8cea6acddfbf5c5c38fd8bd2fcaf16d41f7a679d (
plain) (
blame)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
#!/bin/bash
PROGRAM=/bin/false
RUNLEVEL=3
NEEDS="+network +portmap"
. /etc/init.d/smgl_init
. /etc/sysconfig/nfs
if [[ ! -e /etc/exports ]]; then
$FAILURE
echo "Please create an /etc/exports file. Exiting without starting nfs..."
$NORMAL
exit 1
fi
if [[ -e /usr/sbin/rpc.idmapd ]]; then
HASNFS4=1
fi
# pseudo fs stuff
mount_nfsd()
{
if grep -q 'nfsd' /proc/filesystems; then
if ! grep -q 'nfsd' /etc/mtab; then
required_executable /bin/mount
echo "mounting nfsd"
mount -t nfsd nfsd /proc/fs/nfsd
evaluate_retval
fi
fi
}
umount_nfsd()
{
if grep -q 'nfsd' /etc/mtab; then
required_executable /bin/umount
echo "unmounting nfsd"
umount /proc/fs/nfsd
evaluate_retval
fi
}
mount_pipefs()
{
if grep -q 'rpc_pipefs' /proc/filesystems; then
if ! grep -q 'rpc_pipefs' /etc/mtab; then
required_executable /bin/mount
echo "mounting pipefs"
mount -t rpc_pipefs rpc_pipefs /var/lib/nfs/rpc_pipefs
evaluate_retval
fi
fi
}
umount_pipefs()
{
if grep -q 'rpc_pipefs' /etc/mtab; then
required_executable /bin/umount
echo "unmounting pipefs"
umount /var/lib/nfs/rpc_pipefs
evaluate_retval
fi
}
# for making sure these exist
mknfsdirs() {
local d
for d in /var/lib/nfs/{rpc_pipefs,v4recovery,v4root}; do
[[ ! -d "${d}" ]] && mkdir -p "${d}"
done
}
# may be outsourced
get_kernel_pids()
{
local rval=1
for pid in $(pidof $1)
do
if [[ -z $(</proc/$pid/cmdline) ]]; then
builtin echo $pid
rval=0
fi
done
return $rval
}
start()
{
local bins
echo "Starting NFS services (client & server)"
bins="statd nfsd mountd"
mount_nfsd
if [[ ! -z $HASNFS4 ]]; then
mknfsdirs
mount_pipefs
bins="${bins} idmapd"
fi
for b in $bins; do
required_executable /usr/sbin/rpc.$b
done
# nfs-howto says: these daemons in this order
# userspace does not bother about lockd since linux 2.2.18
for d in ${bins} rquotad; do
if [[ -x /usr/sbin/rpc.$d ]]; then
local opts=
if [[ $d == 'mountd' ]]; then
opts="$MOUNTDOPTS"
if [[ ! -z "$MOUNTD_PORT" ]]; then
opts="$opts -p $MOUNTD_PORT"
fi
elif [[ $d == 'nfsd' ]]; then
opts="$NUMSERVERS"
elif [[ $d == 'statd' && ! -z $STATD_PORT ]]; then
opts="-p $STATD_PORT"
fi
echo -n $d
loadproc /usr/sbin/rpc.$d $opts
fi
done
required_executable /usr/sbin/exportfs
echo -n "exportfs"
/usr/sbin/exportfs -r
evaluate_retval
}
stop()
{
local bins
echo "Stopping NFS services (client & server)"
echo -n "unexporting filesystems"
/usr/sbin/exportfs -au
evaluate_retval
bins="statd nfsd mountd"
umount_nfsd
if [[ ! -z $HASNFS4 ]]; then
umount_pipefs
bins="${bins} idmapd"
fi
for b in $bins; do
required_executable /usr/sbin/rpc.$b
done
# all in one loop to simplify code, reversed order
# atm. only nfsd is really in-kernel (and lockd self-managed)
for d in ${bins} rquotad; do
if [[ -x /usr/sbin/rpc.$d ]]; then
local kpid=$(get_kernel_pids $d)
if [[ -z $kpid ]]; then
echo -n "killing $d"
killproc /usr/sbin/rpc.$d
else
if [[ $d == 'nfsd' ]]; then
echo "Removing kernel nfsd"
/usr/sbin/rpc.nfsd 0
else
echo "not killing kernel $d (PID=${kpid})"
fi
fi
fi
done
}
status()
{
for d in mountd nfsd statd rquotad
do
local kpid=$(get_kernel_pids $d)
[[ -n $kpid ]] && echo "kernel $d there with PIDs $kpid" ||
statusproc /usr/sbin/rpc.$d
done
echo -n "kernel lockd "
kpid=$(get_kernel_pids lockd)
[[ -n $kpid ]] && echo "is active (PID $kpid)" || echo "is not active (but hopefully ready)"
}
|