rc.shutdown revision 232976
137Srgrimes#!/bin/sh 237Srgrimes# 337Srgrimes# Copyright (c) 1997 Ollivier Robert 4705Swollman# All rights reserved. 5705Swollman# 6705Swollman# Redistribution and use in source and binary forms, with or without 739139Sobrien# modification, are permitted provided that the following conditions 846414Sghelmer# are met: 980266Sdougb# 1. Redistributions of source code must retain the above copyright 1080945Sdougb# notice, this list of conditions and the following disclaimer. 1180266Sdougb# 2. Redistributions in binary form must reproduce the above copyright 1239139Sobrien# notice, this list of conditions and the following disclaimer in the 1339139Sobrien# documentation and/or other materials provided with the distribution. 1439139Sobrien# 1539139Sobrien# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 167685Sache# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 177685Sache# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1837Srgrimes# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1950472Speter# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20705Swollman# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21705Swollman# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 227685Sache# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 237685Sache# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2422009Sphk# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 257685Sache# SUCH DAMAGE. 267685Sache# 2722009Sphk# $FreeBSD: head/etc/rc.shutdown 232976 2012-03-14 16:10:39Z ed $ 287685Sache# 297685Sache 307685Sache# Site-specific closing actions for daemons run by init on shutdown, 317685Sache# or before going single-user from multi-user. 3222009Sphk# Output and errors are directed to console by init, and the 337685Sache# console is the controlling terminal. 347685Sache 3522009Sphkstty status '^T' 2> /dev/null 367685Sache 377685Sache# Set shell to ignore SIGINT (2), but not children; 387685Sache# shell catches SIGQUIT (3) and returns to single user after fsck. 397685Sachetrap : 2 407685Sachetrap : 3 # shouldn't be needed 417685Sache 427685SacheHOME=/ 437685SachePATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 447685Sacheexport HOME PATH 457685Sache 467685Sache. /etc/rc.subr 477685Sache 487685Sacheload_rc_config 'XXX' 497685Sache 507685Sache# reverse_list list 517685Sache# print the list in reverse order 527685Sache# 537685Sachereverse_list() 54131994Scperciva{ 55131994Scperciva _revlist= 567685Sache for _revfile in $*; do 577685Sache _revlist="$_revfile${script_name_sep}$_revlist" 587685Sache done 597685Sache echo $_revlist 607685Sache} 617685Sache 627685Sache# If requested, start a watchdog timer in the background which 637685Sache# will terminate rc.shutdown if rc.shutdown doesn't complete 647685Sache# within the specified time. 657685Sache# 667685Sache_rcshutdown_watchdog= 677685Sacheif [ -n "$rcshutdown_timeout" ]; then 687685Sache debug "Initiating watchdog timer." 697685Sache sleep $rcshutdown_timeout && ( 707685Sache _msg="$rcshutdown_timeout second watchdog" 717685Sache _msg="$_msg timeout expired. Shutdown terminated." 727685Sache logger -t rc.shutdown "$_msg" 737685Sache echo "$_msg" 747685Sache date 757685Sache kill -KILL $$ >/dev/null 2>&1 767685Sache ) & 777685Sache _rcshutdown_watchdog=$! 787685Sachefi 797685Sache 807685Sache# Determine the shutdown order of the /etc/rc.d scripts, 817685Sache# and perform the operation 827685Sache# 837685Sachercorder_opts="-k shutdown" 847685Sache[ `/sbin/sysctl -n security.jail.jailed` -eq 1 ] && rcorder_opts="$rcorder_opts -s nojail" 857685Sache 867685Sachecase ${local_startup} in 877685Sache[Nn][Oo] | '') ;; 887685Sache*) find_local_scripts_new ;; 897685Sacheesac 907685Sache 917685Sachefiles=`rcorder ${rcorder_opts} /etc/rc.d/* ${local_rc} 2>/dev/null` 927685Sache 937685Sachefor _rc_elem in `reverse_list $files`; do 94131994Scperciva debug "run_rc_script $_rc_elem faststop" 95131994Scperciva run_rc_script $_rc_elem faststop 967685Sachedone 977685Sache 987685Sache# Terminate the background watchdog timer (if it is running) 997685Sache# 1007685Sacheif [ -n "$_rcshutdown_watchdog" ]; then 1017685Sache pkill -TERM -P $_rcshutdown_watchdog >/dev/null 2>&1 1027685Sachefi 1037685Sache 1047685Sache# Insert other shutdown procedures here 1057685Sache 1067685Sache 1077685Sacheecho '.' 1087685Sacheexit 0 1097685Sache