Home | History | Annotate | Line # | Download | only in etc
rc.shutdown revision 1.6
      1  1.3  lukem #!/bin/sh
      2  1.3  lukem #
      3  1.6  lukem # $NetBSD: rc.shutdown,v 1.6 2001/06/16 04:09:19 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.4  lukem files=`rcorder -k shutdown /etc/rc.d/*`
     51  1.6  lukem nfiles=
     52  1.3  lukem for i in $files; do			# reverse order of files
     53  1.3  lukem 	nfiles="$i $nfiles"
     54  1.3  lukem done
     55  1.3  lukem files=$nfiles
     56  1.3  lukem 
     57  1.3  lukem for i in $files; do
     58  1.3  lukem 	run_rc_script $i stop
     59  1.3  lukem done
     60  1.6  lukem 
     61  1.6  lukem 
     62  1.6  lukem #	Terminate the background watchdog timer (if it is running)
     63  1.6  lukem #
     64  1.6  lukem if [ -n "$_rcshutdown_watchdog" ]; then
     65  1.6  lukem 	kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1
     66  1.6  lukem fi
     67  1.1    bad 
     68  1.3  lukem date
     69  1.1    bad exit 0
     70