3 # shutdwn Common script for system halt/reboot.
5 # Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
6 # Changes: Grzegorz Stanislawski <stangrze@open.net.pl>
7 # Arkadiusz Mi¶kiewicz <misiek@pld-linux.org>
12 PATH=/sbin:/bin:/usr/bin:/usr/sbin
17 . /etc/rc.d/init.d/functions
19 # avoid keyboard interruption
20 trap "echo" INT SEGV QUIT TERM
26 [ "${BASH+bash}" = bash ] && enable kill
30 run_cmd "Sending all processes the TERM signal" killall5 -15
32 run_cmd "Sending all processes the KILL signal" killall5 -9
34 # Write to wtmp file before unmounting /var
37 # Turn off swap, then unmount file systems.
38 run_cmd "Turning off swap" swapoff -a
40 [ -x /etc/rc.d/rc.acct ] && /etc/rc.d/rc.acct stop
42 if [ -x /sbin/quotaoff ]; then
43 run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a
46 # Unmount file systems, killing processes if we have to.
50 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
51 while [ -n "$remaining" -a "$retry" -gt 0 ]
53 show "Unmounting file systems" ; busy
54 if ERRORS=$(umount -a $FORCE -t noproc,devfs 2>&1) ; then
58 [ -n "$ERRORS" ] && echo "$ERRORS"
62 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs | squashfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts)
63 [ -z "$remaining" ] && break
64 /sbin/fuser -k -m $sig $remaining > /dev/null
71 run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro /
74 if [ -x /sbin/raidstop -a -f /etc/raidtab ]; then
75 # we can not use raidstop -a here because this will only stop
76 # devices listed in the default config file which is not always
77 # the case. So we look only for the active raid devices
78 if [ -f /proc/mdstat ] ; then
79 mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat)
80 for mddev in $mddevs ; do
81 run_cmd "Turning off RAID for $mddev" raidstop /dev/$mddev
85 #runcmd "Turning off RAID" /sbin/raidstop -a
88 show "Remounting remaining filesystems ro mode"; busy
89 if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \
91 mount -n -o ro,remount $line; done ); then
97 if [ "$runlevel" = "0" ] ; then
98 show "The system is halted"; ok
99 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
101 if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then
103 is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups
107 show "Please stand by while rebooting the system"; ok
108 [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok)
109 [ -x /sbin/kexec ] && /sbin/kexec -e
113 # This must be last line !
114 # vi:syntax=sh:tw=78:ts=8:sw=4