1*0696600cSBjoern A. Zeeb#!/bin/sh 2*0696600cSBjoern A. Zeeb# 3*0696600cSBjoern A. Zeeb# Copyright (c) 1997 Ollivier Robert 4*0696600cSBjoern A. Zeeb# All rights reserved. 5*0696600cSBjoern A. Zeeb# 6*0696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without 7*0696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions 8*0696600cSBjoern A. Zeeb# are met: 9*0696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright 10*0696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer. 11*0696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright 12*0696600cSBjoern A. Zeeb# notice, this list of conditions and the following disclaimer in the 13*0696600cSBjoern A. Zeeb# documentation and/or other materials provided with the distribution. 14*0696600cSBjoern A. Zeeb# 15*0696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*0696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*0696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*0696600cSBjoern A. Zeeb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*0696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*0696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*0696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*0696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*0696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*0696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*0696600cSBjoern A. Zeeb# SUCH DAMAGE. 26*0696600cSBjoern A. Zeeb# 27*0696600cSBjoern A. Zeeb# $FreeBSD$ 28*0696600cSBjoern A. Zeeb# 29*0696600cSBjoern A. Zeeb 30*0696600cSBjoern A. Zeeb# Site-specific closing actions for daemons run by init on shutdown, 31*0696600cSBjoern A. Zeeb# or before going single-user from multi-user. 32*0696600cSBjoern A. Zeeb# Output and errors are directed to console by init, and the 33*0696600cSBjoern A. Zeeb# console is the controlling terminal. 34*0696600cSBjoern A. Zeeb 35*0696600cSBjoern A. Zeebstty status '^T' 2> /dev/null 36*0696600cSBjoern A. Zeeb 37*0696600cSBjoern A. Zeeb# Set shell to ignore SIGINT (2), but not children; 38*0696600cSBjoern A. Zeeb# shell catches SIGQUIT (3) and returns to single user after fsck. 39*0696600cSBjoern A. Zeebtrap : 2 40*0696600cSBjoern A. Zeebtrap : 3 # shouldn't be needed 41*0696600cSBjoern A. Zeeb 42*0696600cSBjoern A. ZeebHOME=/ 43*0696600cSBjoern A. ZeebPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 44*0696600cSBjoern A. Zeebexport HOME PATH 45*0696600cSBjoern A. Zeeb 46*0696600cSBjoern A. Zeeb. /etc/rc.subr 47*0696600cSBjoern A. Zeeb 48*0696600cSBjoern A. Zeebload_rc_config 49*0696600cSBjoern A. Zeeb 50*0696600cSBjoern A. Zeeb# reverse_list list 51*0696600cSBjoern A. Zeeb# print the list in reverse order 52*0696600cSBjoern A. Zeeb# 53*0696600cSBjoern A. Zeebreverse_list() 54*0696600cSBjoern A. Zeeb{ 55*0696600cSBjoern A. Zeeb _revlist= 56*0696600cSBjoern A. Zeeb for _revfile in $*; do 57*0696600cSBjoern A. Zeeb _revlist="$_revfile${script_name_sep}$_revlist" 58*0696600cSBjoern A. Zeeb done 59*0696600cSBjoern A. Zeeb echo $_revlist 60*0696600cSBjoern A. Zeeb} 61*0696600cSBjoern A. Zeeb 62*0696600cSBjoern A. Zeeb# If requested, start a watchdog timer in the background which 63*0696600cSBjoern A. Zeeb# will terminate rc.shutdown if rc.shutdown doesn't complete 64*0696600cSBjoern A. Zeeb# within the specified time. 65*0696600cSBjoern A. Zeeb# 66*0696600cSBjoern A. Zeeb_rcshutdown_watchdog= 67*0696600cSBjoern A. Zeebif [ -n "$rcshutdown_timeout" ]; then 68*0696600cSBjoern A. Zeeb debug "Initiating watchdog timer." 69*0696600cSBjoern A. Zeeb sleep $rcshutdown_timeout && ( 70*0696600cSBjoern A. Zeeb _msg="$rcshutdown_timeout second watchdog" 71*0696600cSBjoern A. Zeeb _msg="$_msg timeout expired. Shutdown terminated." 72*0696600cSBjoern A. Zeeb logger -t rc.shutdown "$_msg" 73*0696600cSBjoern A. Zeeb echo "$_msg" 74*0696600cSBjoern A. Zeeb date 75*0696600cSBjoern A. Zeeb kill -KILL $$ >/dev/null 2>&1 76*0696600cSBjoern A. Zeeb ) & 77*0696600cSBjoern A. Zeeb _rcshutdown_watchdog=$! 78*0696600cSBjoern A. Zeebfi 79*0696600cSBjoern A. Zeeb 80*0696600cSBjoern A. Zeeb# Determine the shutdown order of the /etc/rc.d scripts, 81*0696600cSBjoern A. Zeeb# and perform the operation 82*0696600cSBjoern A. Zeeb# 83*0696600cSBjoern A. Zeebrcorder_opts="-k shutdown" 84*0696600cSBjoern A. Zeebif [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then 85*0696600cSBjoern A. Zeeb rcorder_opts="$rcorder_opts -s nojail" 86*0696600cSBjoern A. Zeeb if [ `/sbin/sysctl -n security.jail.vnet` -ne 1 ]; then 87*0696600cSBjoern A. Zeeb rcorder_opts="$rcorder_opts -s nojailvnet" 88*0696600cSBjoern A. Zeeb fi 89*0696600cSBjoern A. Zeebfi 90*0696600cSBjoern A. Zeeb 91*0696600cSBjoern A. Zeebcase ${local_startup} in 92*0696600cSBjoern A. Zeeb[Nn][Oo] | '') ;; 93*0696600cSBjoern A. Zeeb*) find_local_scripts_new ;; 94*0696600cSBjoern A. Zeebesac 95*0696600cSBjoern A. Zeeb 96*0696600cSBjoern A. Zeebfiles=`rcorder ${rcorder_opts} /etc/rc.d/* ${local_rc} 2>/dev/null` 97*0696600cSBjoern A. Zeeb 98*0696600cSBjoern A. Zeebfor _rc_elem in `reverse_list $files`; do 99*0696600cSBjoern A. Zeeb debug "run_rc_script $_rc_elem faststop" 100*0696600cSBjoern A. Zeeb run_rc_script $_rc_elem faststop 101*0696600cSBjoern A. Zeebdone 102*0696600cSBjoern A. Zeeb 103*0696600cSBjoern A. Zeeb# Terminate the background watchdog timer (if it is running) 104*0696600cSBjoern A. Zeeb# 105*0696600cSBjoern A. Zeebif [ -n "$_rcshutdown_watchdog" ]; then 106*0696600cSBjoern A. Zeeb pkill -TERM -P $_rcshutdown_watchdog >/dev/null 2>&1 107*0696600cSBjoern A. Zeebfi 108*0696600cSBjoern A. Zeeb 109*0696600cSBjoern A. Zeeb# Insert other shutdown procedures here 110*0696600cSBjoern A. Zeeb 111*0696600cSBjoern A. Zeeb 112*0696600cSBjoern A. Zeebecho '.' 113*0696600cSBjoern A. Zeebexit 0 114