5 # Required-Start: $portmap $time
7 # Default-Start: 2 3 4 5 S
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
23 PIPEFS_MOUNTPOINT=/run/rpc_pipefs
25 if [ -f $DEFAULTFILE ]; then
29 . /lib/lsb/init-functions
31 # Exit if required binaries are missing.
32 [ -x /sbin/rpc.statd ] || exit 0
35 # Parse the fstab file, and determine whether we need idmapd and gssd. (The
36 # /etc/defaults settings, if any, will override our autodetection.) This code
37 # is partially adapted from the mountnfs.sh script in the sysvinit package.
42 if [ -f /etc/fstab ]; then
45 while read DEV MTPT FSTYPE OPTS REST
52 # FSTYPE "nfs" can be NFSv4 now
53 #if [ "$FSTYPE" = "nfs4" ]; then
58 sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5i,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
68 # We also need idmapd if we run an NFSv4 server. It's fairly difficult
69 # to autodetect whether there are NFSv4 exports or not, and idmapd is not a
70 # particularily heavy daemon, so we auto-enable it if we find an /etc/exports
71 # file. This does not mean that there are NFSv4 or other mounts active (or
72 # even that nfs-kernel-server is installed), but it matches what the "start"
73 # condition in nfs-kernel-server's init script does, which has a value in
76 if [ -f /etc/exports ] && grep -q '^[[:space:]]*[^#]*/' /etc/exports; then
88 case "$NEED_IDMAPD" in
92 NEED_IDMAPD=$AUTO_NEED_IDMAPD
100 NEED_GSSD=$AUTO_NEED_GSSD
105 if [ -x /sbin/modprobe -a -f /proc/modules ]
107 modprobe -q "$1" || true
112 if ! grep -E -qs "$1\$" /proc/filesystems
116 if ! mountpoint -q "$2"
118 mount -t "$1" "$1" "$2"
125 if mountpoint -q "$1"
132 # See how we were called.
135 log_daemon_msg "Starting $DESC"
137 if [ "$NEED_STATD" = yes ]; then
138 log_progress_msg "statd"
140 # See if rpcbind is running
141 if [ -x /usr/sbin/rpcinfo ]; then
142 /usr/sbin/rpcinfo -p >/dev/null 2>&1
144 if [ $RET != 0 ]; then
146 log_warning_msg "Not starting: portmapper is not running"
150 start-stop-daemon --start --oknodo --quiet \
151 --pidfile /var/run/rpc.statd.pid \
152 --exec /sbin/rpc.statd -- $STATDOPTS
154 if [ $RET != 0 ]; then
158 if [ -d /run/sendsigs.omit.d ]; then
159 rm -f /run/sendsigs.omit.d/statd
160 ln -s /var/run/rpc.statd.pid /run/sendsigs.omit.d/statd
165 # Don't start idmapd and gssd if we don't have them (say, if /usr is not
167 [ -x /usr/sbin/rpc.idmapd ] || NEED_IDMAPD=no
168 [ -x /usr/sbin/rpc.gssd ] || NEED_GSSD=no
170 if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
175 mkdir -p "$PIPEFS_MOUNTPOINT"
176 if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
178 if [ "$NEED_IDMAPD" = yes ]
180 log_progress_msg "idmapd"
181 start-stop-daemon --start --oknodo --quiet \
182 --exec /usr/sbin/rpc.idmapd
184 if [ $RET != 0 ]; then
189 if [ "$NEED_GSSD" = yes ]
191 do_modprobe rpcsec_gss_krb5
192 log_progress_msg "gssd"
194 # we need this available; better to fail now than
195 # mysteriously on the first mount
196 if ! grep -q -E '^nfs[ ]' /etc/services; then
197 log_action_end_msg 1 "broken /etc/services, please see /usr/share/doc/nfs-common/README.Debian.nfsv4"
201 start-stop-daemon --start --oknodo --quiet \
202 --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
204 if [ $RET != 0 ]; then
215 log_daemon_msg "Stopping $DESC"
217 if [ "$NEED_GSSD" = yes ]
219 log_progress_msg "gssd"
220 start-stop-daemon --stop --oknodo --quiet \
223 if [ $RET != 0 ]; then
228 if [ "$NEED_IDMAPD" = yes ]
230 log_progress_msg "idmapd"
231 start-stop-daemon --stop --oknodo --quiet \
234 if [ $RET != 0 ]; then
239 if [ "$NEED_STATD" = yes ]
241 log_progress_msg "statd"
242 start-stop-daemon --stop --oknodo --quiet \
245 if [ $RET != 0 ]; then
250 do_umount $PIPEFS_MOUNTPOINT 2>/dev/null || true
255 if [ "$NEED_STATD" = yes ]
257 if ! pidof rpc.statd >/dev/null
259 echo "rpc.statd not running"
264 if [ "$NEED_GSSD" = yes ]
266 if ! pidof rpc.gssd >/dev/null
268 echo "rpc.gssd not running"
273 if [ "$NEED_IDMAPD" = yes ]
275 if ! pidof rpc.idmapd >/dev/null
277 echo "rpc.idmapd not running"
282 echo "all daemons running"
286 restart | force-reload)
293 log_success_msg "Usage: nfs-common {start|stop|status|restart}"