rc.shutdown revision 1.7
11.3Slukem#!/bin/sh 21.3Slukem# 31.7Slukem# $NetBSD: rc.shutdown,v 1.7 2001/11/19 03:19:28 lukem Exp $ 41.3Slukem# 51.5Slukem# rc.shutdown -- 61.3Slukem# Run the scripts in /etc/rc.d with reverse rcorder. 71.5Slukem 81.5Slukem# System shutdown script run by shutdown(8) at system shutdown time. 91.5Slukem# Note that halt(8) and reboot(8) do NOT invoke this script. 101.1Sbad 111.1Sbadexport HOME=/ 121.3Slukemexport PATH=/sbin:/bin:/usr/sbin:/usr/bin 131.1Sbad 141.3Slukem. /etc/rc.subr 151.3Slukem. /etc/rc.conf 161.1Sbad 171.3Slukemif ! checkyesno do_rcshutdown; then 181.1Sbad echo "Skipping shutdown hooks." 191.1Sbad exit 0 201.1Sbadfi 211.1Sbad 221.3Slukemstty status '^T' 231.1Sbad 241.6Slukem# Set shell to ignore SIGINT, but not children; 251.6Slukem# shell catches SIGQUIT and returns to single user. 261.3Slukem# 271.6Slukemtrap : INT 281.6Slukemtrap "echo 'Shutdown interrupted.'; exit 1" QUIT 291.3Slukem 301.6Slukem# If requested, start a watchdog timer in the background which 311.6Slukem# will terminate rc.shutdown if rc.shutdown doesn't complete 321.6Slukem# within the specified time. 331.6Slukem# 341.6Slukem_rcshutdown_watchdog= 351.6Slukemif [ -n "$rcshutdown_timeout" ]; then 361.6Slukem sleep $rcshutdown_timeout && ( 371.6Slukem _msg="$rcshutdown_timeout second watchdog timeout expired. Shutdown terminated." 381.6Slukem logger -t rc.shutdown "$_msg" 391.6Slukem echo "$_msg" 401.6Slukem date 411.6Slukem kill -KILL $$ >/dev/null 2>&1 421.6Slukem ) & 431.6Slukem _rcshutdown_watchdog=$! 441.6Slukemfi 451.6Slukem 461.6Slukem 471.6Slukem# Determine the shutdown order of the /etc/rc.d scripts, 481.6Slukem# and perform the operation 491.6Slukem# 501.4Slukemfiles=`rcorder -k shutdown /etc/rc.d/*` 511.3Slukem 521.7Slukemfor _rc_elem in `reverse_list $files`; do 531.7Slukem run_rc_script $_rc_elem stop 541.3Slukemdone 551.6Slukem 561.6Slukem 571.6Slukem# Terminate the background watchdog timer (if it is running) 581.6Slukem# 591.6Slukemif [ -n "$_rcshutdown_watchdog" ]; then 601.6Slukem kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1 611.6Slukemfi 621.1Sbad 631.3Slukemdate 641.1Sbadexit 0 65