rc.shutdown revision 153027
1193267Sjkim#!/bin/sh
2193267Sjkim#
3193267Sjkim# Copyright (c) 1997  Ollivier Robert
4193267Sjkim# All rights reserved.
5193267Sjkim#
6193267Sjkim# Redistribution and use in source and binary forms, with or without
7217365Sjkim# modification, are permitted provided that the following conditions
8298714Sjkim# are met:
9193267Sjkim# 1. Redistributions of source code must retain the above copyright
10193267Sjkim#    notice, this list of conditions and the following disclaimer.
11217365Sjkim# 2. Redistributions in binary form must reproduce the above copyright
12217365Sjkim#    notice, this list of conditions and the following disclaimer in the
13217365Sjkim#    documentation and/or other materials provided with the distribution.
14217365Sjkim#
15217365Sjkim# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16217365Sjkim# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17217365Sjkim# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18217365Sjkim# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19217365Sjkim# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20217365Sjkim# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21217365Sjkim# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22217365Sjkim# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23217365Sjkim# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24217365Sjkim# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25193267Sjkim# SUCH DAMAGE.
26217365Sjkim#
27217365Sjkim# $FreeBSD: head/etc/rc.shutdown 153027 2005-12-02 20:06:07Z dougb $
28217365Sjkim#
29193267Sjkim
30217365Sjkim# Site-specific closing actions for daemons run by init on shutdown,
31217365Sjkim# or before going single-user from multi-user.
32217365Sjkim# Output and errors are directed to console by init, and the
33217365Sjkim# console is the controlling terminal.
34217365Sjkim
35217365Sjkimstty status '^T'
36217365Sjkim
37217365Sjkim# Set shell to ignore SIGINT (2), but not children;
38217365Sjkim# shell catches SIGQUIT (3) and returns to single user after fsck.
39217365Sjkimtrap : 2
40217365Sjkimtrap : 3	# shouldn't be needed
41217365Sjkim
42217365SjkimHOME=/
43193267SjkimPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
44193267Sjkimexport HOME PATH
45193267Sjkim
46193267Sjkim. /etc/rc.subr
47193267Sjkim
48193267Sjkimload_rc_config 'XXX'
49193267Sjkim
50193267Sjkim# reverse_list list
51193267Sjkim#	print the list in reverse order
52272444Sjkim#
53193267Sjkimreverse_list()
54193267Sjkim{
55193267Sjkim	_revlist=
56193267Sjkim	for _revfile in $*; do
57193267Sjkim		_revlist="$_revfile${script_name_sep}$_revlist"
58193267Sjkim	done
59193267Sjkim	echo $_revlist
60249112Sjkim}
61193267Sjkim
62193267Sjkim# If requested, start a watchdog timer in the background which
63193267Sjkim# will terminate rc.shutdown if rc.shutdown doesn't complete
64193267Sjkim# within the specified time.
65193267Sjkim#
66193267Sjkim_rcshutdown_watchdog=
67272444Sjkimif [ -n "$rcshutdown_timeout" ]; then
68272444Sjkim	debug "Initiating watchdog timer."
69193267Sjkim	sleep $rcshutdown_timeout && (
70249112Sjkim		_msg="$rcshutdown_timeout second watchdog"
71249112Sjkim		_msg="$_msg timeout expired. Shutdown terminated."
72193267Sjkim		logger -t rc.shutdown "$_msg"
73193267Sjkim		echo "$_msg"
74193267Sjkim		date
75193267Sjkim		kill -KILL $$ >/dev/null 2>&1
76193267Sjkim	) &
77193267Sjkim	_rcshutdown_watchdog=$!
78249112Sjkimfi
79249112Sjkim
80193267Sjkim# Determine the shutdown order of the /etc/rc.d scripts,
81193267Sjkim# and perform the operation
82193267Sjkim#
83193267Sjkimrcorder_opts="-k shutdown"
84193267Sjkim[ `/sbin/sysctl -n security.jail.jailed` -eq 1 ] && rcorder_opts="$rcorder_opts -s nojail"
85193267Sjkim
86193267Sjkimcase ${local_startup} in
87193267Sjkim[Nn][Oo] | '') ;;
88193267Sjkim*)     find_local_scripts_new ;;
89193267Sjkimesac
90249112Sjkim
91249112Sjkimfiles=`rcorder ${rcorder_opts} /etc/rc.d/* ${local_rc} 2>/dev/null`
92193267Sjkim
93193267Sjkimfor _rc_elem in `reverse_list $files`; do
94249112Sjkim	debug "run_rc_script $_rc_elem faststop"
95249112Sjkim	run_rc_script $_rc_elem faststop
96193267Sjkimdone
97193267Sjkim
98197104Sjkim# Terminate the background watchdog timer (if it is running)
99197104Sjkim#
100197104Sjkimif [ -n "$_rcshutdown_watchdog" ]; then
101228110Sjkim	kill -TERM $_rcshutdown_watchdog >/dev/null 2>&1
102249112Sjkimfi
103228110Sjkim
104228110Sjkim# Insert other shutdown procedures here
105228110Sjkim
106228110Sjkim
107228110Sjkimecho '.'
108228110Sjkimexit 0
109283092Sjkim