2009-10-08 03:40:19 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# /etc/rc.shutdown
|
|
|
|
#
|
|
|
|
|
|
|
|
. /etc/rc.conf
|
|
|
|
. /etc/rc.d/functions
|
|
|
|
|
2010-04-05 01:16:29 +00:00
|
|
|
run_hook shutdown_start
|
|
|
|
|
2009-10-08 03:40:19 +00:00
|
|
|
# avoid staircase effect
|
|
|
|
/bin/stty onlcr
|
|
|
|
|
|
|
|
echo " "
|
2010-07-28 19:27:38 +00:00
|
|
|
printhl "Initiating Shutdown..."
|
2009-10-08 03:40:19 +00:00
|
|
|
echo " "
|
|
|
|
|
2011-05-26 04:45:00 +00:00
|
|
|
[[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown
|
2009-10-08 03:40:19 +00:00
|
|
|
|
2011-05-26 04:45:00 +00:00
|
|
|
kill_everything shutdown
|
2010-04-05 01:16:29 +00:00
|
|
|
|
2009-10-08 03:40:19 +00:00
|
|
|
stat_busy "Saving Random Seed"
|
|
|
|
RANDOM_SEED=/var/lib/misc/random-seed
|
2011-05-26 04:45:00 +00:00
|
|
|
[[ -d ${RANDOM_SEED%/*} ]] || mkdir -p ${RANDOM_SEED%/*}
|
2009-10-08 03:40:19 +00:00
|
|
|
: > $RANDOM_SEED
|
|
|
|
/bin/chmod 0600 $RANDOM_SEED
|
|
|
|
POOL_FILE=/proc/sys/kernel/random/poolsize
|
2011-05-26 04:45:00 +00:00
|
|
|
if [[ -r $POOL_FILE ]]; then
|
|
|
|
read POOL_SIZE <$POOL_FILE
|
2009-10-08 03:40:19 +00:00
|
|
|
else
|
|
|
|
POOL_SIZE=512
|
|
|
|
fi
|
|
|
|
/bin/dd if=/dev/urandom of=$RANDOM_SEED count=1 bs=$POOL_SIZE &> /dev/null
|
|
|
|
stat_done
|
|
|
|
|
2011-05-26 04:45:00 +00:00
|
|
|
if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then
|
2009-10-08 03:40:19 +00:00
|
|
|
/bin/rm -f /etc/localtime
|
2011-05-26 04:45:00 +00:00
|
|
|
status "Saving Time Zone" \
|
|
|
|
/bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
|
2009-10-08 03:40:19 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Write to wtmp file before unmounting
|
|
|
|
/sbin/halt -w
|
|
|
|
|
2011-05-26 04:45:00 +00:00
|
|
|
status "Deactivating Swap" /sbin/swapoff -a
|
|
|
|
|
|
|
|
# stop monitoring of lvm2 groups before unmounting filesystems
|
|
|
|
if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then
|
|
|
|
status "Deactivating monitoring of LVM2 groups" \
|
|
|
|
/sbin/vgchange --monitor n >/dev/null 2>&1
|
|
|
|
fi
|
2009-10-08 03:40:19 +00:00
|
|
|
|
|
|
|
stat_busy "Unmounting Filesystems"
|
2011-05-26 04:45:00 +00:00
|
|
|
if /bin/grep -q devtmpfs /proc/filesystems &>/dev/null; then
|
|
|
|
/bin/umount -a -r -t nosysfs,noproc,nodevtmpfs,nodevpts -O no_netdev
|
|
|
|
else
|
|
|
|
# if we don't have devtmpfs support, /dev is mounted as tmpfs, so don't unmount it
|
|
|
|
/bin/umount -a -r -t notmpfs,nosysfs,noproc,nodevpts -O no_netdev
|
|
|
|
fi
|
2009-10-08 03:40:19 +00:00
|
|
|
stat_done
|
|
|
|
|
|
|
|
# Kill non-root encrypted partition mappings
|
2011-05-26 04:45:00 +00:00
|
|
|
if [[ -f /etc/crypttab && -n $CS ]] && /bin/grep -q ^[^#] /etc/crypttab; then
|
2009-10-08 03:40:19 +00:00
|
|
|
stat_busy "Deactivating encrypted volumes:"
|
2011-05-26 04:45:00 +00:00
|
|
|
# Maybe someone has LVM on an encrypted block device
|
|
|
|
# executing an extra vgchange is errorless
|
|
|
|
if [[ $USELVM =~ yes|YES ]]; then
|
|
|
|
/sbin/vgchange --sysinit -a n >/dev/null 2>&1
|
2010-07-28 19:27:38 +00:00
|
|
|
fi
|
2011-05-26 04:45:00 +00:00
|
|
|
do_lock() {
|
|
|
|
stat_append "${1}.."
|
|
|
|
if $CS remove "$1" >/dev/null 2>&1; then
|
|
|
|
stat_append "ok "
|
|
|
|
else
|
|
|
|
stat_append "failed "
|
2009-10-08 03:40:19 +00:00
|
|
|
fi
|
|
|
|
}
|
2011-05-26 04:45:00 +00:00
|
|
|
read_crypttab do_lock
|
2009-10-08 03:40:19 +00:00
|
|
|
stat_done
|
|
|
|
fi
|
|
|
|
|
2011-05-26 04:45:00 +00:00
|
|
|
if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then
|
|
|
|
status "Deactivating LVM2 groups" /sbin/vgchange --sysinit -a n >/dev/null 2>&1
|
2009-10-08 03:40:19 +00:00
|
|
|
fi
|
|
|
|
|
2011-05-26 04:45:00 +00:00
|
|
|
status "Remounting Root Filesystem Read-only" /bin/mount -n -o remount,ro /
|
2009-10-08 03:40:19 +00:00
|
|
|
|
2010-04-05 01:16:29 +00:00
|
|
|
run_hook shutdown_poweroff
|
|
|
|
|
2011-05-26 04:45:00 +00:00
|
|
|
# PlugApps: Turn LEDs off
|
2011-01-02 07:20:35 +00:00
|
|
|
|
2011-03-05 20:14:44 +00:00
|
|
|
/usr/bin/find /sys/ -path *led* -name *trigger* -exec sh -c '/bin/echo none > {}' \;
|
2010-11-16 01:06:19 +00:00
|
|
|
|
2009-10-08 03:40:19 +00:00
|
|
|
# Power off or reboot
|
2011-05-26 04:45:00 +00:00
|
|
|
printsep
|
|
|
|
if [[ $RUNLEVEL = 0 ]]; then
|
2009-10-08 03:40:19 +00:00
|
|
|
printhl "${C_H2}POWER OFF"
|
|
|
|
/sbin/poweroff -d -f -h -i
|
|
|
|
else
|
|
|
|
printhl "${C_H2}REBOOTING"
|
|
|
|
# if kexec is installed and a kernel is loaded, use it
|
2011-05-26 04:45:00 +00:00
|
|
|
[[ -x /sbin/kexec ]] && /sbin/kexec -e > /dev/null 2>&1
|
2009-10-08 03:40:19 +00:00
|
|
|
/sbin/reboot -d -f -i
|
|
|
|
fi
|
|
|
|
|
|
|
|
# End of file
|
2011-01-02 07:20:35 +00:00
|
|
|
# vim: set ts=2 sw=2 noet:
|