rc.shutdown revision 1.6
11.3Slukem#!/bin/sh 21.3Slukem# 31.6Slukem# $NetBSD: rc.shutdown,v 1.6 2001/06/16 04:09:19 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.6Slukemnfiles= 521.3Slukemfor i in $files; do # reverse order of files 531.3Slukem nfiles="$i $nfiles" 541.3Slukemdone 551.3Slukemfiles=$nfiles 561.3Slukem 571.3Slukemfor i in $files; do 581.3Slukem run_rc_script $i stop 591.3Slukemdone 601.6Slukem 611.6Slukem 621.6Slukem# Terminate the background watchdog timer (if it is running) 631.6Slukem# 641.6Slukemif [ -n "$_rcshutdown_watchdog" ]; then 651.6Slukem kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1 661.6Slukemfi 671.1Sbad 681.3Slukemdate 691.1Sbadexit 0 70