rc.shutdown revision 64821
127837Sdavidn#!/bin/sh
250472Speter# $FreeBSD: head/etc/rc.shutdown 64821 2000-08-18 10:34:11Z sheldonh $
327837Sdavidn
451231Ssheldonh# Site-specific closing actions for daemons run by init on shutdown,
527837Sdavidn# or before going single-user from multi-user.
627837Sdavidn# Output and errors are directed to console by init, and the
727837Sdavidn# console is the controlling terminal.
827837Sdavidn
927837Sdavidnstty status '^T'
1027837Sdavidn
1127837Sdavidn# Set shell to ignore SIGINT (2), but not children;
1227837Sdavidn# shell catches SIGQUIT (3) and returns to single user after fsck.
1327837Sdavidntrap : 2
1427837Sdavidntrap : 3	# shouldn't be needed
1527837Sdavidn
1651231SsheldonhHOME=/
1727837SdavidnPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
1851231Ssheldonhexport HOME PATH
1927837Sdavidn
2062640Stg# If there is a global system configuration file, suck it in.
2162640Stg#
2262640Stgif [ -r /etc/defaults/rc.conf ]; then
2362640Stg	. /etc/defaults/rc.conf
2462640Stg	source_rc_confs
2562640Stgelif [ -r /etc/rc.conf ]; then
2662640Stg	. /etc/rc.conf
2762640Stgfi
2862640Stg
2963307Smarkm# Write some entropy so the rebooting /dev/random can reseed
3063307Smarkm#
3163307Smarkmcase ${entropy_file} in
3263307Smarkm[Nn][Oo] | '')
3363307Smarkm	;;
3463307Smarkm*)
3563689Sache	echo "Writing entropy file."
3663311Ssheldonh	rm -f ${entropy_file}
3763801Ssheldonh	oumask=`umask`
3863801Ssheldonh	umask 077
3963311Ssheldonh	touch ${entropy_file} && \
4063689Sache		dd if=/dev/random of=${entropy_file} \
4163689Sache		   bs=4096 count=1 2> /dev/null
4263801Ssheldonh	umask ${oumask}
4363307Smarkm	;;
4463307Smarkmesac
4563307Smarkm
4653550Sdillon# Check if /var/db/mounttab is clean.
4753550Sdilloncase $1 in
4853550Sdillonreboot)
4953550Sdillon	if [ -f /var/db/mounttab ]; then
5053550Sdillon		rpc.umntall
5153550Sdillon	fi
5253550Sdillon	;;
5353550Sdillonesac
5453550Sdillon
5564821Ssheldonhecho -n "Shutting down daemon processes:"
5627837Sdavidn
5762640Stg# for each valid dir in $local_startup, search for init scripts matching *.sh
5862640Stgcase ${local_startup} in
5962640Stg[Nn][Oo] | '')
6062640Stg	;;
6162640Stg*)
6262640Stg	for dir in ${local_startup}; do
6362640Stg		if [ -d "${dir}" ]; then
6462640Stg			for script in ${dir}/*.sh; do
6562640Stg				if [ -x "${script}" ]; then
6662640Stg					(set -T
6762640Stg					 trap 'exit 1' 2
6862640Stg					 ${script} stop)
6962640Stg				fi
7062640Stg			done
7162640Stg		fi
7262640Stg	done
7362640Stg	echo .
7462640Stg	;;
7562640Stgesac
7627837Sdavidn
7762640Stg# Insert other shutdown procedures here
7827837Sdavidn
7927837Sdavidnecho '.'
8027837Sdavidnexit 0
81