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
22 IDMAPD_PIDFILE=/var/run/rpc.idmapd.pid
24 GSSD_PIDFILE=/var/run/rpc.gssd.pid
25 PIPEFS_MOUNTPOINT=/var/lib/nfs/rpc_pipefs
27 if [ -f $DEFAULTFILE ]; then
31 . /lib/lsb/init-functions
33 # Determine whether lockd daemon is required.
37 '' | [01].* | 2.[0123].* )
38 # Older kernels may or may not need a lockd daemon.
39 # We must assume they do, unless we can prove otherwise.
40 # (A false positive here results only in a harmless message.)
42 if test -f /proc/ksyms
44 grep -q lockdctl /proc/ksyms || NEED_LOCKD=no
48 *) # Modern kernels (>= 2.4) start a lockd thread automatically.
56 # Parse the fstab file, and determine whether we need idmapd and gssd. (The
57 # /etc/defaults settings, if any, will override our autodetection.) This code
58 # is partially adapted from the mountnfs.sh script in the sysvinit package.
65 while read DEV MTPT FSTYPE OPTS REST
67 if [ "$FSTYPE" = "nfs4" ]; then
71 sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5i,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
80 # We also need idmapd if we run an NFSv4 server. It's fairly difficult
81 # to autodetect whether there are NFSv4 exports or not, and idmapd is not a
82 # particularily heavy daemon, so we auto-enable it if we find an /etc/exports
83 # file. This does not mean that there are NFSv4 or other mounts active (or
84 # even that nfs-kernel-server is installed), but it matches what the "start"
85 # condition in nfs-kernel-server's init script does, which has a value in
88 if [ -f /etc/exports ]; then
93 case "$NEED_IDMAPD" in
97 NEED_IDMAPD=$AUTO_NEED_IDMAPD
105 NEED_GSSD=$AUTO_NEED_GSSD
109 # Exit if required binaries are missing.
110 [ -x $PREFIX/sbin/rpc.statd ] || exit 0
111 [ -x $PREFIX/sbin/rpc.lockd ] || [ "$NEED_LOCKD" = no ] || exit 0
112 [ -x /usr/sbin/rpc.idmapd ] || [ "$NEED_IDMAPD" = no ] || exit 0
113 [ -x /usr/sbin/rpc.gssd ] || [ "$NEED_GSSD" = no ] || exit 0
116 modprobe -q "$1" || true
120 if ! grep -E -qs "$1\$" /proc/filesystems
124 if ! mountpoint -q "$2"
126 mount -t "$1" "$1" "$2"
133 if mountpoint -q "$1"
140 # See how we were called.
143 log_daemon_msg "Starting $DESC"
145 log_progress_msg "statd"
146 start-stop-daemon --start --oknodo --quiet \
147 --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
153 if [ "$NEED_LOCKD" = yes ]
155 log_progress_msg "lockd"
156 start-stop-daemon --start --oknodo --quiet \
157 --exec $PREFIX/sbin/rpc.lockd
163 if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
167 if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
169 if [ "$NEED_IDMAPD" = yes ]
171 log_progress_msg "idmapd"
172 start-stop-daemon --start --oknodo --quiet \
173 --make-pidfile --pidfile $IDMAPD_PIDFILE \
174 --exec /usr/sbin/rpc.idmapd
180 if [ "$NEED_GSSD" = yes ]
182 do_modprobe rpcsec_gss_krb5
183 log_progress_msg "gssd"
184 start-stop-daemon --start --oknodo --quiet \
185 --make-pidfile --pidfile $GSSD_PIDFILE \
186 --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
198 log_daemon_msg "Stopping $DESC"
200 if [ "$NEED_GSSD" = yes ]
202 log_progress_msg "gssd"
203 start-stop-daemon --stop --oknodo --quiet \
211 if [ "$NEED_IDMAPD" = yes ]
213 log_progress_msg "idmapd"
214 start-stop-daemon --stop --oknodo --quiet \
220 rm -f $IDMAPD_PIDFILE
222 if [ "$NEED_LOCKD" = yes ]
224 log_progress_msg "lockd"
225 start-stop-daemon --stop --oknodo --quiet \
232 pkill -KILL -u root -x lockd || true
234 log_progress_msg "statd"
235 start-stop-daemon --stop --oknodo --quiet \
241 do_umount $PIPEFS_MOUNTPOINT 2>/dev/null || true
246 if ! pidof rpc.statd >/dev/null
248 echo "rpc.statd not running"
252 if [ "$NEED_GSSD" = yes ]
254 if [ ! -f "$GSSD_PIDFILE" ] || ! pidof rpc.gssd >/dev/null
256 echo "rpc.statd running, but rpc.gssd halted"
261 if [ "$NEED_LOCKD" = yes ]
263 if ! pidof rpc.lockd >/dev/null
265 echo "rpc.statd running, but rpc.lockd halted"
270 if [ "$NEED_IDMAPD" = yes ]
272 if [ ! -f "$IDMAPD_PIDFILE" ] || ! pidof rpc.idmapd >/dev/null
274 echo "rpc.statd running, but rpc.idmapd halted"
279 echo "rpc.statd running"
283 restart | force-reload)
290 log_success_msg "Usage: nfs-common {start|stop|status|restart}"