2000-03-10 16:17:25 +03:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2012-06-25 11:22:45 +04:00
|
|
|
# $NetBSD: rc.shutdown,v 1.9 2012/06/25 07:22:45 jnemeth Exp $
|
2000-03-10 16:17:25 +03:00
|
|
|
#
|
2000-12-15 03:00:09 +03:00
|
|
|
# rc.shutdown --
|
2000-03-10 16:17:25 +03:00
|
|
|
# Run the scripts in /etc/rc.d with reverse rcorder.
|
1998-10-29 23:24:56 +03:00
|
|
|
|
2000-12-15 03:00:09 +03:00
|
|
|
# System shutdown script run by shutdown(8) at system shutdown time.
|
|
|
|
# Note that halt(8) and reboot(8) do NOT invoke this script.
|
|
|
|
|
1998-10-29 23:24:56 +03:00
|
|
|
export HOME=/
|
2000-03-10 16:17:25 +03:00
|
|
|
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
1998-10-29 23:24:56 +03:00
|
|
|
|
2000-03-10 16:17:25 +03:00
|
|
|
. /etc/rc.subr
|
|
|
|
. /etc/rc.conf
|
1998-10-29 23:24:56 +03:00
|
|
|
|
2000-03-10 16:17:25 +03:00
|
|
|
if ! checkyesno do_rcshutdown; then
|
1998-10-29 23:24:56 +03:00
|
|
|
echo "Skipping shutdown hooks."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2000-03-10 16:17:25 +03:00
|
|
|
stty status '^T'
|
1998-10-29 23:24:56 +03:00
|
|
|
|
2001-06-16 08:09:19 +04:00
|
|
|
# Set shell to ignore SIGINT, but not children;
|
|
|
|
# shell catches SIGQUIT and returns to single user.
|
2000-03-10 16:17:25 +03:00
|
|
|
#
|
2001-06-16 08:09:19 +04:00
|
|
|
trap : INT
|
|
|
|
trap "echo 'Shutdown interrupted.'; exit 1" QUIT
|
2000-03-10 16:17:25 +03:00
|
|
|
|
2001-06-16 08:09:19 +04:00
|
|
|
# If requested, start a watchdog timer in the background which
|
|
|
|
# will terminate rc.shutdown if rc.shutdown doesn't complete
|
|
|
|
# within the specified time.
|
|
|
|
#
|
|
|
|
_rcshutdown_watchdog=
|
|
|
|
if [ -n "$rcshutdown_timeout" ]; then
|
|
|
|
sleep $rcshutdown_timeout && (
|
|
|
|
_msg="$rcshutdown_timeout second watchdog timeout expired. Shutdown terminated."
|
|
|
|
logger -t rc.shutdown "$_msg"
|
|
|
|
echo "$_msg"
|
|
|
|
date
|
|
|
|
kill -KILL $$ >/dev/null 2>&1
|
|
|
|
) &
|
|
|
|
_rcshutdown_watchdog=$!
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2012-06-25 11:22:45 +04:00
|
|
|
# Determine the shutdown order of the rc.d scripts,
|
2001-06-16 08:09:19 +04:00
|
|
|
# and perform the operation
|
|
|
|
#
|
2012-06-25 11:22:45 +04:00
|
|
|
scripts=$(for rcd in ${rc_directories:-/etc/rc.d}; do
|
|
|
|
test -d ${rcd} && echo ${rcd}/*; done)
|
|
|
|
files=$(rcorder -k shutdown ${rcshutdown_rcorder_flags} ${scripts})
|
2000-03-10 16:17:25 +03:00
|
|
|
|
2002-05-19 05:01:32 +04:00
|
|
|
for _rc_elem in $(reverse_list $files); do
|
2001-11-19 06:19:28 +03:00
|
|
|
run_rc_script $_rc_elem stop
|
2000-03-10 16:17:25 +03:00
|
|
|
done
|
1998-10-29 23:24:56 +03:00
|
|
|
|
2001-06-16 08:09:19 +04:00
|
|
|
|
|
|
|
# Terminate the background watchdog timer (if it is running)
|
|
|
|
#
|
|
|
|
if [ -n "$_rcshutdown_watchdog" ]; then
|
|
|
|
kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1
|
|
|
|
fi
|
|
|
|
|
2000-03-10 16:17:25 +03:00
|
|
|
date
|
1998-10-29 23:24:56 +03:00
|
|
|
exit 0
|