#! /bin/sh ### BEGIN INIT INFO # Provides: umountnfs # Required-Start: # Required-Stop: umountfs # Should-Stop: $network $portmap nfs-common # Default-Start: # Default-Stop: 0 6 # Short-Description: Unmount all network filesystems except the root fs. # Description: Also unmounts all virtual filesystems (proc, # devpts, usbfs, sysfs) that are not mounted at the # top level. ### END INIT INFO setvar PATH = "/sbin:/usr/sbin:/bin:/usr/bin" setvar KERNEL = "$(uname -s)" setvar RELEASE = "$(uname -r)" source /lib/init/vars.sh source /lib/lsb/init-functions match "${KERNEL}:${RELEASE}" { with Linux:[01].*|Linux:2.[01].* setvar FLAGS = """" with Linux:2.[23].*|Linux:2.4.?|Linux:2.4.?-*|Linux:2.4.10|Linux:2.4.10-* setvar FLAGS = ""-f"" with * setvar FLAGS = ""-f -l"" } proc do_stop { # Write a reboot record to /var/log/wtmp before unmounting halt -w # Remove bootclean flag files (precaution against symlink attacks) rm -f /tmp/.clean /run/.clean /run/lock/.clean # # Make list of points to unmount in reverse order of their creation # setvar DIRS = """" while read -r DEV MTPT FSTYPE OPTS REST { match $MTPT { with /|/proc|/dev|/dev/pts|/dev/shm|/proc/*|/sys|/run|/run/* continue } match $FSTYPE { with nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|ceph setvar DIRS = ""$MTPT $DIRS"" with proc|procfs|linprocfs|devpts|usbfs|usbdevfs|sysfs setvar DIRS = ""$MTPT $DIRS"" } match $OPTS { with _netdev|*,_netdev|_netdev,*|*,_netdev,* setvar DIRS = ""$MTPT $DIRS"" } } < /etc/mtab if test $DIRS { test $VERBOSE = no || log_action_begin_msg "Unmounting remote and non-toplevel virtual filesystems" fstab-decode umount $FLAGS $DIRS setvar ES = "$Status" test $VERBOSE = no || log_action_end_msg $ES } # emit unmounted-remote-filesystems hook point so any upstart jobs # that support remote filesystems can be stopped if test -x /sbin/initctl { initctl --quiet emit unmounted-remote-filesystems 2>/dev/null || true } } match $1 { with start|status # No-op with restart|reload|force-reload echo "Error: argument '$1' not supported" >&2 exit 3 with stop|"" do_stop with * echo "Usage: umountnfs.sh [start|stop]" >&2 exit 3 } :