5 # Required-Start: $time
6 # Default-Start: 2 3 4 5
8 # Short-Description: NFS support files common to client and server
9 # Description: NFS is a popular protocol for file sharing across
10 # TCP/IP networks. This service provides various
11 # support functions for NFS mounts.
15 DESC="NFS common utilities"
18 DEFAULTFILE=/etc/default/nfs-common
23 PIPEFS_MOUNTPOINT=/var/lib/nfs/rpc_pipefs
25 if [ -f $DEFAULTFILE ]; then
29 . /lib/lsb/init-functions
31 # Determine whether lockd daemon is required.
35 '' | [01].* | 2.[0123].* )
36 # Older kernels may or may not need a lockd daemon.
37 # We must assume they do, unless we can prove otherwise.
38 # (A false positive here results only in a harmless message.)
40 if test -f /proc/ksyms
42 grep -q lockdctl /proc/ksyms || NEED_LOCKD=no
46 *) # Modern kernels (>= 2.4) start a lockd thread automatically.
54 # Parse the fstab file, and determine whether we need idmapd and gssd. (The
55 # /etc/defaults settings, if any, will override our autodetection.) This code
56 # is partially adapted from the mountnfs.sh script in the sysvinit package.
63 while read DEV MTPT FSTYPE OPTS REST
65 if [ "$FSTYPE" = "nfs4" ]; then
69 sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5i,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
78 # We also need idmapd if we run an NFSv4 server. It's fairly difficult
79 # to autodetect whether there are NFSv4 exports or not, and idmapd is not a
80 # particularily heavy daemon, so we auto-enable it if we find an /etc/exports
81 # file. This does not mean that there are NFSv4 or other mounts active (or
82 # even that nfs-kernel-server is installed), but it matches what the "start"
83 # condition in nfs-kernel-server's init script does, which has a value in
86 if [ -f /etc/exports ]; then
91 case "$NEED_IDMAPD" in
95 NEED_IDMAPD=$AUTO_NEED_IDMAPD
103 NEED_GSSD=$AUTO_NEED_GSSD
107 # Exit if required binaries are missing.
108 [ -x $PREFIX/sbin/rpc.statd ] || exit 0
109 [ -x $PREFIX/sbin/rpc.lockd ] || [ "$NEED_LOCKD" = no ] || exit 0
110 [ -x /usr/sbin/rpc.idmapd ] || [ "$NEED_IDMAPD" = no ] || exit 0
111 [ -x /usr/sbin/rpc.gssd ] || [ "$NEED_GSSD" = no ] || exit 0
114 modprobe -q "$1" || true
118 if ! grep -E -qs "$1\$" /proc/filesystems
122 if ! mountpoint -q "$2"
124 mount -t "$1" "$1" "$2"
131 if mountpoint -q "$1"
138 # See how we were called.
141 log_daemon_msg "Starting $DESC"
143 log_progress_msg "statd"
144 start-stop-daemon --start --oknodo --quiet \
145 --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
151 if [ "$NEED_LOCKD" = yes ]
153 log_progress_msg "lockd"
154 start-stop-daemon --start --oknodo --quiet \
155 --exec $PREFIX/sbin/rpc.lockd
161 if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
165 if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
167 if [ "$NEED_IDMAPD" = yes ]
169 log_progress_msg "idmapd"
170 start-stop-daemon --start --oknodo --quiet \
171 --exec /usr/sbin/rpc.idmapd
177 if [ "$NEED_GSSD" = yes ]
179 do_modprobe rpcsec_gss_krb5
180 log_progress_msg "gssd"
181 start-stop-daemon --start --oknodo --quiet \
182 --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
194 log_daemon_msg "Stopping $DESC"
196 if [ "$NEED_GSSD" = yes ]
198 log_progress_msg "gssd"
199 start-stop-daemon --stop --oknodo --quiet \
206 if [ "$NEED_IDMAPD" = yes ]
208 log_progress_msg "idmapd"
209 start-stop-daemon --stop --oknodo --quiet \
216 if [ "$NEED_LOCKD" = yes ]
218 log_progress_msg "lockd"
219 start-stop-daemon --stop --oknodo --quiet \
226 pkill -KILL -u root -x lockd || true
228 log_progress_msg "statd"
229 start-stop-daemon --stop --oknodo --quiet \
235 do_umount $PIPEFS_MOUNTPOINT 2>/dev/null || true
240 if ! pidof rpc.statd >/dev/null
242 echo "rpc.statd not running"
246 if [ "$NEED_GSSD" = yes ]
248 if ! pidof rpc.gssd >/dev/null
250 echo "rpc.statd running, but rpc.gssd halted"
255 if [ "$NEED_LOCKD" = yes ]
257 if ! pidof rpc.lockd >/dev/null
259 echo "rpc.statd running, but rpc.lockd halted"
264 if [ "$NEED_IDMAPD" = yes ]
266 if ! pidof rpc.idmapd >/dev/null
268 echo "rpc.statd running, but rpc.idmapd halted"
273 echo "rpc.statd running"
277 restart | force-reload)
284 log_success_msg "Usage: nfs-common {start|stop|status|restart}"