xref: /freebsd/libexec/rc/rc.shutdown (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb#
30696600cSBjoern A. Zeeb# Copyright (c) 1997  Ollivier Robert
40696600cSBjoern A. Zeeb# All rights reserved.
50696600cSBjoern A. Zeeb#
60696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without
70696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions
80696600cSBjoern A. Zeeb# are met:
90696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright
100696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer.
110696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright
120696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer in the
130696600cSBjoern A. Zeeb#    documentation and/or other materials provided with the distribution.
140696600cSBjoern A. Zeeb#
150696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
160696600cSBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
170696600cSBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
180696600cSBjoern A. Zeeb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
190696600cSBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
200696600cSBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
210696600cSBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
220696600cSBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
230696600cSBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
240696600cSBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
250696600cSBjoern A. Zeeb# SUCH DAMAGE.
260696600cSBjoern A. Zeeb#
270696600cSBjoern A. Zeeb#
280696600cSBjoern A. Zeeb
290696600cSBjoern A. Zeeb# Site-specific closing actions for daemons run by init on shutdown,
300696600cSBjoern A. Zeeb# or before going single-user from multi-user.
310696600cSBjoern A. Zeeb# Output and errors are directed to console by init, and the
320696600cSBjoern A. Zeeb# console is the controlling terminal.
330696600cSBjoern A. Zeeb
340696600cSBjoern A. Zeebstty status '^T' 2> /dev/null
350696600cSBjoern A. Zeeb
360696600cSBjoern A. Zeeb# Set shell to ignore SIGINT (2), but not children;
370696600cSBjoern A. Zeeb# shell catches SIGQUIT (3) and returns to single user after fsck.
380696600cSBjoern A. Zeebtrap : 2
390696600cSBjoern A. Zeebtrap : 3	# shouldn't be needed
400696600cSBjoern A. Zeeb
410696600cSBjoern A. ZeebHOME=/
420696600cSBjoern A. ZeebPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
430696600cSBjoern A. Zeebexport HOME PATH
440696600cSBjoern A. Zeeb
455fda0d60SAndriy Gaponrc_shutdown=${1:-"unspecified"}
465fda0d60SAndriy Gapon
470696600cSBjoern A. Zeeb. /etc/rc.subr
480696600cSBjoern A. Zeeb
490696600cSBjoern A. Zeebload_rc_config
500696600cSBjoern A. Zeeb
510696600cSBjoern A. Zeeb# reverse_list list
520696600cSBjoern A. Zeeb#	print the list in reverse order
530696600cSBjoern A. Zeeb#
540696600cSBjoern A. Zeebreverse_list()
550696600cSBjoern A. Zeeb{
560696600cSBjoern A. Zeeb	_revlist=
570696600cSBjoern A. Zeeb	for _revfile in $*; do
580696600cSBjoern A. Zeeb		_revlist="$_revfile${script_name_sep}$_revlist"
590696600cSBjoern A. Zeeb	done
600696600cSBjoern A. Zeeb	echo $_revlist
610696600cSBjoern A. Zeeb}
620696600cSBjoern A. Zeeb
630696600cSBjoern A. Zeeb# If requested, start a watchdog timer in the background which
640696600cSBjoern A. Zeeb# will terminate rc.shutdown if rc.shutdown doesn't complete
650696600cSBjoern A. Zeeb# within the specified time.
660696600cSBjoern A. Zeeb#
670696600cSBjoern A. Zeeb_rcshutdown_watchdog=
680696600cSBjoern A. Zeebif [ -n "$rcshutdown_timeout" ]; then
690696600cSBjoern A. Zeeb	debug "Initiating watchdog timer."
700696600cSBjoern A. Zeeb	sleep $rcshutdown_timeout && (
710696600cSBjoern A. Zeeb		_msg="$rcshutdown_timeout second watchdog"
720696600cSBjoern A. Zeeb		_msg="$_msg timeout expired. Shutdown terminated."
730696600cSBjoern A. Zeeb		logger -t rc.shutdown "$_msg"
744a76bd99SEd Maste		echo
750696600cSBjoern A. Zeeb		echo "$_msg"
760696600cSBjoern A. Zeeb		date
77*7424699cSEd Maste		kill -KILL $$ >/dev/null 2>&1
780696600cSBjoern A. Zeeb	) &
790696600cSBjoern A. Zeeb	_rcshutdown_watchdog=$!
800696600cSBjoern A. Zeebfi
810696600cSBjoern A. Zeeb
820696600cSBjoern A. Zeeb# Determine the shutdown order of the /etc/rc.d scripts,
830696600cSBjoern A. Zeeb# and perform the operation
840696600cSBjoern A. Zeeb#
850696600cSBjoern A. Zeebrcorder_opts="-k shutdown"
860696600cSBjoern A. Zeebif [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
870696600cSBjoern A. Zeeb	rcorder_opts="$rcorder_opts -s nojail"
880696600cSBjoern A. Zeeb	if [ `/sbin/sysctl -n security.jail.vnet` -ne 1 ]; then
890696600cSBjoern A. Zeeb		rcorder_opts="$rcorder_opts -s nojailvnet"
900696600cSBjoern A. Zeeb	fi
910696600cSBjoern A. Zeebfi
920696600cSBjoern A. Zeeb
930696600cSBjoern A. Zeebcase ${local_startup} in
940696600cSBjoern A. Zeeb[Nn][Oo] | '') ;;
950696600cSBjoern A. Zeeb*)     find_local_scripts_new ;;
960696600cSBjoern A. Zeebesac
970696600cSBjoern A. Zeeb
980696600cSBjoern A. Zeebfiles=`rcorder ${rcorder_opts} /etc/rc.d/* ${local_rc} 2>/dev/null`
990696600cSBjoern A. Zeeb
1000696600cSBjoern A. Zeebfor _rc_elem in `reverse_list $files`; do
1010696600cSBjoern A. Zeeb	debug "run_rc_script $_rc_elem faststop"
1020696600cSBjoern A. Zeeb	run_rc_script $_rc_elem faststop
1030696600cSBjoern A. Zeebdone
1040696600cSBjoern A. Zeeb
1050696600cSBjoern A. Zeeb# Terminate the background watchdog timer (if it is running)
1060696600cSBjoern A. Zeeb#
1070696600cSBjoern A. Zeebif [ -n "$_rcshutdown_watchdog" ]; then
1080696600cSBjoern A. Zeeb	pkill -TERM -P $_rcshutdown_watchdog >/dev/null 2>&1
1090696600cSBjoern A. Zeebfi
1100696600cSBjoern A. Zeeb
1110696600cSBjoern A. Zeeb# Insert other shutdown procedures here
1120696600cSBjoern A. Zeeb
1130696600cSBjoern A. Zeeb
1140696600cSBjoern A. Zeebecho '.'
1150696600cSBjoern A. Zeebexit 0
116