]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc
additionally warnings
[FreeBSD/FreeBSD.git] / etc / rc
1 #!/bin/sh
2 #       $Id: rc,v 1.145 1998/06/02 11:02:16 phk Exp $
3 #       From: @(#)rc    5.27 (Berkeley) 6/5/91
4
5 # System startup script run by init on autoboot
6 # or after single-user.
7 # Output and error are redirected to console by init,
8 # and the console is the controlling terminal.
9
10 # Note that almost all the user-configurable behavior is no longer in
11 # this file, but rather in /etc/rc.conf.  Please check this file
12 # first before contemplating any changes here.
13
14 stty status '^T'
15
16 # Set shell to ignore SIGINT (2), but not children;
17 # shell catches SIGQUIT (3) and returns to single user after fsck.
18 trap : 2
19 trap : 3        # shouldn't be needed
20
21 HOME=/; export HOME
22 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
23 export PATH
24
25 # Configure ccd devices.
26 if [ -f /etc/ccd.conf ]; then
27         ccdconfig -C
28 fi
29
30 swapon -a
31
32 if [ $1x = autobootx ]; then
33         echo Automatic reboot in progress...
34         fsck -p
35         case $? in
36         0)
37                 ;;
38         2)
39                 exit 1
40                 ;;
41         4)
42                 reboot
43                 echo "reboot failed... help!"
44                 exit 1
45                 ;;
46         8)
47                 echo "Automatic file system check failed... help!"
48                 exit 1
49                 ;;
50         12)
51                 echo "Reboot interrupted"
52                 exit 1
53                 ;;
54         130)
55                 # interrupt before catcher installed
56                 exit 1
57                 ;;
58         *)
59                 echo "Unknown error in reboot"
60                 exit 1
61                 ;;
62         esac
63 else
64         echo Skipping disk checks ...
65 fi
66
67 trap "echo 'Reboot interrupted'; exit 1" 3
68
69 # root must be read/write both for NFS diskless and for VFS LKMs before
70 # proceeding any further.
71 mount -u -o rw /
72 if [ $? != 0 ]; then
73         echo "Filesystem mount failed, startup aborted"
74         exit 1
75 fi
76
77 umount -a >/dev/null 2>&1
78
79 mount -a -t nonfs
80 if [ $? != 0 ]; then
81         echo "Filesystem mount failed, startup aborted"
82         exit 1
83 fi
84
85 # If there is a global system configuration file, suck it in.
86 if [ -f /etc/rc.conf ]; then
87     . /etc/rc.conf
88 fi
89
90 # If old file exists, whine until they fix it.
91 if [ -f /etc/sysconfig ]; then
92         echo "Warning: /etc/sysconfig has been replaced by /etc/rc.conf."
93         echo "You should switch to /etc/rc.conf ASAP to eliminate this warning."
94 fi
95
96 adjkerntz -i
97
98 rm -rf /var/run/*
99
100 # Keep a copy of the boot messages around
101 dmesg > /var/run/dmesg.boot
102
103 # Add additional swapfile, if configured.
104 if [ "x$swapfile" != "xNO" -a -w "$swapfile" -a -b /dev/vn0b ]; then
105         echo "Adding $swapfile as additional swap."
106         vnconfig /dev/vn0b $swapfile && swapon /dev/vn0b
107 fi
108
109 # configure serial devices
110 if [ -f /etc/rc.serial ]; then
111         . /etc/rc.serial
112 fi
113
114 # start up PC-card configuration
115 if [ -f /etc/rc.pccard ]; then
116         . /etc/rc.pccard
117 fi
118
119 # start up the initial network configuration.
120 if [ -f /etc/rc.network ]; then
121         . /etc/rc.network       # We only need to do this once.
122         network_pass1
123 fi
124
125 mount -a -t nfs
126
127 # Whack the pty perms back into shape.
128 chmod 666 /dev/tty[pqrsPQRS]*
129
130 # clean up left-over files
131 rm -f /etc/nologin
132 rm -f /var/spool/lock/*
133 rm -rf /var/spool/uucp/.Temp/*
134 (cd /var/run && { cp /dev/null utmp; chmod 644 utmp; })
135
136 #
137 # Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
138 # help in any way for long-living systems, and it might accidentally
139 # clobber files you would rather like to have preserved after a crash
140 # (if not using mfs /tmp anyway).
141 #
142 # See also the example of another cleanup policy in /etc/periodic/daily.
143 #
144 if [ "X${clear_tmp_enable}" = X"YES" ]; then
145         echo clearing /tmp
146
147         # prune quickly with one rm, then use find to clean up /tmp/[lq]*
148         # (not needed with mfs /tmp, but doesn't hurt there...)
149         (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
150             find -d . ! -name . ! -name lost+found ! -name quotas -exec rm -rf -- {} \;)
151
152         # Also remove X lock files since it will prevent you from
153         # restarting X11 after a system crash.
154         rm -f /tmp/.X*-lock /tmp/.X11-unix/*
155 fi
156
157 # snapshot any kernel -c changes back to disk
158 echo 'recording kernel -c changes'
159 dset -q
160
161 echo -n 'additional daemons:'
162 # start system logging and name service (named needs to start before syslogd
163 # if you don't have a /etc/resolv.conf)
164 #
165 if [ "X${syslogd_enable}" = X"YES" ]; then
166         # Transitional symlink (for the next couple of years :) until all
167         # binaries had a chance to move towards /var/run/log.
168         if [ ! -h /dev/log ] ; then
169                 # might complain for r/o root f/s
170                 ln -sf /var/run/log /dev/log
171         fi
172
173         rm -f /var/run/log
174         echo -n ' syslogd';             syslogd ${syslogd_flags}
175 fi
176
177 if [ "X${tickadj_enable}" = X"YES" ]; then
178         echo -n ' tickadj';     tickadj ${tickadj_flags--Aq}
179 fi
180 echo '.'
181
182 # enable dumpdev so that savecore can see it
183 # /var/crash should be a directory or a symbolic link
184 # to the crash directory if core dumps are to be saved.
185 if [ "X${dumpdev}" != X"NO" -a -e ${dumpdev} -a -d /var/crash ]; then
186         dumpon ${dumpdev}
187         echo -n checking for core dump...
188         savecore /var/crash
189 fi
190
191 if [ -n "$network_pass1_done" ]; then
192     network_pass2
193 fi
194
195 # Check the quotas (must be after ypbind if using NIS)
196 if [ "X${check_quotas}" = X"YES" ]; then
197         echo -n 'checking quotas:'
198         quotacheck -a
199         echo ' done.'
200         quotaon -a
201 fi
202
203 if [ -n "$network_pass2_done" ]; then
204     network_pass3
205 fi
206
207
208 # build ps databases
209 kvm_mkdb 
210 dev_mkdb
211
212 # check the password temp/lock file
213 if [ -f /etc/ptmp ]
214 then
215         logger -s -p auth.err \
216         "password file may be incorrect -- /etc/ptmp exists"
217 fi
218
219 if [ "X${accounting_enable}" = X"YES" -a -d /var/account ]; then
220         echo 'turning on accounting'
221         if [ ! -e /var/account/acct ]; then
222                 touch /var/account/acct
223         fi
224         accton /var/account/acct
225 fi
226
227 # Make shared lib searching a little faster.  Leave /usr/lib first if you
228 # add your own entries or you may come to grief.
229 _LDC=/usr/lib/aout
230 for i in $ldconfig_paths; do
231         if test -d $i; then
232                 _LDC="${_LDC} $i"
233         fi
234 done
235 echo 'setting ldconfig path:' ${_LDC}
236 ldconfig ${_LDC}
237
238 # Now start up miscellaneous daemons that don't belong anywhere else
239 #
240 echo -n starting standard daemons:
241 if [ "X${inetd_enable}" != X"NO" ]; then
242         echo -n ' inetd';       inetd ${inetd_flags}
243 fi
244
245 if [ "X${cron_enable}" != X"NO" ]; then
246         echo -n ' cron';        cron
247 fi
248
249 if [ "X${lpd_enable}" = X"YES" ]; then
250         echo -n ' printer';             lpd ${lpd_flags}
251 fi
252
253 if [ "X${sendmail_enable}" = X"YES" -a -r /etc/sendmail.cf ]; then
254         echo -n ' sendmail';    /usr/sbin/sendmail ${sendmail_flags}
255 fi
256
257 echo '.'
258
259 # configure implementation specific stuff
260 arch=`uname -m`
261 if [ -f /etc/rc.${arch} ]; then
262         . /etc/rc.${arch}
263 fi
264
265 # Recover vi editor files.
266 vibackup=`echo /var/tmp/vi.recover/vi.*`
267 if [ "$vibackup" != '/var/tmp/vi.recover/vi.*' ]; then
268         echo 'Recovering vi editor sessions'
269         for i in $vibackup; do
270                 # Only test files that are readable.
271                 if test ! -r $i; then
272                         continue
273                 fi
274
275                 # Unmodified nvi editor backup files either have the
276                 # execute bit set or are zero length.  Delete them.
277                 if test -x $i -o ! -s $i; then
278                         rm -f $i
279                 fi
280         done
281
282         # It is possible to get incomplete recovery files, if the editor
283         # crashes at the right time.
284         virecovery=`echo /var/tmp/vi.recover/recover.*`
285         if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
286                 for i in $virecovery; do
287                         # Only test files that are readable.
288                         if test ! -r $i; then
289                                 continue
290                         fi
291
292                         # Delete any recovery files that are zero length,
293                         # corrupted, or that have no corresponding backup file.
294                         # Else send mail to the user.
295                         recfile=`awk '/^X-vi-recover-path:/{print $2}' < $i`
296                         if test -n "$recfile" -a -s "$recfile"; then
297                                 sendmail -t < $i
298                         else
299                                 rm -f $i
300                         fi
301                 done
302         fi
303 fi
304
305 # for each valid dir in $local_startup, search for init scripts matching *.sh
306 if [ "X${local_startup}" != X"NO" ]; then
307         echo -n 'Local package initialization:'
308         for dir in ${local_startup}; do
309                 [ -d ${dir} ] && for script in ${dir}/*.sh; do
310                         [ -x ${script} ] && ${script} start
311                 done
312         done
313         echo .
314 fi
315
316 # Do traditional (but rather obsolete) rc.local file if it exists.
317 [ -f /etc/rc.local ] && sh /etc/rc.local
318
319 # Raise kernel security level.  This should be done only after `fsck' has
320 # repaired local file systems if you want the securelevel to be greater than 1.
321 if [ "X${kern_securelevel_enable}" != X"NO" -a "${kern_securelevel}" -ge 0 ]; 
322 then
323         echo 'Raising kernel security level'
324         sysctl -w kern.securelevel=${kern_securelevel}
325 fi
326
327 date
328 exit 0