/[gentoo-alt]/trunk/sys-apps/freebsd-usbin/files/nfs.initd
Gentoo

Contents of /trunk/sys-apps/freebsd-usbin/files/nfs.initd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 405 - (show annotations) (download)
Thu May 26 20:14:11 2005 UTC (9 years, 1 month ago) by flameeyes
File size: 5877 byte(s)
New revision: this time installs nfs and rpcbind init.d files, so you can use nfs with locking support.

1 #!/sbin/runscript
2 # Copyright 1999-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header$
5
6 #---------------------------------------------------------------------------
7 # This script starts/stops the following
8 # rpc.statd if necessary (also checked by init.d/nfsmount)
9 # rpc.rquotad if exists (from quota package)
10 # rpc.nfsd
11 # rpc.mountd
12 #---------------------------------------------------------------------------
13
14 # NB: Config is in /etc/conf.d/nfs
15
16 opts="reload"
17
18 # This variable is used for controlling whether or not to run exportfs -ua;
19 # see stop() for more information
20 restarting=no
21
22 # The binary locations
23 exportfs=/usr/sbin/exportfs
24 statd=/usr/sbin/rpc.statd
25 idmapd=/usr/sbin/rpc.idmapd
26 rquotad=/usr/sbin/rpc.rquotad
27 nfsd=/usr/sbin/rpc.nfsd
28 mountd=/usr/sbin/rpc.mountd
29
30 depend() {
31 use ypbind net
32 need rpcbind
33 after quota
34 }
35
36 start_idmapd() {
37 [[ ! -x ${idmapd} ]] && return 0
38
39 if grep -q rpc_pipefs /proc/filesystems ; then
40 if ! grep -q "rpc_pipefs /var/lib/nfs/rpc_pipefs" /proc/mounts ; then
41 [[ ! -d /var/lib/nfs/rpc_pipefs ]] && mkdir -p /var/lib/nfs/rpc_pipefs
42 ebegin "Mounting RPC pipefs"
43 mount -t rpc_pipefs rpc_pipefs /var/lib/nfs/rpc_pipefs
44 eend $?
45 fi
46 fi
47
48 ebegin "Starting idmapd"
49 ${idmapd} ${RPCIDMAPDOPTS}
50 eend $?
51 }
52
53 stop_idmapd() {
54 [[ ! -x ${idmapd} ]] && return 0
55
56 ebegin "Stopping idmapd"
57 start-stop-daemon --stop --quiet --exec ${idmapd}
58 ret=$?
59 eend ${ret}
60
61 if [[ $restarting == "no" ]] ; then
62 if grep -q "rpc_pipefs /var/lib/nfs/rpc_pipefs" /proc/mounts ; then
63 ebegin "Unmounting RPC pipefs"
64 umount /var/lib/nfs/rpc_pipefs
65 eend $?
66 fi
67 fi
68
69 return ${ret}
70 }
71
72 start_statd() {
73 # Don't start rpc.statd if already started by init.d/nfsmount
74 killall -0 rpc.statd &>/dev/null && return 0
75 ebegin "Starting NFS statd"
76 start-stop-daemon --start --quiet --exec \
77 $statd -- $RPCSTATDOPTS 1>&2
78 eend $? "Error starting NFS statd"
79 }
80
81 stop_statd() {
82 # Don't stop rpc.statd if it's in use by init.d/nfsmount.
83 mount -t nfs | grep -q . && return 0
84 # Make sure it's actually running
85 killall -0 rpc.statd &>/dev/null || return 0
86 # Okay, all tests passed, stop rpc.statd
87 ebegin "Stopping NFS statd"
88 start-stop-daemon --stop --quiet --exec $statd 1>&2
89 eend $? "Error stopping NFS statd"
90 }
91
92 waitfor_exportfs() {
93 local pid=$1
94 ( sleep ${EXPORTFSTIMEOUT:-30}; kill -9 $pid &>/dev/null ) &
95 wait $1
96 }
97
98 start() {
99 # Make sure nfs support is loaded in the kernel #64709
100 if [ -e /proc/modules ] ; then
101 modprobe nfsd &> /dev/null
102 fi
103
104 # This is the new "kernel 2.6 way" to handle the exports file
105 if grep -q nfsd /proc/filesystems &>/dev/null; then
106 if ! grep -q "nfsd /proc/fs/nfs" /proc/mounts &>/dev/null; then
107 ebegin "Mounting nfsd filesystem in /proc"
108 mount -t nfsd nfsd /proc/fs/nfs
109 eend $? "Error mounting nfsd filesystem in /proc"
110 fi
111 fi
112 # now that nfsd is mounted inside /proc, we can safely start mountd later
113
114 start_idmapd
115 start_statd
116
117 # Exportfs likes to hang if networking isn't working.
118 # If that's the case, then try to kill it so the
119 # bootup process can continue.
120 if grep -q '^/' /etc/exports &>/dev/null; then
121 ebegin "Exporting NFS directories"
122 $exportfs -r 1>&2 &
123 waitfor_exportfs $!
124 eend $? "Error exporting NFS directories"
125 fi
126
127 if [ -x $rquotad ]; then
128 ebegin "Starting NFS rquotad"
129 start-stop-daemon --start --quiet --exec \
130 $rquotad -- $RPCRQUOTADOPTS 1>&2
131 eend $? "Error starting NFS rquotad"
132 fi
133
134 ebegin "Starting NFS daemon"
135 start-stop-daemon --start --quiet --exec \
136 $nfsd -- $RPCNFSDCOUNT 1>&2
137 eend $? "Error starting NFS daemon"
138
139 # Start mountd
140 ebegin "Starting NFS mountd"
141 start-stop-daemon --start --quiet --exec \
142 $mountd -- $RPCMOUNTDOPTS 1>&2
143 eend $? "Error starting NFS mountd"
144 }
145
146 stop() {
147 # Don't check NFSSERVER variable since it might have changed,
148 # instead use --oknodo to smooth things over
149 ebegin "Stopping NFS mountd"
150 start-stop-daemon --stop --quiet --oknodo \
151 --exec $mountd 1>&2
152 eend $? "Error stopping NFS mountd"
153
154 # nfsd sets its process name to [nfsd] so don't look for $nfsd
155 ebegin "Stopping NFS daemon"
156 start-stop-daemon --stop --quiet --oknodo \
157 --name nfsd --user root --signal 2 1>&2
158 eend $? "Error stopping NFS daemon"
159
160 if [ -x $rquotad ]; then
161 ebegin "Stopping NFS rquotad"
162 start-stop-daemon --stop --quiet --oknodo \
163 --exec $rquotad 1>&2
164 eend $? "Error stopping NFS rquotad"
165 fi
166
167 # When restarting the NFS server, running "exportfs -ua" probably
168 # isn't what the user wants. Running it causes all entries listed
169 # in xtab to be removed from the kernel export tables, and the
170 # xtab file is cleared. This effectively shuts down all NFS
171 # activity, leaving all clients holding stale NFS filehandles,
172 # *even* when the NFS server has restarted.
173 #
174 # That's what you would want if you were shutting down the NFS
175 # server for good, or for a long period of time, but not when the
176 # NFS server will be running again in short order. In this case,
177 # then "exportfs -r" will reread the xtab, and all the current
178 # clients will be able to resume NFS activity, *without* needing
179 # to umount/(re)mount the filesystem.
180 if [ "$restarting" = no ]; then
181 ebegin "Unexporting NFS directories"
182 # Exportfs likes to hang if networking isn't working.
183 # If that's the case, then try to kill it so the
184 # shutdown process can continue.
185 $exportfs -ua 1>&2 &
186 waitfor_exportfs $!
187 eend $? "Error unexporting NFS directories"
188 fi
189
190 stop_statd
191 stop_idmapd
192 }
193
194 reload() {
195 # Exportfs likes to hang if networking isn't working.
196 # If that's the case, then try to kill it so the
197 # bootup process can continue.
198 ebegin "Reloading /etc/exports"
199 $exportfs -r 1>&2 &
200 waitfor_exportfs $!
201 eend $? "Error exporting NFS directories"
202 }
203
204 restart() {
205 # See long comment in stop() regarding "restarting" and exportfs -ua
206 restarting=yes
207 svc_stop
208 svc_start
209 }

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20