rc.shutdown revision 187685
113546Sjulian#!/bin/sh 235509Sjb# 313546Sjulian# Copyright (c) 1997 Ollivier Robert 413546Sjulian# All rights reserved. 513546Sjulian# 613546Sjulian# Redistribution and use in source and binary forms, with or without 713546Sjulian# modification, are permitted provided that the following conditions 813546Sjulian# are met: 913546Sjulian# 1. Redistributions of source code must retain the above copyright 1013546Sjulian# notice, this list of conditions and the following disclaimer. 1113546Sjulian# 2. Redistributions in binary form must reproduce the above copyright 1213546Sjulian# notice, this list of conditions and the following disclaimer in the 13165967Simp# documentation and/or other materials provided with the distribution. 1413546Sjulian# 1513546Sjulian# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1613546Sjulian# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1713546Sjulian# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1813546Sjulian# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1913546Sjulian# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2049439Sdeischen# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2113546Sjulian# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2213546Sjulian# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2313546Sjulian# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2413546Sjulian# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2513546Sjulian# SUCH DAMAGE. 2613546Sjulian# 2713546Sjulian# $FreeBSD: head/etc/rc.shutdown 187685 2009-01-25 10:31:45Z bz $ 2813546Sjulian# 2950476Speter 3013546Sjulian# Site-specific closing actions for daemons run by init on shutdown, 31174112Sdeischen# or before going single-user from multi-user. 32174112Sdeischen# Output and errors are directed to console by init, and the 3313546Sjulian# console is the controlling terminal. 3417706Sjulian 3517706Sjulianstty status '^T' 3653812Salfred 3753812Salfred# Set shell to ignore SIGINT (2), but not children; 3813546Sjulian# shell catches SIGQUIT (3) and returns to single user after fsck. 3913546Sjuliantrap : 2 40174112Sdeischentrap : 3 # shouldn't be needed 41103388Smini 4213546SjulianHOME=/ 43113658SdeischenPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 4467097Sdeischenexport HOME PATH 4575369Sdeischen 4671581Sdeischen. /etc/rc.subr 4713546Sjulian 48174112Sdeischenload_rc_config 'XXX' 4913546Sjulian 5013546Sjulian# reverse_list list 51115399Skan# print the list in reverse order 52115399Skan# 5372374Sdeischenreverse_list() 54113658Sdeischen{ 5513546Sjulian _revlist= 5648046Sjb for _revfile in $*; do 5713546Sjulian _revlist="$_revfile${script_name_sep}$_revlist" 5813546Sjulian done 5953812Salfred echo $_revlist 6053812Salfred} 6153812Salfred 6253812Salfred# If requested, start a watchdog timer in the background which 6353812Salfred# will terminate rc.shutdown if rc.shutdown doesn't complete 6413546Sjulian# within the specified time. 65113658Sdeischen# 6653812Salfred_rcshutdown_watchdog= 6771581Sdeischenif [ -n "$rcshutdown_timeout" ]; then 6871581Sdeischen debug "Initiating watchdog timer." 6953812Salfred sleep $rcshutdown_timeout && ( 7053812Salfred _msg="$rcshutdown_timeout second watchdog" 7153812Salfred _msg="$_msg timeout expired. Shutdown terminated." 7253812Salfred logger -t rc.shutdown "$_msg" 7353812Salfred echo "$_msg" 7453812Salfred date 7553812Salfred kill -KILL $$ >/dev/null 2>&1 7653812Salfred ) & 7771581Sdeischen _rcshutdown_watchdog=$! 7853812Salfredfi 7953812Salfred 8053812Salfred# Determine the shutdown order of the /etc/rc.d scripts, 8153812Salfred# and perform the operation 8253812Salfred# 8353812Salfredrcorder_opts="-k shutdown" 8453812Salfred[ `/sbin/sysctl -n security.jail.jailed` -eq 1 ] && rcorder_opts="$rcorder_opts -s nojail" 8553812Salfred 8671581Sdeischencase ${local_startup} in 8713546Sjulian[Nn][Oo] | '') ;; 88113658Sdeischen*) find_local_scripts_new ;; 89120074Sdavidxuesac 90120074Sdavidxu 9113546Sjulianfiles=`rcorder ${rcorder_opts} /etc/rc.d/* ${local_rc} 2>/dev/null` 9236827Sjb 93113658Sdeischenfor _rc_elem in `reverse_list $files`; do 9436827Sjb debug "run_rc_script $_rc_elem faststop" 95113658Sdeischen run_rc_script $_rc_elem faststop 96113658Sdeischendone 97113658Sdeischen 9836827Sjb# Terminate the background watchdog timer (if it is running) 9936827Sjb# 10036827Sjbif [ -n "$_rcshutdown_watchdog" ]; then 101113658Sdeischen pkill -TERM -P $_rcshutdown_watchdog >/dev/null 2>&1 102113658Sdeischenfi 103113658Sdeischen 104113658Sdeischen# Insert other shutdown procedures here 105114187Sdeischen 106113658Sdeischen 107114187Sdeischenecho '.' 108136847Sdavidxuexit 0 109136847Sdavidxu