#! /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 global PATH := '/sbin:/usr/sbin:/bin:/usr/bin' global KERNEL := $[uname -s] global RELEASE := $[uname -r] source /lib/init/vars.sh source /lib/lsb/init-functions matchstr "$(KERNEL):$(RELEASE)" { Linux:[01].*|Linux:2.[01].* { global FLAGS := ''"" } Linux:2.[23].*|Linux:2.4.?|Linux:2.4.?-*|Linux:2.4.10|Linux:2.4.10-* { global FLAGS := '"-f'" } * { global 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 # global DIRS := ''"" while read -r DEV MTPT FSTYPE OPTS REST { matchstr $MTPT { /|/proc|/dev|/dev/pts|/dev/shm|/proc/*|/sys|/run|/run/* { continue } /var/run { continue } /var/lock { continue } } matchstr $FSTYPE { nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|ceph { global DIRS := ""$MTPT $DIRS"" } proc|procfs|linprocfs|devpts|usbfs|usbdevfs|sysfs { global DIRS := ""$MTPT $DIRS"" } } matchstr $OPTS { _netdev|*,_netdev|_netdev,*|*,_netdev,* { global 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 global 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 } } matchstr $1 { start { # No-op } restart|reload|force-reload { echo "Error: argument '$1' not supported" > !2 exit 3 } stop|"" { do_stop } * { echo "Usage: umountnfs.sh [start|stop]" > !2 exit 3 } } :