]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.shutdown
This commit was generated by cvs2svn to compensate for changes in r98008,
[FreeBSD/FreeBSD.git] / etc / rc.shutdown
1 #!/bin/sh
2 #
3 # Copyright (c) 1997  Ollivier Robert
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 #    notice, this list of conditions and the following disclaimer in the
13 #    documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
26 #
27 # $FreeBSD$
28 #
29
30 # Site-specific closing actions for daemons run by init on shutdown,
31 # or before going single-user from multi-user.
32 # Output and errors are directed to console by init, and the
33 # console is the controlling terminal.
34
35 stty status '^T'
36
37 # Set shell to ignore SIGINT (2), but not children;
38 # shell catches SIGQUIT (3) and returns to single user after fsck.
39 trap : 2
40 trap : 3        # shouldn't be needed
41
42 HOME=/
43 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
44 export HOME PATH
45
46 # If there is a global system configuration file, suck it in.
47 #
48 if [ -r /etc/defaults/rc.conf ]; then
49         . /etc/defaults/rc.conf
50         source_rc_confs
51 elif [ -r /etc/rc.conf ]; then
52         . /etc/rc.conf
53 fi
54
55 # reverse_list list
56 #       print the list in reverse order
57 #
58 reverse_list()
59 {
60         _revlist=
61         for _revfile in $*; do
62                 _revlist="$_revfile${script_name_sep}$_revlist"
63         done
64         echo $_revlist
65 }
66
67 # Write some entropy so the rebooting /dev/random can reseed
68 #
69 case ${entropy_file} in
70 [Nn][Oo] | '')
71         ;;
72 *)
73         echo -n 'Writing entropy file:'
74         rm -f ${entropy_file}
75         oumask=`umask`
76         umask 077
77         if touch ${entropy_file} ; then
78                 entropy_file_confirmed="${entropy_file}"
79         else
80                 # Try this as a reasonable alternative for read-only
81                 # roots, diskless workstations, etc.
82                 rm -f /var/db/entropy
83                 if touch /var/db/entropy ; then
84                         entropy_file_confirmed=/var/db/entropy
85                 fi
86         fi
87         case ${entropy_file_confirmed} in
88         '')
89                 echo ' ERROR - entropy file write failed'
90                 ;;
91         *)
92                 dd if=/dev/random of=${entropy_file_confirmed} \
93                    bs=4096 count=1 2> /dev/null
94                 echo '.'
95                 ;;
96         esac
97         umask ${oumask}
98         ;;
99 esac
100
101 # Check if /var/db/mounttab is clean.
102 case $1 in
103 reboot)
104         if [ -f /var/db/mounttab ]; then
105                 rpc.umntall
106         fi
107         ;;
108 esac
109
110 echo -n 'Shutting down daemon processes:'
111
112 # for each valid dir in $local_startup, search for init scripts matching *.sh
113 case ${local_startup} in
114 [Nn][Oo] | '')
115         ;;
116 *)
117         slist=""
118         if [ -z "${script_name_sep}" ]; then
119                 script_name_sep=" "
120         fi
121         for dir in ${local_startup}; do
122                 if [ -d "${dir}" ]; then
123                         for script in ${dir}/*.sh; do
124                                 slist="${slist}${script_name_sep}${script}"
125                         done
126                 fi
127         done
128         script_save_sep="$IFS"
129         IFS="${script_name_sep}"
130         for script in `reverse_list ${slist}`; do
131                 if [ -x "${script}" ]; then
132                         (set -T
133                         trap 'exit 1' 2
134                         ${script} stop)
135                 fi
136         done
137         IFS="${script_save_sep}"
138         echo '.'
139         ;;
140 esac
141
142 # Insert other shutdown procedures here
143
144 # Saving firewall state tables should be done last
145 echo -n 'Saving firewall state tables:'
146
147 # Save IP-filter state tables
148 case ${ipfs_enable} in
149 [Yy][Ee][Ss])
150         echo -n ' ipfs'
151         ${ipfs_program:-/sbin/ipfs} -W ${ipfs_flags}
152         ;;
153 esac
154
155 echo '.'
156 exit 0