#! /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 # Modified by: Patrick J. Volkerding, # Modified by: Jean-Philippe Guillemin, # # Set the path. PATH=/sbin:/etc:/bin:/usr/bin . /etc/shell-colors #### Set the splash screen to verbose mode #### [[ -x /sbin/splash && -e /proc/splash ]] && echo "verbose" > /proc/splash & # Set linefeed mode to avoid staircase effect. stty onlcr echo -e "${BOLDMAGENTA}Running shutdown script $0${COLOR_RESET}" # Find out how we were called. case "$0" in *0) command="halt" ;; *6) command=reboot ;; *) echo "$0: call me as \"rc.0\" or \"rc.6\" please!" exit 1 ;; esac # Save the system time to the hardware clock using hwclock --systohc. if [ -x /sbin/hwclock ]; then # Check for a broken motherboard RTC clock (where ioports for rtc are # unknown) to prevent hwclock causing a hang: if ! grep -q -w rtc /proc/ioports ; then CLOCK_OPT="--directisa" fi if grep -q "^UTC" /etc/hardwareclock 2> /dev/null ; then echo "Saving system time to the hardware clock (UTC)" /sbin/hwclock $CLOCK_OPT --utc --systohc else echo "Saving system time to the hardware clock (localtime)" /sbin/hwclock $CLOCK_OPT --localtime --systohc fi fi # Save the sound settings if [ -x /usr/sbin/alsactl ]; then echo "Saving the Sound Settings" /usr/sbin/alsactl store fi # Update the shared library links if [ -x /sbin/ldconfig ]; then echo -e "${BOLDWHITE}Updating shared library links${COLOR_RESET}" /sbin/ldconfig fi # Font caching du /usr/share/fonts > /tmp/fonts.list touch /etc/fonts.list if ! (cmp -s /etc/fonts.list /tmp/fonts.list) ; then for fontdir in cyrillic OTF TTF 100dpi 75dpi misc Type1 Speedo util encodings; do [ -d /usr/share/fonts/${fontdir} ] && \ ( [ -x /usr/bin/mkfontscale ] && ( chroot . /usr/bin/mkfontscale /usr/share/fonts/${fontdir} > /dev/null 2>&1 ) [ -x /usr/bin/mkfontdir ] && ( chroot . /usr/bin/mkfontdir /usr/share/fonts/${fontdir} > /dev/null 2>&1 ) ) done du /usr/share/fonts > /etc/fonts.list fi # Update the X font indexes: echo "Updating X font indexes: /usr/bin/fc-cache..." if [ -d /var/cache/fontconfig ]; then rm -rf /var/cache/fontconfig mkdir -p /var/cache/fontconfig fi [ -x /usr/bin/fc-cache ] && /usr/bin/fc-cache -rf > /dev/null 2>&1 # Update any existing icon cache files: if find /usr/share/icons 2> /dev/null | grep -q icon-theme.cache ; then for theme_dir in /usr/share/icons/* ; do if [ -r ${theme_dir}/icon-theme.cache ]; then echo "Updating icon-theme.cache in ${theme_dir}..." /usr/bin/gtk-update-icon-cache -t -f ${theme_dir} 1> /dev/null 2> /dev/null fi done if [ -r /usr/share/icons/icon-theme.cache ]; then echo "Updating icon-theme.cache in /usr/share/icons..." /usr/bin/gtk-update-icon-cache -t -f /usr/share/icons 1> /dev/null 2> /dev/null fi fi # Update mime database: if [ -x /usr/bin/update-mime-database -a -d /usr/share/mime ]; then echo "Updating MIME database: /usr/bin/update-mime-database /usr/share/mime..." /usr/bin/update-mime-database /usr/share/mime 1> /dev/null 2> /dev/null & fi # Unmount any NFS, SMB, or CIFS filesystems: echo "Unmounting remote filesystems" umount -a -r -t nfs,smbfs,cifs # Bring down the networking system, but first make sure that this # isn't a diskless client with the / partition mounted via NFS: if ! mount | grep -q 'on / type nfs' ; then if [ -x /etc/rc.d/rc.inet1 ]; then echo -e "${BOLDCYAN}Stopping the network${COLOR_RESET}" . /etc/rc.d/rc.inet1 stop 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 /var/run/dhcpcd*.pid 1>/dev/null 2>/dev/null ; then /sbin/dhcpcd -k 1> /dev/null 2>/dev/null fi # Turn off process accounting: if [ -x /sbin/accton -a -r /var/log/pacct ]; then echo "Turning off process accounting" /sbin/accton fi # Kill all processes. # INIT is supposed to handle this entirely now, but this didn't always # work correctly without this second pass at killing off the processes. # Since INIT already notified the user that processes were being killed, # we'll avoid echoing this info this time around. if [ "$1" != "fast" ]; then # shutdown did not already kill all processes killall5 -15 sleep 5 killall5 -9 fi # Try to turn off quota. if 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." # Use the pool size from /proc, or 512 bytes: if [ -r /proc/sys/kernel/random/poolsize ]; then dd if=/dev/urandom of=/etc/random-seed count=1 bs=$(cat /proc/sys/kernel/random/poolsize) 2> /dev/null else dd if=/dev/urandom of=/etc/random-seed count=1 bs=512 2> /dev/null fi chmod 600 /etc/random-seed # Before unmounting file systems write a reboot or halt record to wtmp. $command -w # Remove stale locks and junk files rm -f /var/lock/* /var/spool/uucp/LCK..* /tmp/.X*lock /tmp/core /core 2> /dev/null if [ -d /var/lock/subsys ]; then rm -f /var/lock/subsys/* fi # Remove stale hunt sockets if [ -r /tmp/hunt -o -r /tmp/hunt.stats ]; then echo "Removing your stale hunt sockets from /tmp." rm -f /tmp/hunt* fi # Turn off swap, then unmount local file systems. echo "Turning off swap" sync swapoff -a echo "Unmounting local file systems" umount -a -r -t nonfs,noproc,nosysfs echo "Remounting root filesystem read-only." mount -n -o remount,ro / # This never hurts: sync # sleep 1 fixes problems with some hard drives that don't # otherwise finish syncing before reboot or poweroff sleep 1 # This is to ensure all processes have completed on SMP machines: wait # Now halt (poweroff with APM or ACPI enabled kernels) or reboot. if [ "$command" = "reboot" ]; then echo -e "${BOLDMAGENTA}Rebooting...${COLOR_RESET}" reboot else echo -e "${BOLDMAGENTA}Shutdown...${COLOR_RESET}" poweroff fi