1 #!/bin/sh 2 # 3 # $NetBSD: rc.shutdown,v 1.6 2001/06/16 04:09:19 lukem Exp $ 4 # 5 # rc.shutdown -- 6 # Run the scripts in /etc/rc.d with reverse rcorder. 7 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. 10 11 export HOME=/ 12 export PATH=/sbin:/bin:/usr/sbin:/usr/bin 13 14 . /etc/rc.subr 15 . /etc/rc.conf 16 17 if ! checkyesno do_rcshutdown; then 18 echo "Skipping shutdown hooks." 19 exit 0 20 fi 21 22 stty status '^T' 23 24 # Set shell to ignore SIGINT, but not children; 25 # shell catches SIGQUIT and returns to single user. 26 # 27 trap : INT 28 trap "echo 'Shutdown interrupted.'; exit 1" QUIT 29 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. 33 # 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=$! 44 fi 45 46 47 # Determine the shutdown order of the /etc/rc.d scripts, 48 # and perform the operation 49 # 50 files=`rcorder -k shutdown /etc/rc.d/*` 51 nfiles= 52 for i in $files; do # reverse order of files 53 nfiles="$i $nfiles" 54 done 55 files=$nfiles 56 57 for i in $files; do 58 run_rc_script $i stop 59 done 60 61 62 # Terminate the background watchdog timer (if it is running) 63 # 64 if [ -n "$_rcshutdown_watchdog" ]; then 65 kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1 66 fi 67 68 date 69 exit 0 70