#!/bin/sh # # hdw - linux /etc/init.d/down (copied from ROCK Linux) # # shutdown and reboot script. # exec 2>&1 export PATH=/bin:/sbin:/usr/bin:/usr/sbin case "$1" in *halt) command=halt ;; *reboot) command=reboot ;; *) echo "never call this script directly !" ; exit 1 ;; esac touch /var/log/init.msg /var/log/boot.msg mv /var/log/init.msg /var/log/init.old mv /var/log/boot.msg /var/log/boot.old echo "** shutting down hdw-linux **" . /etc/conf/bootdown [ -f /fastdown ] && FASTDOWN=1 [ $FASTDOWN = 1 ] && echo "fast shutdown mode enabled." echo "writing a wtmp record ..." $command -w echo "saving kernel random seed ..." dd if=/dev/urandom of=/var/state/random-seed count=1 2> /dev/null if [ $FASTDOWN = 1 ] then echo "sending all processes a SIGTERM (15) ..." killall5 -15 ; sleep 3 echo "sending all processes a SIGKILL (9) ..." killall5 -9 ; sleep 2 else echo "sending all processes a SIGTERM (15) ..." killall5 -15 ; sleep 5 echo "sending all processes a 2nd SIGTERM (15) ..." killall5 -15 ; sleep 3 echo "sending all processes a SIGKILL (9) ..." killall5 -9 ; sleep 3 echo "sending all processes a 2nd SIGKILL (9) ..." killall5 -9 ; sleep 3 fi echo "turning off swap ..." swapoff -a ; sync ; sleep 1 if [ $FASTDOWN = 1 ] then echo "unmounting file systems ..." umount -vnra -t noproc,devfs,shm mount -vn -o remount,ro / sleep 1 ; sync ; sleep 1 else echo "remounting sync/ro and umount filesystems ..." grep -v '^none ' /etc/mtab /proc/mounts | grep -v ' / ' | \ cut -f1,2 -d' ' | sort -u -k2 -t' ' | sort -r -k2 -t' ' | \ while read dev fs ; do echo -n "$dev on $fs: sync" ; mount -o remount,sync $fs echo -n " ro" ; mount -o remount,ro $fs echo " umount" ; umount $fs done echo "shutting down udev ..." /etc/init.d/udev stop umount /dev/pts ; rm -rf /dev/pts umount /dev/shm ; rm -rf /dev/shm umount /dev echo "unmounting remaining file systems ..." sync ; sleep 1 ; sync grep -E -v '^none (/|[a-z]+:) ' /proc/mounts > /etc/mtab umount -vnra -t noproc,devfs,shm mount -vn -o remount,sync / mount -vn -o remount,ro / sleep 1 ; sync ; sleep 1 fi echo "going to $command the system ..." exec $command -d -f -i -p