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