rc.shutdown revision 66830
127837Sdavidn#!/bin/sh 266830Sobrien# 366830Sobrien# Copyright (c) 1997 Ollivier Robert 466830Sobrien# All rights reserved. 566830Sobrien# 666830Sobrien# Redistribution and use in source and binary forms, with or without 766830Sobrien# modification, are permitted provided that the following conditions 866830Sobrien# are met: 966830Sobrien# 1. Redistributions of source code must retain the above copyright 1066830Sobrien# notice, this list of conditions and the following disclaimer. 1166830Sobrien# 2. Redistributions in binary form must reproduce the above copyright 1266830Sobrien# notice, this list of conditions and the following disclaimer in the 1366830Sobrien# documentation and/or other materials provided with the distribution. 1466830Sobrien# 1566830Sobrien# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1666830Sobrien# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1766830Sobrien# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1866830Sobrien# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1966830Sobrien# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2066830Sobrien# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2166830Sobrien# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2266830Sobrien# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2366830Sobrien# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2466830Sobrien# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2566830Sobrien# SUCH DAMAGE. 2666830Sobrien# 2750472Speter# $FreeBSD: head/etc/rc.shutdown 66830 2000-10-08 19:20:36Z obrien $ 2866830Sobrien# 2927837Sdavidn 3051231Ssheldonh# Site-specific closing actions for daemons run by init on shutdown, 3127837Sdavidn# or before going single-user from multi-user. 3227837Sdavidn# Output and errors are directed to console by init, and the 3327837Sdavidn# console is the controlling terminal. 3427837Sdavidn 3527837Sdavidnstty status '^T' 3627837Sdavidn 3727837Sdavidn# Set shell to ignore SIGINT (2), but not children; 3827837Sdavidn# shell catches SIGQUIT (3) and returns to single user after fsck. 3927837Sdavidntrap : 2 4027837Sdavidntrap : 3 # shouldn't be needed 4127837Sdavidn 4251231SsheldonhHOME=/ 4327837SdavidnPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 4451231Ssheldonhexport HOME PATH 4527837Sdavidn 4662640Stg# If there is a global system configuration file, suck it in. 4762640Stg# 4862640Stgif [ -r /etc/defaults/rc.conf ]; then 4962640Stg . /etc/defaults/rc.conf 5062640Stg source_rc_confs 5162640Stgelif [ -r /etc/rc.conf ]; then 5262640Stg . /etc/rc.conf 5362640Stgfi 5462640Stg 5563307Smarkm# Write some entropy so the rebooting /dev/random can reseed 5663307Smarkm# 5763307Smarkmcase ${entropy_file} in 5863307Smarkm[Nn][Oo] | '') 5963307Smarkm ;; 6063307Smarkm*) 6163689Sache echo "Writing entropy file." 6263311Ssheldonh rm -f ${entropy_file} 6363801Ssheldonh oumask=`umask` 6463801Ssheldonh umask 077 6563311Ssheldonh touch ${entropy_file} && \ 6663689Sache dd if=/dev/random of=${entropy_file} \ 6763689Sache bs=4096 count=1 2> /dev/null 6863801Ssheldonh umask ${oumask} 6963307Smarkm ;; 7063307Smarkmesac 7163307Smarkm 7253550Sdillon# Check if /var/db/mounttab is clean. 7353550Sdilloncase $1 in 7453550Sdillonreboot) 7553550Sdillon if [ -f /var/db/mounttab ]; then 7653550Sdillon rpc.umntall 7753550Sdillon fi 7853550Sdillon ;; 7953550Sdillonesac 8053550Sdillon 8164821Ssheldonhecho -n "Shutting down daemon processes:" 8227837Sdavidn 8362640Stg# for each valid dir in $local_startup, search for init scripts matching *.sh 8462640Stgcase ${local_startup} in 8562640Stg[Nn][Oo] | '') 8662640Stg ;; 8762640Stg*) 8862640Stg for dir in ${local_startup}; do 8962640Stg if [ -d "${dir}" ]; then 9062640Stg for script in ${dir}/*.sh; do 9162640Stg if [ -x "${script}" ]; then 9262640Stg (set -T 9362640Stg trap 'exit 1' 2 9462640Stg ${script} stop) 9562640Stg fi 9662640Stg done 9762640Stg fi 9862640Stg done 9962640Stg echo . 10062640Stg ;; 10162640Stgesac 10227837Sdavidn 10362640Stg# Insert other shutdown procedures here 10427837Sdavidn 10527837Sdavidnecho '.' 10627837Sdavidnexit 0 107