aboutsummaryrefslogtreecommitdiffstats
path: root/rc.d/init.d/halt
diff options
context:
space:
mode:
Diffstat (limited to 'rc.d/init.d/halt')
-rwxr-xr-xrc.d/init.d/halt178
1 files changed, 126 insertions, 52 deletions
diff --git a/rc.d/init.d/halt b/rc.d/init.d/halt
index cb33cbed..3f6d5dac 100755
--- a/rc.d/init.d/halt
+++ b/rc.d/init.d/halt
@@ -20,7 +20,7 @@ halt_crypto() {
[ -z "$dst" -o "${dst#\#}" != "$dst" ] && continue
if [ -b "/dev/mapper/$dst" ]; then
if /sbin/dmsetup info "$dst" | grep -q '^Open count: *0$'; then
- action $"Stopping disk encryption for $dst" /sbin/cryptsetup remove "$dst"
+ action "Stopping disk encryption for %s" $dst /sbin/cryptsetup remove "$dst"
else
fnval=1
fi
@@ -30,36 +30,27 @@ halt_crypto() {
}
kill_all() {
- local STRING rc
-
- STRING=$1
- echo -n "$STRING "
- shift
/sbin/killall5 "$@"
rc=$?
- # Retval: 0: success 1: error 2: no processes found to kill
if [ "$rc" == 1 ]; then
- failure $"$STRING"
- else
- success $"$STRING"
+ return 1
fi
- echo
- return $rc
+ return 0
}
# See how we were called.
case "$0" in
*halt)
- message=$"Halting system..."
+ message=`gprintf "Halting system..."`
command="/sbin/halt"
;;
*reboot)
- message=$"Please stand by while rebooting the system..."
+ message=`gprintf "Please stand by while rebooting the system..."`
command="/sbin/reboot"
kexec_command="/sbin/kexec"
;;
*)
- echo $"$0: call me as 'halt' or 'reboot' please!"
+ gprintf "%s: call me as 'halt' or 'reboot' please!\n" $0
exit 1
;;
esac
@@ -67,44 +58,87 @@ case "$1" in
*start)
;;
*)
- echo $"Usage: $0 {start}"
+ gprintf "Usage: %s\n" "$(basename $0) {start}"
exit 1
;;
esac
+# Recreate the /initrd if needed
+if [ ! -d /initrd ]; then
+ action "Creating initrd directory" mkdir /initrd
+fi
+if [ -d /initrd -a ! -f /initrd/README.WARNING ]; then
+ cat > /initrd/README.WARNING <<EOF
+(mkinitrd) Don't remove this directory, it's needed at boot time,
+in the initrd, to perform the pivot_root.
+EOF
+fi
+
+update_boot_stage kill
+
# Kill all processes.
[ "${BASH+bash}" = bash ] && enable kill
+OMITPIDS=
+omitfile=/var/run/sendsigs.omit
+if [ -e $omitfile ]; then
+ for pid in $(cat $omitfile); do
+ OMITPIDS="${OMITPIDS:+$OMITPIDS }-o $pid"
+ done
+fi
# Find mdmon pid's and omit killing them
OMITARGS=
-for i in /dev/md/*.pid; do
- if [ ! -r "$i" ]; then
+for i in /dev/.mdadm/*.pid; do
+ if [ "$i" = "mdadm.pid" -o ! -r "$i" ]; then
continue
fi
OMITARGS="$OMITARGS -o $(cat $i)"
done
-kill_all $"Sending all processes the TERM signal..." -15 $OMITARGS
+
+action "Sending all processes the TERM signal..." kill_all -15 $OMITPIDS $OMITARGS
+alldead=""
+for i in 0 1 2 3 4 5 6 7 8 9 10; do
+ # use SIGCONT/signal 18 to check if there are
+ # processes left. No need to check the exit code
+ # value, because either killall5 work and it make
+ # sense to wait for processes to die, or it fail and
+ # there is nothing to wait for.
+ if /sbin/killall5 -18 $OMITPIDS $OMITARGS; then
+ :
+ else
+ alldead=1
+ break
+ fi
+
+ sleep 1
+done
# No need to sleep and kill -9 if no processes to kill were found
-if [ "$?" == 0 ]; then
- sleep 2
- kill_all $"Sending all processes the KILL signal..." -9 $OMITARGS
+if [ -z "$alldead" ]; then
+ action "Sending all processes the KILL signal..." kill_all -9 $OMITPIDS $OMITARGS
fi
# Write to wtmp file before unmounting /var
/sbin/halt -w
# Save mixer settings, here for lack of a better place.
-if [ -s /etc/alsa/alsactl.conf ] && [ -x /sbin/alsactl ] && [ -w /etc/asound.state ]; then
- action $"Saving mixer settings" /sbin/alsactl -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --ignore store
+if [ -x /sbin/alsactl ]; then
+ action "Saving mixer settings" /sbin/alsactl --ignore store
fi
# Save random seed
touch /var/lib/random-seed
chmod 600 /var/lib/random-seed
-action $"Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
+action "Saving random seed: " dd if=/dev/urandom of=/var/lib/random-seed count=1 bs=512 2>/dev/null
-[ -x /sbin/hwclock ] && action $"Syncing hardware clock to system time" /sbin/hwclock --systohc
+update_boot_stage clock
+[ -x /sbin/hwclock ] && action "Syncing hardware clock to system time" /sbin/hwclock --systohc
+
+if [ -x /sbin/halt.pre ]; then
+ /sbin/halt.pre
+fi
+
+update_boot_stage umount
# Try to unmount tmpfs filesystems to avoid swapping them in. Ignore failures.
tmpfs=$(awk '$2 ~ /^\/($|proc|dev)/ { next; }
@@ -114,7 +148,7 @@ tmpfs=$(awk '$2 ~ /^\/($|proc|dev)/ { next; }
# Turn off swap, then unmount file systems.
[ -f /proc/swaps ] && SWAPS=$(awk '! /^Filename/ { print $1 }' /proc/swaps)
if [ -n "$SWAPS" ]; then
- action $"Turning off swap: " swapoff $SWAPS
+ action "Turning off swap: " swapoff $SWAPS
for dst in $SWAPS; do
if [[ "$dst" == /dev/mapper* ]] \
&& [ "$(dmsetup status "$dst" | cut -d ' ' -f 3)" = crypt ]; then
@@ -125,7 +159,11 @@ if [ -n "$SWAPS" ]; then
done
fi
-[ -x /sbin/quotaoff ] && action $"Turning off quotas: " /sbin/quotaoff -aug
+[ -x /sbin/quotaoff ] && action "Turning off quotas: " /sbin/quotaoff -aug
+
+# first remove entry /initrd/loopfs as it can't be unmounted :(
+mtab=$(fgrep -v "/initrd/loopfs[^/]" /etc/mtab)
+(IFS= ; echo $mtab > /etc/mtab)
# Unmount file systems, killing processes if we have to.
# Unmount loopback stuff first
@@ -134,29 +172,61 @@ __umount_loopback_loop
# Unmount RPC pipe file systems
__umount_loop '$3 ~ /^rpc_pipefs$/ || $3 ~ /^rpc_svc_gss_pipefs$/ {print $2}' \
/proc/mounts \
- $"Unmounting pipe file systems: " \
- $"Unmounting pipe file systems (retry): " \
+ "Unmounting pipe file systems: " \
+ "Unmounting pipe file systems (retry): " \
-f
LANG=C __umount_loop '$2 ~ /^\/$|^\/proc|^\/cgroup|^\/sys\/fs\/cgroup|^\/dev/{next}
+ $2 ~ /^\/live\//{next}
$3 == "tmpfs" || $3 == "proc" {print $2 ; next}
/(loopfs|autofs|nfs|cifs|smbfs|ncpfs|sysfs|^none|^\/dev\/ram|^\/dev\/root$)/ {next}
{print $2}' /proc/mounts \
- $"Unmounting file systems: " \
- $"Unmounting file systems (retry): " \
+ "Unmounting file systems: " \
+ "Unmounting file systems (retry): " \
-f
-[ -f /proc/bus/usb/devices ] && $UMOUNT /proc/bus/usb
+update_boot_stage lvm
+
+# stop crypto devices before lvm, as they can sit on top of LVM
[ -f /etc/crypttab ] && halt_crypto
+if [ -f /etc/lvm/lvm.conf -a -x /sbin/lvm2 ]; then
+ if grep -q -s 'device-mapper' /proc/devices; then
+ _vgchange_cmd="/sbin/lvm2 vgchange -a n"
+ fi
+fi
+
+if [ -z "${_vgscan_cmd}" -a -f /etc/lvmtab -a -e /proc/lvm ] ; then
+ if [ -x /sbin/lvm1-vgchange ]; then
+ _vgchange_cmd="/sbin/lvm1-vgchange -a n"
+ elif [ -x /sbin/vgchange ]; then
+ _vgchange_cmd="/sbin/vgchange -a n"
+ fi
+fi
+
+if [ -n "${_vgchange_cmd}" ]; then
+ action "Shutting down LVM:" ${_vgchange_cmd}
+fi
+
+# for NUT
+# do it here to have /proc/usb mounted for UPS on USB
+if [ -f /etc/init.d/upsd ]; then
+ /etc/init.d/upsd powerdown
+ [ $? == 3 ] && exit 1
+fi
+
+[ -f /proc/bus/usb/devices ] && $UMOUNT /proc/bus/usb
+
# remove the crash indicator flag
rm -f /.autofsck
+update_boot_stage umount_force
+
# Try all file systems other than root, essential filesystems and RAM disks,
# one last time.
-awk '$2 !~ /\/(|dev|proc|selinux|cgroup|sys)$/ && $1 !~ /(^\/dev\/ram|cgroup)/ { print $2 }' \
- /proc/mounts | sort -r | \
+# eugeni: we should umount the filesystems in reverse order (#53042)
+tac /proc/mounts | awk '$2 !~ /\/(|dev|proc|selinux|cgroup|sys)$/ && $2 !~ /^\/live\// && $1 !~ /(^\/dev\/ram|cgroup)/ { print $2 }' | \
while read line; do
fstab-decode $UMOUNT -f $line
done
@@ -165,8 +235,7 @@ if [ -x /sbin/halt.local ]; then
/sbin/halt.local
fi
-# Tell init to re-exec itself.
-kill -TERM 1
+update_boot_stage remount_ro
# Remount read only anything that's left mounted.
# echo $"Remounting remaining filesystems readonly"
@@ -174,34 +243,39 @@ mount | awk '{ print $1,$3 }' | while read dev dir; do
fstab-decode mount -n -o ro,remount $dev $dir
done
+# (bor) it is impossible under systemd and is not required otherwise
+# action "Unmounting proc file system: " umount /proc
+
+# See if this is a powerfail situation.
+if [ -f /etc/apcupsd/powerfail ]; then
+ gprintf "APCUPSD will now power off the UPS!\n"
+ echo
+ /etc/apcupsd/apccontrol killpower
+ echo
+ gprintf "Please ensure that the UPS has powered off before rebooting\n"
+ gprintf "Otherwise, the UPS may cut the power during the reboot!!!\n"
+ echo
+fi
+
+update_boot_stage halt
+
# If we left mdmon's running wait for the raidsets to become clean
if [ -n "$OMITARGS" ]; then
mdadm --wait-clean --scan
fi
# Now halt or reboot.
-echo $"$message"
+echo "$message"
if [ -f /fastboot ]; then
- echo $"On the next boot fsck will be skipped."
+ gprintf "On the next boot fsck will be skipped.\n"
elif [ -f /forcefsck ]; then
- echo $"On the next boot fsck will be forced."
-fi
-
-# Shutdown UPS drivers
-if [ "$command" = /sbin/halt ] && [ -f /etc/sysconfig/ups ]; then
- . /etc/sysconfig/ups
- if [ -z $POWERDOWNFLAG ]; then
- POWERDOWNFLAG=/etc/killpower
- fi
- if [ "$SERVER" = "yes" ] && [ -f $POWERDOWNFLAG ]; then
- /sbin/upsdrvctl shutdown
- fi
+ gprintf "On the next boot fsck will be forced.\n"
fi
# First, try kexec. If that fails, fall back to rebooting the old way.
[ -n "$kexec_command" ] && $kexec_command -e -x >& /dev/null
-HALTARGS="-d"
+HALTARGS="-i -d"
[ "$INIT_HALT" != "HALT" ] && HALTARGS="$HALTARGS -p"
exec $command $HALTARGS