2 # Copyright 1999-2014 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
6 extra_started_commands="reload"
8 # This variable is used for controlling whether or not to run exportfs -ua;
9 # see stop() for more information
12 # The binary locations
13 exportfs=/usr/sbin/exportfs
14 mountd=/usr/sbin/rpc.mountd
15 nfsd=/usr/sbin/rpc.nfsd
16 smnotify=/usr/sbin/sm-notify
20 # XXX: no way to detect NFSv4 is desired and so need rpc.idmapd
22 awk '!/^[[:space:]]*#/ {
23 # clear the path to avoid spurious matches
25 if ($0 ~ /[(][^)]*sec=(krb|spkm)[^)]*[)]/) {
29 }' /etc/exports /etc/exports.d/*.exports 2>/dev/null
31 config /etc/exports /etc/exports.d/*.exports
32 need portmap rpc.statd ${myneed} ${NFS_NEEDED_SERVICES}
33 use ypbind net dns rpc.rquotad rpc.idmapd rpc.svcgssd
39 for d in v4recovery v4root ; do
41 [ ! -d "${d}" ] && mkdir -p "${d}"
47 ( sleep ${EXPORTFS_TIMEOUT:-30}; kill -9 ${pid} 2>/dev/null ) &
52 if [ -e /proc/modules ] ; then
53 # Make sure nfs support is loaded in the kernel #64709
54 if ! grep -qs nfsd /proc/filesystems ; then
57 # Restart idmapd if needed #220747
58 if grep -qs nfsd /proc/modules ; then
59 killall -q -HUP rpc.idmapd
63 # This is the new "kernel 2.6 way" to handle the exports file
64 if grep -qs nfsd /proc/filesystems ; then
65 if ! mountinfo -q /proc/fs/nfsd ; then
66 ebegin "Mounting nfsd filesystem in /proc"
67 mount -t nfsd -o nodev,noexec,nosuid nfsd /proc/fs/nfsd
72 for o in ${OPTS_NFSD} ; do
73 echo "${o#*=}" > "/proc/fs/nfsd/${o%%=*}"
79 ebegin "Starting NFS $1"
89 # Exportfs likes to hang if networking isn't working.
90 # If that's the case, then try to kill it so the
91 # bootup process can continue.
92 if grep -qs '^[[:space:]]*/' /etc/exports /etc/exports.d/*.exports ; then
93 ebegin "Exporting NFS directories"
100 start_it mountd ${mountd} ${OPTS_RPC_MOUNTD}
101 start_it daemon ${nfsd} ${OPTS_RPC_NFSD}
102 [ -x "${smnotify}" ] && start_it smnotify ${smnotify} ${OPTS_SMNOTIFY}
109 ebegin "Stopping NFS mountd"
110 start-stop-daemon --stop --exec ${mountd}
114 # nfsd sets its process name to [nfsd] so don't look for $nfsd
115 ebegin "Stopping NFS daemon"
116 start-stop-daemon --stop --name nfsd --user root --signal 2
119 # in case things don't work out ... #228127
122 # When restarting the NFS server, running "exportfs -ua" probably
123 # isn't what the user wants. Running it causes all entries listed
124 # in xtab to be removed from the kernel export tables, and the
125 # xtab file is cleared. This effectively shuts down all NFS
126 # activity, leaving all clients holding stale NFS filehandles,
127 # *even* when the NFS server has restarted.
129 # That's what you would want if you were shutting down the NFS
130 # server for good, or for a long period of time, but not when the
131 # NFS server will be running again in short order. In this case,
132 # then "exportfs -r" will reread the xtab, and all the current
133 # clients will be able to resume NFS activity, *without* needing
134 # to umount/(re)mount the filesystem.
135 if [ "${restarting}" = no -o "${RC_CMD}" = "restart" ] ; then
136 ebegin "Unexporting NFS directories"
137 # Exportfs likes to hang if networking isn't working.
138 # If that's the case, then try to kill it so the
139 # shutdown process can continue.
149 # Exportfs likes to hang if networking isn't working.
150 # If that's the case, then try to kill it so the
151 # bootup process can continue.
152 ebegin "Reloading /etc/exports"
153 ${exportfs} -r 1>&2 &
159 # See long comment in stop() regarding "restarting" and exportfs -ua