2009-08-26 17:00:38 +02:00
|
|
|
#! /bin/sh
|
|
|
|
#
|
|
|
|
# rc.6 This file is executed by init when it goes into runlevel
|
|
|
|
# 0 (halt) or runlevel 6 (reboot). It kills all processes,
|
|
|
|
# unmounts file systems and then either halts or reboots.
|
|
|
|
#
|
|
|
|
# Version: @(#)/etc/rc.d/rc.6 2.47 Sat Jan 13 13:37:26 PST 2001
|
|
|
|
#
|
|
|
|
# Author: Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
|
|
|
|
# Modified by: Patrick J. Volkerding, <volkerdi@slackware.com>
|
|
|
|
#
|
|
|
|
|
|
|
|
# Set the path.
|
2018-05-28 21:12:29 +02:00
|
|
|
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
|
2009-08-26 17:00:38 +02:00
|
|
|
|
|
|
|
# If there are SystemV init scripts for this runlevel, run them.
|
|
|
|
if [ -x /etc/rc.d/rc.sysvinit ]; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.sysvinit
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Set linefeed mode to avoid staircase effect.
|
|
|
|
/bin/stty onlcr
|
|
|
|
|
|
|
|
echo "Running shutdown script $0:"
|
|
|
|
|
|
|
|
# Find out how we were called.
|
|
|
|
case "$0" in
|
|
|
|
*0)
|
2016-06-30 22:26:57 +02:00
|
|
|
shutdown_command="halt"
|
2009-08-26 17:00:38 +02:00
|
|
|
;;
|
|
|
|
*6)
|
2016-06-30 22:26:57 +02:00
|
|
|
shutdown_command=reboot
|
2009-08-26 17:00:38 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$0: call me as \"rc.0\" or \"rc.6\" please!"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2018-06-13 07:43:00 +02:00
|
|
|
# Restart init. This prevents init from hanging on to file handles for removed
|
|
|
|
# glibc shared libraries in the case that those were upgraded or reinstalled.
|
|
|
|
/sbin/telinit u
|
|
|
|
|
2009-08-26 17:00:38 +02:00
|
|
|
# Save the system time to the hardware clock using hwclock --systohc.
|
2016-06-30 22:26:57 +02:00
|
|
|
# This will also create or update the timestamps in /etc/adjtime.
|
2009-08-26 17:00:38 +02:00
|
|
|
if [ -x /sbin/hwclock ]; then
|
|
|
|
# Check for a broken motherboard RTC clock (where ioports for rtc are
|
|
|
|
# unknown) to prevent hwclock causing a hang:
|
2016-06-30 22:26:57 +02:00
|
|
|
if ! grep -q " : rtc" /proc/ioports ; then
|
2009-08-26 17:00:38 +02:00
|
|
|
CLOCK_OPT="--directisa"
|
|
|
|
fi
|
2016-06-30 22:26:57 +02:00
|
|
|
if [ /etc/adjtime -nt /etc/hardwareclock ]; then
|
|
|
|
if grep -q "^LOCAL" /etc/adjtime ; then
|
|
|
|
echo "Saving system time to the hardware clock (localtime)."
|
|
|
|
else
|
|
|
|
echo "Saving system time to the hardware clock (UTC)."
|
|
|
|
fi
|
|
|
|
/sbin/hwclock $CLOCK_OPT --systohc
|
|
|
|
elif grep -q "^UTC" /etc/hardwareclock 2> /dev/null ; then
|
2009-08-26 17:00:38 +02:00
|
|
|
echo "Saving system time to the hardware clock (UTC)."
|
2016-06-30 22:26:57 +02:00
|
|
|
if [ ! -r /etc/adjtime ]; then
|
|
|
|
echo "Creating system time correction file /etc/adjtime."
|
|
|
|
fi
|
2009-08-26 17:00:38 +02:00
|
|
|
/sbin/hwclock $CLOCK_OPT --utc --systohc
|
|
|
|
else
|
|
|
|
echo "Saving system time to the hardware clock (localtime)."
|
2016-06-30 22:26:57 +02:00
|
|
|
if [ ! -r /etc/adjtime ]; then
|
|
|
|
echo "Creating system time correction file /etc/adjtime."
|
|
|
|
fi
|
|
|
|
/sbin/hwclock $CLOCK_OPT --localtime --systohc
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Run any local shutdown scripts:
|
|
|
|
if [ -x /etc/rc.d/rc.local_shutdown ]; then
|
|
|
|
/etc/rc.d/rc.local_shutdown stop
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Stop the Apache web server:
|
|
|
|
if [ -x /etc/rc.d/rc.httpd ]; then
|
|
|
|
/etc/rc.d/rc.httpd stop
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Stop the MySQL database:
|
2018-05-28 21:12:29 +02:00
|
|
|
if [ -x /etc/rc.d/rc.mysqld -a -r /var/run/mysql/mysql.pid ]; then
|
|
|
|
/etc/rc.d/rc.mysqld stop
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Stop the Samba server:
|
|
|
|
if [ -x /etc/rc.d/rc.samba ]; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.samba stop
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Shut down the NFS server:
|
|
|
|
if [ -x /etc/rc.d/rc.nfsd ]; then
|
|
|
|
/etc/rc.d/rc.nfsd stop
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Shut down the SSH server:
|
|
|
|
if [ -x /etc/rc.d/rc.sshd ]; then
|
|
|
|
/etc/rc.d/rc.sshd stop
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Shut down the SASL authentication daemon:
|
|
|
|
if [ -x /etc/rc.d/rc.saslauthd ]; then
|
|
|
|
/etc/rc.d/rc.saslauthd stop
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Shut down OpenLDAP:
|
|
|
|
if [ -x /etc/rc.d/rc.openldap ]; then
|
|
|
|
/etc/rc.d/rc.openldap stop
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Stop D-Bus:
|
|
|
|
if [ -x /etc/rc.d/rc.messagebus ]; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.messagebus stop
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
|
2011-04-25 15:37:00 +02:00
|
|
|
# Kill any processes (typically gam) that would otherwise prevent
|
|
|
|
# unmounting NFS volumes:
|
|
|
|
unset FUSER_DELAY
|
2016-06-30 22:26:57 +02:00
|
|
|
for dir in $(/bin/mount | grep 'type nfs ' | cut -d ' ' -f 3 ) ; do
|
2011-04-25 15:37:00 +02:00
|
|
|
echo "Killing processes holding NFS mount $dir open..."
|
|
|
|
# Background this to prevent fuser from also blocking shutdown:
|
2018-05-28 21:12:29 +02:00
|
|
|
/usr/bin/fuser -k -M -m $dir &
|
2011-04-25 15:37:00 +02:00
|
|
|
FUSER_DELAY=5
|
|
|
|
done
|
|
|
|
# If fuser was run, let it have some delay:
|
|
|
|
if [ ! -z "$FUSER_DELAY" ]; then
|
|
|
|
sleep $FUSER_DELAY
|
|
|
|
fi
|
|
|
|
|
2009-08-26 17:00:38 +02:00
|
|
|
# Unmount any NFS, SMB, or CIFS filesystems:
|
2016-06-30 22:26:57 +02:00
|
|
|
echo "Unmounting remote filesystems:"
|
|
|
|
/bin/umount -v -a -l -f -r -t nfs,smbfs,cifs | tr -d ' ' | grep successfully | sed "s/:successfullyunmounted/ has been successfully unmounted./g"
|
2009-08-26 17:00:38 +02:00
|
|
|
|
|
|
|
# Try to shut down pppd:
|
|
|
|
PS="$(ps ax)"
|
|
|
|
if echo "$PS" | /bin/grep -q -w pppd ; then
|
|
|
|
if [ -x /usr/sbin/ppp-off ]; then
|
|
|
|
/usr/sbin/ppp-off
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-09-26 03:10:42 +02:00
|
|
|
# Shut down YP services:
|
|
|
|
if [ -x /etc/rc.d/rc.yp ]; then
|
|
|
|
if grep -wq stop /etc/rc.d/rc.yp ; then
|
|
|
|
/etc/rc.d/rc.yp stop
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2009-08-26 17:00:38 +02:00
|
|
|
# Bring down the networking system, but first make sure that this
|
|
|
|
# isn't a diskless client with the / partition mounted via NFS:
|
|
|
|
if ! /bin/mount | /bin/grep -q 'on / type nfs' ; then
|
|
|
|
if [ -x /etc/rc.d/rc.inet1 ]; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.inet1 stop
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# In case dhcpcd might have been manually started on the command line,
|
|
|
|
# look for the .pid file, and shut dhcpcd down if it's found:
|
|
|
|
if /bin/ls /etc/dhcpc/*.pid 1> /dev/null 2> /dev/null ; then
|
|
|
|
/sbin/dhcpcd -k 1> /dev/null 2> /dev/null
|
|
|
|
# A little time for /etc/resolv.conf and/or other files to
|
|
|
|
# restore themselves.
|
|
|
|
sleep 2
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Shut down PCMCIA devices:
|
|
|
|
if [ -x /etc/rc.d/rc.pcmcia ]; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.pcmcia stop
|
2009-08-26 17:00:38 +02:00
|
|
|
# The cards might need a little extra time here to deactivate:
|
|
|
|
/bin/sleep 5
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Turn off process accounting:
|
|
|
|
if [ -x /sbin/accton -a -r /var/log/pacct ]; then
|
|
|
|
/sbin/accton off
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Terminate acpid before syslog:
|
|
|
|
if [ -x /etc/rc.d/rc.acpid -a -r /var/run/acpid.pid ]; then # quit
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.acpid stop
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
|
2012-09-26 03:10:42 +02:00
|
|
|
# Stop udev:
|
|
|
|
if [ -x /etc/rc.d/rc.udev ]; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.udev force-stop
|
2012-09-26 03:10:42 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Kill all remaining processes.
|
2016-06-30 22:26:57 +02:00
|
|
|
OMITPIDS="$(for p in $(pgrep mdmon); do echo -o $p; done)" # Don't kill mdmon
|
2012-09-26 03:10:42 +02:00
|
|
|
if [ ! "$1" = "fast" ]; then
|
|
|
|
echo "Sending all processes the SIGTERM signal."
|
2016-06-30 22:26:57 +02:00
|
|
|
/sbin/killall5 -15 $OMITPIDS
|
2009-08-26 17:00:38 +02:00
|
|
|
/bin/sleep 5
|
2012-09-26 03:10:42 +02:00
|
|
|
echo "Sending all processes the SIGKILL signal."
|
2016-06-30 22:26:57 +02:00
|
|
|
/sbin/killall5 -9 $OMITPIDS
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Try to turn off quota.
|
|
|
|
if /bin/grep -q quota /etc/fstab ; then
|
|
|
|
if [ -x /sbin/quotaoff ]; then
|
|
|
|
echo "Turning off filesystem quotas."
|
|
|
|
/sbin/quotaoff -a
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Carry a random seed between reboots.
|
|
|
|
echo "Saving random seed from /dev/urandom in /etc/random-seed."
|
2013-11-04 18:08:47 +01:00
|
|
|
# Use the pool size from /proc, or 4096 bits:
|
2009-08-26 17:00:38 +02:00
|
|
|
if [ -r /proc/sys/kernel/random/poolsize ]; then
|
2013-11-04 18:08:47 +01:00
|
|
|
/bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=$(expr $(cat /proc/sys/kernel/random/poolsize) / 8) 2> /dev/null
|
2009-08-26 17:00:38 +02:00
|
|
|
else
|
|
|
|
/bin/dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null
|
|
|
|
fi
|
|
|
|
/bin/chmod 600 /etc/random-seed
|
|
|
|
|
|
|
|
# Before unmounting file systems write a reboot or halt record to wtmp.
|
2016-06-30 22:26:57 +02:00
|
|
|
$shutdown_command -w
|
2009-08-26 17:00:38 +02:00
|
|
|
|
|
|
|
# Turn off swap:
|
|
|
|
echo "Turning off swap."
|
|
|
|
/sbin/swapoff -a
|
|
|
|
/bin/sync
|
|
|
|
|
2016-06-30 22:26:57 +02:00
|
|
|
# Stop cgmanager and cgproxy:
|
|
|
|
if [ -x /etc/rc.d/rc.cgmanager ]; then
|
2018-05-28 21:12:29 +02:00
|
|
|
/etc/rc.d/rc.cgmanager stop
|
2016-06-30 22:26:57 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Unmounting local file systems:"
|
|
|
|
/bin/umount -v -a -t no,proc,sysfs | tr -d ' ' | grep successfully | sed "s/:successfullyunmounted/ has been successfully unmounted./g" 2> /dev/null
|
2009-08-26 17:00:38 +02:00
|
|
|
|
2016-06-30 22:26:57 +02:00
|
|
|
echo "Remounting root filesystem read-only:"
|
2009-08-26 17:00:38 +02:00
|
|
|
/bin/mount -v -n -o remount,ro /
|
|
|
|
|
|
|
|
# This never hurts:
|
|
|
|
/bin/sync
|
|
|
|
|
|
|
|
# Close any volumes opened by cryptsetup:
|
2010-05-19 10:58:23 +02:00
|
|
|
if [ -f /etc/crypttab -a -x /sbin/cryptsetup ]; then
|
2009-08-26 17:00:38 +02:00
|
|
|
cat /etc/crypttab | grep -v "^#" | grep -v "^$" | while read line; do
|
|
|
|
# NOTE: we only support LUKS formatted volumes (except for swap)!
|
|
|
|
LUKS=$(echo $line | tr '\t' ' ' | tr -s ' ' | cut -f1 -d' ')
|
|
|
|
DEV=$(echo $line | tr '\t' ' ' | tr -s ' ' | cut -f2 -d' ')
|
|
|
|
OPTS=$(echo $line | tr '\t' ' ' | tr -s ' ' | cut -f4 -d' ')
|
2010-05-19 10:58:23 +02:00
|
|
|
if /sbin/cryptsetup isLuks $DEV 2>/dev/null ; then
|
2009-08-26 17:00:38 +02:00
|
|
|
echo "Locking LUKS crypt volume '${LUKS}':"
|
2010-05-19 10:58:23 +02:00
|
|
|
/sbin/cryptsetup luksClose ${LUKS}
|
2009-08-26 17:00:38 +02:00
|
|
|
elif echo $OPTS | grep -wq swap ; then
|
|
|
|
# If any of the volumes was used as encrypted swap,
|
|
|
|
# then run mkswap on the underlying device -
|
|
|
|
# in case other Linux installations on this computer should use it:
|
|
|
|
echo "Erasing encrypted swap '${LUKS}' and restoring normal swap on ${DEV}:"
|
2010-05-19 10:58:23 +02:00
|
|
|
/sbin/cryptsetup remove ${LUKS}
|
2009-08-26 17:00:38 +02:00
|
|
|
mkswap $DEV
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Deactivate LVM volume groups:
|
|
|
|
if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then
|
|
|
|
echo "Deactivating LVM volume groups:"
|
|
|
|
/sbin/vgchange -an --ignorelockingfailure
|
|
|
|
fi
|
|
|
|
|
|
|
|
# This never hurts again (especially since root-on-LVM always fails
|
|
|
|
# to deactivate the / logical volume... but at least it was
|
|
|
|
# remounted as read-only first)
|
|
|
|
/bin/sync
|
|
|
|
|
|
|
|
# sleep 3 fixes problems with some hard drives that don't
|
|
|
|
# otherwise finish syncing before reboot or poweroff
|
|
|
|
/bin/sleep 3
|
|
|
|
|
|
|
|
# This is to ensure all processes have completed on SMP machines:
|
|
|
|
wait
|
|
|
|
|
|
|
|
if [ -x /sbin/genpowerd ]; then
|
|
|
|
# See if this is a powerfail situation:
|
|
|
|
if /bin/egrep -q "FAIL|SCRAM" /etc/upsstatus 2> /dev/null ; then
|
|
|
|
# Signal UPS to shut off the inverter:
|
|
|
|
/sbin/genpowerd -k
|
|
|
|
if [ ! $? = 0 ]; then
|
|
|
|
echo
|
|
|
|
echo "There was an error signaling the UPS."
|
|
|
|
echo "Perhaps you need to edit /etc/genpowerd.conf to configure"
|
|
|
|
echo "the serial line and UPS type."
|
|
|
|
# Wasting 15 seconds of precious power:
|
|
|
|
/bin/sleep 15
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Now halt (poweroff with APM or ACPI enabled kernels) or reboot.
|
2016-06-30 22:26:57 +02:00
|
|
|
if [ "$shutdown_command" = "reboot" ]; then
|
2009-08-26 17:00:38 +02:00
|
|
|
echo "Rebooting."
|
|
|
|
/sbin/reboot
|
|
|
|
else
|
|
|
|
/sbin/poweroff
|
|
|
|
fi
|
|
|
|
|