]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - rc.d/rc.shutdown
- merge my private tree
[projects/rc-scripts.git] / rc.d / rc.shutdown
index cb47f36071e2e9aceb035972f8f53b8159e6e699..0f591c5bb0ec89c4e58ec22d95717a114e305ac7 100755 (executable)
@@ -3,16 +3,19 @@
 # shutdwn       Common script for system halt/reboot.
 #
 # Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
-#               Modified for PLD Linux by Grzegorz Stanislawski
-# Changes:      Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
+# Changes:     Grzegorz Stanislawski <stangrze@open.net.pl>
+#              Arkadiusz Mi¶kiewicz <misiek@pld.org.pl>
 #
-# $Id: rc.shutdown,v 1.9 2000/06/18 09:52:05 kloczek Exp $
+# $Id: rc.shutdown,v 1.12.2.4 2001/09/30 10:19:36 misiek Exp $
 
 # Set the path.
 PATH=/sbin:/bin:/usr/bin:/usr/sbin
 
-# NLS
-NLS_DOMAIN="rc-scripts"
+# We can't use real NLS here! There are shells that support them and you end up
+# with unmountable /usr)
+NLS_DOMAIN=qwertyuiop
+
+runlevel="${1}"
 
 # move to root dir
 cd /
@@ -31,33 +34,68 @@ halt -w
 
 # Turn off swap, then unmount file systems.
 run_cmd "Turning off swap and accounting" swapoff -a
-[ -x /sbin/accton ] && /sbin/accton
+[ -x /sbin/accton ] && /sbin/accton 2>&1 | grep -v "not implemented"
+[ -x /sbin/quotaoff ] && run_cmd "Turning off quotas" /sbin/quotaoff -a
+
+# Unmount file systems, killing processes if we have to.
+# Unmount binded mounts
+remainingbind=$(awk '$4 ~ /bind/ {print $2}' /etc/mtab 2> /dev/null)
+# Unmount loopback stuff first
+remainingloop=$(awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
 
-if [ -x /sbin/quotaoff ]; then
-       run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
+if [ -n "$remainingbind" ]; then
+    remaining="$remainingbind"
+    [ -n "$remainingloop" ] && remaining="$remaining $remainingloop"
+else
+    remaining="$remainingloop"
 fi
 
-# Unmount file systems, killing processes if we have to.
-sig=
-retry=3
-remaining=`awk '!/(^#|proc|loopfs|devfs|devpts|^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts`
-while [ -n "$remaining" -a "$retry" -gt 0 ]
-do
-       show "Unmounting file systems"; busy
+if [ -n "$remaining" ]; then
+    sig=
+    retry=3
+    while [ -n "$remaining" -a "$retry" -gt 0 ]; do
        if [ "$retry" -lt 3 ]; then
-               run_cmd "Unmounting file systems"  umount -a -f -t noproc
+           run_cmd "Unmounting bind and loopback filesystems (retry)" umount $remaining
        else
-               run_cmd "Unmounting file systems"  umount -a -f -t noproc
+           run_cmd "Unmounting bind and loopback filesystems" umount $remaining
+       fi
+       remainingbind=$(awk '$4 ~ /bind/ {print $2}' /etc/mtab 2> /dev/null)
+       remainingloop=$(awk '!/^#/ && $1 ~ /^\/dev\/loop/ && $2 != "/" {print $2}' /proc/mounts)
+       if [ -n "$remainingbind" ]; then
+           remaining="$remainingbind"
+           [ -n "$remainingloop" ] && remaining="$remaining $remainingloop"
+       else
+           remaining="$remainingloop"
        fi
-       sleep 2
-       remaining=`awk '!/(^#|proc|loopfs|devfs|devpts|^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts`
        [ -z "$remaining" ] && break
-       /sbin/fuser -k -m $sig $remaining >/dev/null
+       /sbin/fuser -k -m $sig $remaining > /dev/null
        sleep 5
-       retry=$(($retry-1))
+       retry=$(( $retry - 1 ))
        sig=-9
+    done
+fi
+
+sig=
+retry=3
+remaining=$(awk '!/(^#|proc|loopfs|autofs|devfs|devpts|shm|^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
+
+while [ -n "$remaining" -a "$retry" -gt 0 ]; do
+    if [ "$retry" -lt 3 ]; then
+       run_cmd "Unmounting file systems (retry)"  umount -a -f -t noproc
+    else
+       run_cmd "Unmounting file systems" umount -a -f -t noproc
+    fi
+    sleep 2
+    remaining=$(awk '!/(^#|proc|loopfs|autofs|devfs|devpts|shm|^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
+    [ -z "$remaining" ] && break
+    /sbin/fuser -k -m $sig $remaining >/dev/null
+    sleep 5
+    retry=$(( $retry - 1 ))
+    sig=-9
 done
 
+[ -f /proc/bus/usb/devices ] && umount /proc/bus/usb
+
 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
 
 # turn off raid
@@ -68,19 +106,32 @@ if [ -x /sbin/raidstop -a -f /etc/raidtab ]; then
        if [ -f /proc/mdstat ] ; then
                mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat)
                for mddev in $mddevs ; do
-                       MESSAGE="`nls "Turning off RAID for %s" "$mddev"`"
-                       run_cmd "$MESSAGE" raidstop /dev/$mddev
+                       run_cmd "Turning off RAID for $mddev" /sbin/raidstop /dev/$mddev
                done
                unset mddev mddevs
        fi
-       #runcmd "Turning off RAID" /sbin/raidstop -a
+       # runcmd "Turning off RAID" /sbin/raidstop -a
 fi
 
 show "Remounting remaining filesystems ro mode"; busy
-if ( mount | awk '/ext2/ { print $3 }' | \
+if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
        while read line; do 
        mount -n -o ro,remount $line; done ); then
-       deltext; ok
+       ok
 else
-       deltext; fail
+       fail
 fi
+
+if [ "$runlevel" = "0" ] ; then
+       show "The system is halted"; ok
+       [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
+       eval halt -d -p
+else
+       show "Please stand by while rebooting the system"; ok
+       [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
+       eval reboot -d
+fi
+
+# This must be last line !
+# vi:syntax=sh:tw=78:ts=8:sw=4
+
This page took 0.029422 seconds and 4 git commands to generate.