rc.shutdown revision 85219
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 85219 2001-10-20 04:33:02Z darrenr $ 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*) 6170108Sdougb echo -n 'Writing entropy file:' 6263311Ssheldonh rm -f ${entropy_file} 6363801Ssheldonh oumask=`umask` 6463801Ssheldonh umask 077 6567179Sjwd if touch ${entropy_file} ; then 6667179Sjwd entropy_file_confirmed="${entropy_file}" 6767179Sjwd else 6867179Sjwd # Try this as a reasonable alternative for read-only 6967179Sjwd # roots, diskless workstations, etc. 7067179Sjwd rm -f /var/db/entropy 7167179Sjwd if touch /var/db/entropy ; then 7267179Sjwd entropy_file_confirmed=/var/db/entropy 7367179Sjwd fi 7467179Sjwd fi 7567179Sjwd case ${entropy_file_confirmed} in 7667179Sjwd '') 7770108Sdougb echo ' ERROR - entropy file write failed' 7867179Sjwd ;; 7967179Sjwd *) 8067179Sjwd dd if=/dev/random of=${entropy_file_confirmed} \ 8167397Sache bs=4096 count=1 2> /dev/null 8270108Sdougb echo '.' 8367179Sjwd ;; 8467179Sjwd esac 8563801Ssheldonh umask ${oumask} 8663307Smarkm ;; 8763307Smarkmesac 8863307Smarkm 8953550Sdillon# Check if /var/db/mounttab is clean. 9053550Sdilloncase $1 in 9153550Sdillonreboot) 9253550Sdillon if [ -f /var/db/mounttab ]; then 9353550Sdillon rpc.umntall 9453550Sdillon fi 9553550Sdillon ;; 9653550Sdillonesac 9753550Sdillon 9870108Sdougbecho -n 'Shutting down daemon processes:' 9927837Sdavidn 10062640Stg# for each valid dir in $local_startup, search for init scripts matching *.sh 10162640Stgcase ${local_startup} in 10262640Stg[Nn][Oo] | '') 10362640Stg ;; 10462640Stg*) 10579825Sroam slist="" 10662640Stg for dir in ${local_startup}; do 10762640Stg if [ -d "${dir}" ]; then 10862640Stg for script in ${dir}/*.sh; do 10979825Sroam slist="${script}${script_name_sep}${slist}" 11062640Stg done 11162640Stg fi 11262640Stg done 11379825Sroam script_save_sep="$IFS" 11479825Sroam IFS="${script_name_sep}" 11579825Sroam for script in ${slist}; do 11679825Sroam if [ -x "${script}" ]; then 11779825Sroam (set -T 11879825Sroam trap 'exit 1' 2 11979825Sroam ${script} stop) 12079825Sroam fi 12179825Sroam done 12279825Sroam IFS="${script_save_sep}" 12370108Sdougb echo '.' 12462640Stg ;; 12562640Stgesac 12627837Sdavidn 12785219Sdarrenr# Save IP Filter state tables 12885219Sdarrenr 12985219Sdarrenrcase ${ipfs_enable} in 13085219Sdarrenr[Yy][Ee][Ss]) 13185219Sdarrenr echo -n 'Saving IP Filter state tables:' 13285219Sdarrenr eval ${ipfs_program:-/sbin/ipfs -W} ${ipfs_flags} 13385219Sdarrenr ;; 13485219Sdarrenresac 13585219Sdarrenr 13685219Sdarrenrecho . 13785219Sdarrenr 13862640Stg# Insert other shutdown procedures here 13927837Sdavidn 14027837Sdavidnecho '.' 14127837Sdavidnexit 0 142