rc.shutdown revision 70108
131567Ssef#!/bin/sh
231899Ssef#
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 70108 2000-12-17 08:16:06Z dougb $
2831899Ssef#
2931899Ssef
3031899Ssef# Site-specific closing actions for daemons run by init on shutdown,
3131899Ssef# or before going single-user from multi-user.
3232275Scharnier# Output and errors are directed to console by init, and the
3332275Scharnier# console is the controlling terminal.
3450477Speter
3532275Scharnierstty status '^T'
3632275Scharnier
3731899Ssef# 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
4131567Ssef
4231567SsefHOME=/
4385301SdesPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
4485301Sdesexport HOME PATH
4585301Sdes
4685301Sdes# If there is a global system configuration file, suck it in.
4785301Sdes#
4832275Scharnierif [ -r /etc/defaults/rc.conf ]; then
4932275Scharnier	. /etc/defaults/rc.conf
5032275Scharnier	source_rc_confs
5132275Scharnierelif [ -r /etc/rc.conf ]; then
5231567Ssef	. /etc/rc.conf
5331567Sseffi
5431567Ssef
5531579Speter# Write some entropy so the rebooting /dev/random can reseed
5631567Ssef#
5731567Ssefcase ${entropy_file} in
5831567Ssef[Nn][Oo] | '')
5939908Ssef	;;
6039908Ssef*)
6139908Ssef	echo -n 'Writing entropy file:'
6239908Ssef	rm -f ${entropy_file}
6339908Ssef	oumask=`umask`
6431567Ssef	umask 077
6531567Ssef	if touch ${entropy_file} ; then
6631567Ssef		entropy_file_confirmed="${entropy_file}"
6731567Ssef	else
6839908Ssef		# Try this as a reasonable alternative for read-only
6931567Ssef		# roots, diskless workstations, etc.
7031567Ssef		rm -f /var/db/entropy
7131567Ssef		if touch /var/db/entropy ; then
7231567Ssef			entropy_file_confirmed=/var/db/entropy
7331567Ssef		fi
7431567Ssef	fi
7531567Ssef	case ${entropy_file_confirmed} in
7631567Ssef	'')
7781608Speter		echo ' ERROR - entropy file write failed'
7831567Ssef		;;
7931567Ssef	*)
8031567Ssef		dd if=/dev/random of=${entropy_file_confirmed} \
8131567Ssef		   bs=4096 count=1 2> /dev/null
8232275Scharnier		echo '.'
8332275Scharnier		;;
8432275Scharnier	esac
8532275Scharnier	umask ${oumask}
8632275Scharnier	;;
8731567Ssefesac
8831567Ssef
8931567Ssef# Check if /var/db/mounttab is clean.
9038897Ssefcase $1 in
9138897Ssefreboot)
9238897Ssef	if [ -f /var/db/mounttab ]; then
9338897Ssef		rpc.umntall
9431567Ssef	fi
9531567Ssef	;;
9631567Ssefesac
9731567Ssef
9831567Ssefecho -n 'Shutting down daemon processes:'
9939908Ssef
10039908Ssef# for each valid dir in $local_startup, search for init scripts matching *.sh
10139908Ssefcase ${local_startup} in
10239908Ssef[Nn][Oo] | '')
10331567Ssef	;;
10431580Speter*)
10531567Ssef	for dir in ${local_startup}; do
10639908Ssef		if [ -d "${dir}" ]; then
10731567Ssef			for script in ${dir}/*.sh; do
10831567Ssef				if [ -x "${script}" ]; then
10931567Ssef					(set -T
11031567Ssef					 trap 'exit 1' 2
11131567Ssef					 ${script} stop)
11231567Ssef				fi
11331567Ssef			done
11431567Ssef		fi
11531567Ssef	done
11631567Ssef	echo '.'
11731567Ssef	;;
11831567Ssefesac
11931567Ssef
12031567Ssef# Insert other shutdown procedures here
12131567Ssef
12231567Ssefecho '.'
12331567Ssefexit 0
12431567Ssef