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