PageRenderTime 141ms CodeModel.GetById 132ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/rc6.d/S40umountfs

http://github.com/brinkman83/bashrc
Shell | 140 lines | 106 code | 11 blank | 23 comment | 10 complexity | 842eba3cdd65c66a424f80a53f87d704 MD5 | raw file
  1#! /bin/sh
  2### BEGIN INIT INFO
  3# Provides:          umountfs
  4# Required-Start:
  5# Required-Stop:     umountroot
  6# Default-Start:
  7# Default-Stop:      0 6
  8# Short-Description: Turn off swap and unmount all local file systems.
  9# Description:
 10### END INIT INFO
 11
 12PATH=/sbin:/usr/sbin:/bin:/usr/bin
 13. /lib/init/vars.sh
 14
 15. /lib/lsb/init-functions
 16
 17umask 022
 18
 19do_stop () {
 20	exec 9<&0 </proc/mounts
 21
 22	PROTECTED_MOUNTS="$(sed -n '0,/^\/[^ ]* \/ /p' /proc/mounts)"
 23	WEAK_MTPTS="" # be gentle, don't use force
 24	REG_MTPTS=""
 25	TMPFS_MTPTS=""
 26	while read -r DEV MTPT FSTYPE REST
 27	do
 28		echo "$PROTECTED_MOUNTS" | grep -qs "^$DEV $MTPT " && continue
 29		case "$MTPT" in
 30		  /|/proc|/dev|/.dev|/dev/pts|/dev/shm|/dev/.static/dev|/proc/*|/sys|/lib/init/rw)
 31			continue
 32			;;
 33		  /var/run)
 34			continue
 35			;;
 36		  /var/lock)
 37			continue
 38			;;
 39		esac
 40		case "$FSTYPE" in 
 41		  proc|procfs|linprocfs|devfs|sysfs|usbfs|usbdevfs|devpts)
 42			continue
 43			;;
 44		  tmpfs)
 45			TMPFS_MTPTS="$MTPT $TMPFS_MTPTS"
 46			;;
 47		  *)
 48			if echo "$PROTECTED_MOUNTS" | grep -qs "^$DEV "; then
 49				WEAK_MTPTS="$MTPT $WEAK_MTPTS"
 50			else
 51				REG_MTPTS="$MTPT $REG_MTPTS"
 52			fi
 53			;;
 54		esac
 55	done
 56
 57	exec 0<&9 9<&-
 58	
 59	#
 60	# Make sure tmpfs file systems are umounted before turning off
 61	# swap, to avoid running out of memory if the tmpfs filesystems
 62	# use a lot of space.
 63	#
 64	if [ "$TMPFS_MTPTS" ]
 65	then
 66		if [ "$VERBOSE" = no ]
 67		then
 68			log_action_begin_msg "Unmounting temporary filesystems"
 69			fstab-decode umount $TMPFS_MTPTS
 70			log_action_end_msg $?
 71		else
 72			log_daemon_msg "Will now unmount temporary filesystems"
 73			fstab-decode umount -v $TMPFS_MTPTS
 74			log_end_msg $?
 75		fi
 76	fi
 77
 78	#
 79	# Deactivate swap
 80	#
 81	if [ "$VERBOSE" = no ]
 82	then
 83		log_action_begin_msg "Deactivating swap"
 84		swapoff -a >/dev/null
 85		log_action_end_msg $?
 86	else
 87		log_daemon_msg "Will now deactivate swap"
 88		swapoff -a -v
 89		log_end_msg $?
 90	fi
 91
 92	#
 93	# Unmount local filesystems
 94	#
 95	if [ "$WEAK_MTPTS" ]; then
 96		# Do not use -f umount option for WEAK_MTPTS
 97		if [ "$VERBOSE" = no ]
 98		then
 99			log_action_begin_msg "Unmounting weak filesystems"
100			fstab-decode umount -r -d $WEAK_MTPTS
101			log_action_end_msg $?
102		else
103			log_daemon_msg "Will now unmount weak filesystems"
104			fstab-decode umount -v -r -d $WEAK_MTPTS
105			log_end_msg $?
106		fi
107	fi
108	if [ "$REG_MTPTS" ]
109	then
110		if [ "$VERBOSE" = no ]
111		then
112			log_action_begin_msg "Unmounting local filesystems"
113			fstab-decode umount -f -r -d $REG_MTPTS
114			log_action_end_msg $?
115		else
116			log_daemon_msg "Will now unmount local filesystems"
117			fstab-decode umount -f -v -r -d $REG_MTPTS
118			log_end_msg $?
119		fi
120	fi
121}
122
123case "$1" in
124  start)
125	# No-op
126	;;
127  restart|reload|force-reload)
128	echo "Error: argument '$1' not supported" >&2
129	exit 3
130	;;
131  stop)
132	do_stop
133	;;
134  *)
135	echo "Usage: $0 start|stop" >&2
136	exit 3
137	;;
138esac
139
140: