#! /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 setglobal PATH = '/sbin:/usr/sbin:/bin:/usr/bin' setglobal KERNEL = $[uname -s] setglobal RELEASE = $[uname -r] source /lib/init/vars.sh source /lib/lsb/init-functions match "$(KERNEL):$(RELEASE)" { with Linux:[01].*|Linux:2.[01].* setglobal FLAGS = ''"" with Linux:2.[23].*|Linux:2.4.?|Linux:2.4.?-*|Linux:2.4.10|Linux:2.4.10-* setglobal FLAGS = '"-f'" with * setglobal 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 # setglobal 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 setglobal DIRS = ""$MTPT $DIRS"" with proc|procfs|linprocfs|devpts|usbfs|usbdevfs|sysfs setglobal DIRS = ""$MTPT $DIRS"" } match $OPTS { with _netdev|*,_netdev|_netdev,*|*,_netdev,* setglobal 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 setglobal 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 } :