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$
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
35232976Sedstty status '^T' 2> /dev/null
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 && (
70136615Sschweikh		_msg="$rcshutdown_timeout second watchdog"
71136615Sschweikh		_msg="$_msg 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#
83138847Srsercorder_opts="-k shutdown"
84250804Sjamieif [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
85250804Sjamie	rcorder_opts="$rcorder_opts -s nojail"
86250804Sjamie	if [ `/sbin/sysctl -n security.jail.vnet` -ne 1 ]; then
87250804Sjamie		rcorder_opts="$rcorder_opts -s nojailvnet"
88250804Sjamie	fi
89250804Sjamiefi
9053550Sdillon
91153027Sdougbcase ${local_startup} in
92153027Sdougb[Nn][Oo] | '') ;;
93153027Sdougb*)     find_local_scripts_new ;;
94153027Sdougbesac
95153027Sdougb
96153027Sdougbfiles=`rcorder ${rcorder_opts} /etc/rc.d/* ${local_rc} 2>/dev/null`
97153027Sdougb
98117324Smtmfor _rc_elem in `reverse_list $files`; do
99131135Smtm	debug "run_rc_script $_rc_elem faststop"
100131135Smtm	run_rc_script $_rc_elem faststop
101117324Smtmdone
10227837Sdavidn
103117324Smtm# Terminate the background watchdog timer (if it is running)
104117324Smtm#
105117324Smtmif [ -n "$_rcshutdown_watchdog" ]; then
106187685Sbz	pkill -TERM -P $_rcshutdown_watchdog >/dev/null 2>&1
107117324Smtmfi
10827837Sdavidn
10986856Sdarrenr# Insert other shutdown procedures here
11085219Sdarrenr
11186856Sdarrenr
11227837Sdavidnecho '.'
11327837Sdavidnexit 0
114