rc.shutdown revision 1.9
11.3Slukem#!/bin/sh 21.3Slukem# 31.9Sjnemeth# $NetBSD: rc.shutdown,v 1.9 2012/06/25 07:22:45 jnemeth 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.9Sjnemeth# Determine the shutdown order of the rc.d scripts, 481.6Slukem# and perform the operation 491.6Slukem# 501.9Sjnemethscripts=$(for rcd in ${rc_directories:-/etc/rc.d}; do 511.9Sjnemeth test -d ${rcd} && echo ${rcd}/*; done) 521.9Sjnemethfiles=$(rcorder -k shutdown ${rcshutdown_rcorder_flags} ${scripts}) 531.3Slukem 541.8Slukemfor _rc_elem in $(reverse_list $files); do 551.7Slukem run_rc_script $_rc_elem stop 561.3Slukemdone 571.6Slukem 581.6Slukem 591.6Slukem# Terminate the background watchdog timer (if it is running) 601.6Slukem# 611.6Slukemif [ -n "$_rcshutdown_watchdog" ]; then 621.6Slukem kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1 631.6Slukemfi 641.1Sbad 651.3Slukemdate 661.1Sbadexit 0 67