5 # Required-Start: $time
7 # Default-Start: 2 3 4 5
9 # Short-Description: NFS support files common to client and server
10 # Description: NFS is a popular protocol for file sharing across
11 # TCP/IP networks. This service provides various
12 # support functions for NFS mounts.
16 DESC="NFS common utilities"
19 DEFAULTFILE=/etc/default/nfs-common
24 PIPEFS_MOUNTPOINT=/var/lib/nfs/rpc_pipefs
26 if [ -f $DEFAULTFILE ]; then
30 . /lib/lsb/init-functions
32 # Determine whether lockd daemon is required.
36 '' | [01].* | 2.[0123].* )
37 # Older kernels may or may not need a lockd daemon.
38 # We must assume they do, unless we can prove otherwise.
39 # (A false positive here results only in a harmless message.)
41 if test -f /proc/ksyms
43 grep -q lockdctl /proc/ksyms || NEED_LOCKD=no
47 *) # Modern kernels (>= 2.4) start a lockd thread automatically.
55 # Parse the fstab file, and determine whether we need idmapd and gssd. (The
56 # /etc/defaults settings, if any, will override our autodetection.) This code
57 # is partially adapted from the mountnfs.sh script in the sysvinit package.
64 while read DEV MTPT FSTYPE OPTS REST
66 if [ "$FSTYPE" = "nfs4" ]; then
70 sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5i,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
79 # We also need idmapd if we run an NFSv4 server. It's fairly difficult
80 # to autodetect whether there are NFSv4 exports or not, and idmapd is not a
81 # particularily heavy daemon, so we auto-enable it if we find an /etc/exports
82 # file. This does not mean that there are NFSv4 or other mounts active (or
83 # even that nfs-kernel-server is installed), but it matches what the "start"
84 # condition in nfs-kernel-server's init script does, which has a value in
87 if [ -f /etc/exports ]; then
92 case "$NEED_IDMAPD" in
96 NEED_IDMAPD=$AUTO_NEED_IDMAPD
104 NEED_GSSD=$AUTO_NEED_GSSD
108 # Exit if required binaries are missing.
109 [ -x $PREFIX/sbin/rpc.statd ] || exit 0
110 [ -x $PREFIX/sbin/rpc.lockd ] || [ "$NEED_LOCKD" = no ] || exit 0
111 [ -x /usr/sbin/rpc.idmapd ] || [ "$NEED_IDMAPD" = no ] || exit 0
112 [ -x /usr/sbin/rpc.gssd ] || [ "$NEED_GSSD" = no ] || exit 0
115 modprobe -q "$1" || true
119 if ! grep -E -qs "$1\$" /proc/filesystems
123 if ! mountpoint -q "$2"
125 mount -t "$1" "$1" "$2"
132 if mountpoint -q "$1"
139 # See how we were called.
142 log_daemon_msg "Starting $DESC"
144 log_progress_msg "statd"
145 start-stop-daemon --start --oknodo --quiet \
146 --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
152 if [ "$NEED_LOCKD" = yes ]
154 log_progress_msg "lockd"
155 start-stop-daemon --start --oknodo --quiet \
156 --exec $PREFIX/sbin/rpc.lockd
162 if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
166 if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
168 if [ "$NEED_IDMAPD" = yes ]
170 log_progress_msg "idmapd"
171 start-stop-daemon --start --oknodo --quiet \
172 --exec /usr/sbin/rpc.idmapd
178 if [ "$NEED_GSSD" = yes ]
180 do_modprobe rpcsec_gss_krb5
181 log_progress_msg "gssd"
183 # we need this available; better to fail now than
184 # mysteriously on the first mount
185 if ! grep -q -E '^nfs[ ]' /etc/services; then
186 log_action_end_msg 1 "broken /etc/services, please see /usr/share/doc/nfs-common/README.Debian.nfsv4"
190 start-stop-daemon --start --oknodo --quiet \
191 --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
203 log_daemon_msg "Stopping $DESC"
205 if [ "$NEED_GSSD" = yes ]
207 log_progress_msg "gssd"
208 start-stop-daemon --stop --oknodo --quiet \
215 if [ "$NEED_IDMAPD" = yes ]
217 log_progress_msg "idmapd"
218 start-stop-daemon --stop --oknodo --quiet \
225 if [ "$NEED_LOCKD" = yes ]
227 log_progress_msg "lockd"
228 start-stop-daemon --stop --oknodo --quiet \
235 pkill -KILL -u root -x lockd || true
237 log_progress_msg "statd"
238 start-stop-daemon --stop --oknodo --quiet \
244 do_umount $PIPEFS_MOUNTPOINT 2>/dev/null || true
249 if ! pidof rpc.statd >/dev/null
251 echo "rpc.statd not running"
255 if [ "$NEED_GSSD" = yes ]
257 if ! pidof rpc.gssd >/dev/null
259 echo "rpc.statd running, but rpc.gssd halted"
264 if [ "$NEED_LOCKD" = yes ]
266 if ! pidof rpc.lockd >/dev/null
268 echo "rpc.statd running, but rpc.lockd halted"
273 if [ "$NEED_IDMAPD" = yes ]
275 if ! pidof rpc.idmapd >/dev/null
277 echo "rpc.statd running, but rpc.idmapd halted"
282 echo "rpc.statd running"
286 restart | force-reload)
293 log_success_msg "Usage: nfs-common {start|stop|status|restart}"