#!/bin/sh # # shutdwn Common script for system halt/reboot. # # Author: Miquel van Smoorenburg, # Changes: Grzegorz Stanislawski # Arkadiusz Mi¶kiewicz # # $Id$ # Set the path. PATH=/sbin:/bin:/usr/bin:/usr/sbin # move to root dir cd / . /etc/rc.d/init.d/functions # Kill all processes. [ "${BASH+bash}" = bash ] && enable kill runlevel=$1 run_cmd "Sending all processes the TERM signal" killall5 -15 sleep 5 run_cmd "Sending all processes the KILL signal" killall5 -9 # Write to wtmp file before unmounting /var halt -w # Turn off swap, then unmount file systems. run_cmd "Turning off swap and accounting" swapoff -a [ -x /sbin/accton ] && LC_ALL=C /sbin/accton 2>&1 | grep -v "not implemented" if [ -x /sbin/quotaoff ]; then run_cmd "Turning off quotas for local filesystems" /sbin/quotaoff -a fi # Unmount file systems, killing processes if we have to. sig=-15 retry=3 force= remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | iso9660 | ramfs | tmpfs | sysfs |^none|^\/dev\/root| \/ )/ {print $2}' /proc/mounts) while [ -n "$remaining" -a "$retry" -gt 0 ] do show "Unmounting file systems" ; busy if ERRORS=$(umount -a $FORCE -t noproc,devfs 2>&1) ; then ok else fail [ -n "$ERRORS" ] && echo "$ERRORS" fi sleep 2 remaining=$(awk '!/(^#| proc | loopfs | devfs | devpts | shm | sysfs |^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 force="-f" done run_cmd "Remounting root filesystem in ro mode" mount -n -o remount,ro / # turn off raid if [ -x /sbin/raidstop -a -f /etc/raidtab ]; then # we can not use raidstop -a here because this will only stop # devices listed in the default config file which is not always # the case. So we look only for the active raid devices if [ -f /proc/mdstat ] ; then mddevs=$(awk '/^md.* active/ {print $1}' /proc/mdstat) for mddev in $mddevs ; do run_cmd "Turning off RAID for $mddev" raidstop /dev/$mddev done unset mddev mddevs fi #runcmd "Turning off RAID" /sbin/raidstop -a fi show "Remounting remaining filesystems ro mode"; busy if ( mount | awk '/ext2|ext3|reiserfs|xfs|jfs/ { print $3 }' | \ while read line; do mount -n -o ro,remount $line; done ); then ok else fail fi if [ "$runlevel" = "0" ] ; then show "The system is halted"; ok [ -f /fastboot ] && (show "On the next boot fsck will be skipped."; ok) if [ -x /sbin/poweroff-ups -a -f /etc/killpower -a -f /etc/sysconfig/ups ] ; then . /etc/sysconfig/ups is_yes "$POWEROFF_UPS" && /sbin/poweroff-ups fi 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