rc.shutdown revision 131135
127837Sdavidn#!/bin/sh 266830Sobrien# 366830Sobrien# Copyright (c) 1997 Ollivier Robert 466830Sobrien# All rights reserved. 566830Sobrien# 666830Sobrien# Redistribution and use in source and binary forms, with or without 766830Sobrien# modification, are permitted provided that the following conditions 866830Sobrien# are met: 966830Sobrien# 1. Redistributions of source code must retain the above copyright 1066830Sobrien# notice, this list of conditions and the following disclaimer. 1166830Sobrien# 2. Redistributions in binary form must reproduce the above copyright 1266830Sobrien# notice, this list of conditions and the following disclaimer in the 1366830Sobrien# documentation and/or other materials provided with the distribution. 1466830Sobrien# 1566830Sobrien# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1666830Sobrien# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1766830Sobrien# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1866830Sobrien# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1966830Sobrien# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2066830Sobrien# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2166830Sobrien# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2266830Sobrien# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2366830Sobrien# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2466830Sobrien# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2566830Sobrien# SUCH DAMAGE. 2666830Sobrien# 2750472Speter# $FreeBSD: head/etc/rc.shutdown 131135 2004-06-26 09:27:30Z mtm $ 2866830Sobrien# 2927837Sdavidn 3051231Ssheldonh# Site-specific closing actions for daemons run by init on shutdown, 3127837Sdavidn# or before going single-user from multi-user. 3227837Sdavidn# Output and errors are directed to console by init, and the 3327837Sdavidn# console is the controlling terminal. 3427837Sdavidn 3527837Sdavidnstty status '^T' 3627837Sdavidn 3727837Sdavidn# Set shell to ignore SIGINT (2), but not children; 3827837Sdavidn# shell catches SIGQUIT (3) and returns to single user after fsck. 3927837Sdavidntrap : 2 4027837Sdavidntrap : 3 # shouldn't be needed 4127837Sdavidn 4251231SsheldonhHOME=/ 4327837SdavidnPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 4451231Ssheldonhexport HOME PATH 4527837Sdavidn 46117324Smtm. /etc/rc.subr 4762640Stg 48117324Smtmload_rc_config 'XXX' 4998189Sgordon 5096830Sgordon# reverse_list list 5196830Sgordon# print the list in reverse order 5296830Sgordon# 5396830Sgordonreverse_list() 5496830Sgordon{ 5596830Sgordon _revlist= 5696830Sgordon for _revfile in $*; do 5796830Sgordon _revlist="$_revfile${script_name_sep}$_revlist" 5896830Sgordon done 5996830Sgordon echo $_revlist 6096830Sgordon} 6196830Sgordon 62117324Smtm# If requested, start a watchdog timer in the background which 63117324Smtm# will terminate rc.shutdown if rc.shutdown doesn't complete 64117324Smtm# within the specified time. 6563307Smarkm# 66117324Smtm_rcshutdown_watchdog= 67117324Smtmif [ -n "$rcshutdown_timeout" ]; then 68117324Smtm debug "Initiating watchdog timer." 69130151Sschweikh sleep $rcshutdown_timeout && ( 70117324Smtm _msg="$rcshutdown_timeout second watchdog" \ 71117324Smtm " timeout expired. Shutdown terminated." 72117324Smtm logger -t rc.shutdown "$_msg" 73117324Smtm echo "$_msg" 74117324Smtm date 75117324Smtm kill -KILL $$ >/dev/null 2>&1 76117324Smtm ) & 77117324Smtm _rcshutdown_watchdog=$! 78117324Smtmfi 7963307Smarkm 80117324Smtm# Determine the shutdown order of the /etc/rc.d scripts, 81117324Smtm# and perform the operation 82117324Smtm# XXX - rcorder(8) with multiple -k switches works as a logical OR, 83117324Smtm# so, we can't do this: rcorder -k shutdown -k FreeBSD. 84117324Smtm# 85117324Smtmfiles=`eval grep -l \'^# KEYWORD:.*FreeBSD\' \`rcorder -k shutdown /etc/rc.d/* 2>/dev/null\`` 8653550Sdillon 87117324Smtmfor _rc_elem in `reverse_list $files`; do 88131135Smtm debug "run_rc_script $_rc_elem faststop" 89131135Smtm run_rc_script $_rc_elem faststop 90117324Smtmdone 9127837Sdavidn 92117324Smtm# Terminate the background watchdog timer (if it is running) 93117324Smtm# 94117324Smtmif [ -n "$_rcshutdown_watchdog" ]; then 95117324Smtm kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1 96117324Smtmfi 9727837Sdavidn 9886856Sdarrenr# Insert other shutdown procedures here 9985219Sdarrenr 10086856Sdarrenr 10127837Sdavidnecho '.' 10227837Sdavidnexit 0 103