rc.shutdown revision 250804
1191005Sdelphij#!/bin/sh
2204977Simp#
331899Ssef# Copyright (c) 1997  Ollivier Robert
431899Ssef# All rights reserved.
531899Ssef#
631899Ssef# Redistribution and use in source and binary forms, with or without
731899Ssef# modification, are permitted provided that the following conditions
831899Ssef# are met:
931899Ssef# 1. Redistributions of source code must retain the above copyright
1031899Ssef#    notice, this list of conditions and the following disclaimer.
1131899Ssef# 2. Redistributions in binary form must reproduce the above copyright
1231899Ssef#    notice, this list of conditions and the following disclaimer in the
1331899Ssef#    documentation and/or other materials provided with the distribution.
1431899Ssef#
1531899Ssef# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1631899Ssef# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1731899Ssef# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1831899Ssef# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1931899Ssef# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2031899Ssef# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2131899Ssef# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2231899Ssef# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2331899Ssef# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2431899Ssef# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2531899Ssef# SUCH DAMAGE.
2631899Ssef#
2731899Ssef# $FreeBSD: head/etc/rc.shutdown 250804 2013-05-19 04:10:34Z jamie $
2831899Ssef#
2931899Ssef
3031899Ssef# Site-specific closing actions for daemons run by init on shutdown,
3131899Ssef# or before going single-user from multi-user.
32119852Scharnier# Output and errors are directed to console by init, and the
33119852Scharnier# console is the controlling terminal.
3432275Scharnier
3531899Ssefstty status '^T' 2> /dev/null
36222103Sbcr
3731567Ssef# Set shell to ignore SIGINT (2), but not children;
3831567Ssef# shell catches SIGQUIT (3) and returns to single user after fsck.
3931567Sseftrap : 2
4031567Sseftrap : 3	# shouldn't be needed
4185301Sdes
42123916ScracauerHOME=/
43104581SmikePATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
44123916Scracauerexport HOME PATH
45168569Sdelphij
46191005Sdelphij. /etc/rc.subr
4785301Sdes
4832275Scharnierload_rc_config 'XXX'
49200462Sdelphij
50200462Sdelphij# reverse_list list
5132275Scharnier#	print the list in reverse order
5231567Ssef#
5331567Ssefreverse_list()
5431567Ssef{
55101423Smdodd	_revlist=
5631579Speter	for _revfile in $*; do
5731567Ssef		_revlist="$_revfile${script_name_sep}$_revlist"
58101282Smdodd	done
5987703Smarkm	echo $_revlist
60192025Sdds}
6131567Ssef
62241162Szont# If requested, start a watchdog timer in the background which
6331567Ssef# will terminate rc.shutdown if rc.shutdown doesn't complete
64144177Salfred# within the specified time.
6532275Scharnier#
6632275Scharnier_rcshutdown_watchdog=
67144177Salfredif [ -n "$rcshutdown_timeout" ]; then
68192025Sdds	debug "Initiating watchdog timer."
69192025Sdds	sleep $rcshutdown_timeout && (
70144177Salfred		_msg="$rcshutdown_timeout second watchdog"
7131567Ssef		_msg="$_msg timeout expired. Shutdown terminated."
7231567Ssef		logger -t rc.shutdown "$_msg"
7338897Ssef		echo "$_msg"
7438897Ssef		date
7538897Ssef		kill -KILL $$ >/dev/null 2>&1
7638897Ssef	) &
7731567Ssef	_rcshutdown_watchdog=$!
78144177Salfredfi
79144177Salfred
80144177Salfred# Determine the shutdown order of the /etc/rc.d scripts,
8131567Ssef# and perform the operation
82130394Sdwmalone#
83144177Salfredrcorder_opts="-k shutdown"
84179051Sjhbif [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then
85179051Sjhb	rcorder_opts="$rcorder_opts -s nojail"
86130394Sdwmalone	if [ `/sbin/sysctl -n security.jail.vnet` -ne 1 ]; then
8739908Ssef		rcorder_opts="$rcorder_opts -s nojailvnet"
88144177Salfred	fi
89144177Salfredfi
90144177Salfred
91144177Salfredcase ${local_startup} in
9239908Ssef[Nn][Oo] | '') ;;
93106716Smarcel*)     find_local_scripts_new ;;
94144177Salfredesac
95106716Smarcel
96154047Sgrehanfiles=`rcorder ${rcorder_opts} /etc/rc.d/* ${local_rc} 2>/dev/null`
97154047Sgrehan
98154047Sgrehanfor _rc_elem in `reverse_list $files`; do
99211935Snwhitehorn	debug "run_rc_script $_rc_elem faststop"
100211935Snwhitehorn	run_rc_script $_rc_elem faststop
101154047Sgrehandone
102211935Snwhitehorn
103101320Sjake# Terminate the background watchdog timer (if it is running)
104144177Salfred#
105101320Sjakeif [ -n "$_rcshutdown_watchdog" ]; then
106188628Simp	pkill -TERM -P $_rcshutdown_watchdog >/dev/null 2>&1
107188628Simpfi
108188628Simp
109188628Simp# Insert other shutdown procedures here
110188628Simp
111144177Salfred
11231567Ssefecho '.'
11331567Ssefexit 0
11431567Ssef