etc/services - sync with NetBSD-8
[minix.git] / etc / rc.shutdown
blob6026863031c1663f6cc2d9106818c2ad343cdb19
1 #!/bin/sh
3 # $NetBSD: rc.shutdown,v 1.9 2012/06/25 07:22:45 jnemeth Exp $
5 # rc.shutdown --
6 # Run the scripts in /etc/rc.d with reverse rcorder.
8 # System shutdown script run by shutdown(8) at system shutdown time.
9 # Note that halt(8) and reboot(8) do NOT invoke this script.
11 export HOME=/
12 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
14 . /etc/rc.subr
15 . /etc/rc.conf
17 if ! checkyesno do_rcshutdown; then
18 echo "Skipping shutdown hooks."
19 exit 0
22 stty status '^T'
24 # Set shell to ignore SIGINT, but not children;
25 # shell catches SIGQUIT and returns to single user.
27 trap : INT
28 trap "echo 'Shutdown interrupted.'; exit 1" QUIT
30 # If requested, start a watchdog timer in the background which
31 # will terminate rc.shutdown if rc.shutdown doesn't complete
32 # within the specified time.
34 _rcshutdown_watchdog=
35 if [ -n "$rcshutdown_timeout" ]; then
36 sleep $rcshutdown_timeout && (
37 _msg="$rcshutdown_timeout second watchdog timeout expired. Shutdown terminated."
38 logger -t rc.shutdown "$_msg"
39 echo "$_msg"
40 date
41 kill -KILL $$ >/dev/null 2>&1
42 ) &
43 _rcshutdown_watchdog=$!
47 # Determine the shutdown order of the rc.d scripts,
48 # and perform the operation
50 scripts=$(for rcd in ${rc_directories:-/etc/rc.d}; do
51 test -d ${rcd} && echo ${rcd}/*; done)
52 files=$(rcorder -k shutdown ${rcshutdown_rcorder_flags} ${scripts})
54 for _rc_elem in $(reverse_list $files); do
55 run_rc_script $_rc_elem stop
56 done
59 # Terminate the background watchdog timer (if it is running)
61 if [ -n "$_rcshutdown_watchdog" ]; then
62 kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1
65 date
66 exit 0