]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc
This commit was generated by cvs2svn to compensate for changes in r57419,
[FreeBSD/FreeBSD.git] / etc / rc
1 #!/bin/sh
2 # $FreeBSD$
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 of the user-configurable behavior is no longer in
11 # this file, but rather in /etc/defaults/rc.conf.  Please check that file
12 # first before contemplating any changes here.  If you do need to change
13 # this file for some reason, we would like to know about it.
14
15 stty status '^T'
16
17 # Set shell to ignore SIGINT (2), but not children;
18 # shell catches SIGQUIT (3) and returns to single user after fsck.
19 #
20 trap : 2
21 trap : 3        # shouldn't be needed
22
23 HOME=/
24 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin
25 export HOME PATH
26
27 # BOOTP diskless boot.  We have to run the rc file early in order to
28 # retarget various config files.
29 #
30 if [ -r /etc/rc.diskless1 ]; then
31         dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
32         if [ ${dlv:=0} != 0 ]; then
33                 . /etc/rc.diskless1
34         fi
35 fi
36
37 # If there is a global system configuration file, suck it in.
38 #
39 if [ -r /etc/defaults/rc.conf ]; then
40         . /etc/defaults/rc.conf
41 elif [ -r /etc/rc.conf ]; then
42         . /etc/rc.conf
43 fi
44
45 # Configure ccd devices.
46 #
47 if [ -r /etc/ccd.conf ]; then
48         ccdconfig -C
49 fi
50
51 case ${start_vinum} in
52 [Yy][Ee][Ss])
53         vinum start
54         ;;
55 esac
56
57 swapon -a
58
59 case $1 in
60 autoboot)
61         echo Automatic reboot in progress...
62         fsck -p
63         case $? in
64         0)
65                 ;;
66         2)
67                 exit 1
68                 ;;
69         4)
70                 reboot
71                 echo "reboot failed... help!"
72                 exit 1
73                 ;;
74         8)
75                 echo "Automatic file system check failed... help!"
76                 exit 1
77                 ;;
78         12)
79                 echo "Reboot interrupted"
80                 exit 1
81                 ;;
82         130)
83                 # interrupt before catcher installed
84                 exit 1
85                 ;;
86         *)
87                 echo "Unknown error in reboot"
88                 exit 1
89                 ;;
90         esac
91         ;;
92 *)
93         echo Skipping disk checks ...
94         ;;
95 esac
96
97 set -T
98 trap "echo 'Reboot interrupted'; exit 1" 3
99
100 # root normally must be read/write, but if this is a BOOTP NFS
101 # diskless boot it does not have to be.
102 #
103 case ${root_rw_mount} in
104 [Nn][Oo] | '')
105         ;;
106 *)
107         if ! mount -u -o rw / ; then
108                 echo "Mounting root filesystem rw failed, startup aborted"
109                 exit 1
110         fi
111         ;;
112 esac
113
114 umount -a >/dev/null 2>&1
115
116 # Mount everything except nfs filesystems.
117 mount -a -t nonfs
118
119 case $? in
120 0)
121         ;;
122 *)
123         echo "Mounting /etc/fstab filesystems failed, startup aborted"
124         exit 1
125         ;;
126 esac
127
128 # Run custom disk mounting function here
129 #
130 if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
131                 sh ${diskless_mount}
132 fi
133
134 adjkerntz -i
135
136 clean_var() {
137         if [ ! -f /var/run/clean_var ]; then
138                 rm -rf /var/run/*
139                 rm -f /var/spool/lock/*
140                 rm -rf /var/spool/uucp/.Temp/*
141                 # Keep a copy of the boot messages around
142                 dmesg >/var/run/dmesg.boot
143                 # And an initial utmp file
144                 (cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
145                 >/var/run/clean_var
146         fi
147 }
148
149 if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then
150         # network_pass1() *may* end up writing stuff to /var - we don't want to
151         # remove it immediately afterwards - *nor* to we want to fail to clean
152         # an nfs-mounted /var.
153         clean_var
154 fi
155
156 # Add additional swapfile, if configured.
157 #
158 case ${swapfile} in
159 [Nn][Oo] | '')
160         ;;
161 *)
162         if [ -w "${swapfile}" -a -c /dev/vn0b ]; then
163                 echo "Adding ${swapfile} as additional swap."
164                 vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b
165         fi
166         ;;
167 esac
168
169 # Set sysctl variables as early as we can
170 #
171 if [ -r /etc/rc.sysctl ]; then
172         . /etc/rc.sysctl
173 fi
174
175 # Configure serial devices
176 #
177 if [ -r /etc/rc.serial ]; then
178         . /etc/rc.serial
179 fi
180
181 # Start up PC-card configuration
182 #
183 if [ -r /etc/rc.pccard ]; then
184         . /etc/rc.pccard
185 fi
186
187 # Start up the initial network configuration.
188 #
189 if [ -r /etc/rc.network ]; then
190         . /etc/rc.network       # We only need to do this once.
191         network_pass1
192 fi
193
194 case ${ipv6_enable} in
195 [Yy][Ee][Ss])
196         if [ -r /etc/rc.network6 ]; then
197                 . /etc/rc.network6      # We only need to do this once also.
198                 network6_pass1
199         fi
200         ;;
201 esac
202
203 # Mount NFS filesystems.
204 echo -n "Mounting NFS file systems"
205 mount -a -t nfs
206 echo .
207
208 # Whack the pty perms back into shape.
209 #
210 chflags 0 /dev/tty[pqrsPQRS]*
211 chmod 666 /dev/tty[pqrsPQRS]*
212 chown root:wheel /dev/tty[pqrsPQRS]*
213
214 # Clean up left-over files
215 #
216 clean_var                       # If it hasn't already been done
217 rm /var/run/clean_var
218
219 # Clearing /tmp at boot-time seems to have a long tradition.  It doesn't
220 # help in any way for long-living systems, and it might accidentally
221 # clobber files you would rather like to have preserved after a crash
222 # (if not using mfs /tmp anyway).
223 #
224 # See also the example of another cleanup policy in /etc/periodic/daily.
225 #
226 case ${clear_tmp_enable} in
227 [Yy][Ee][Ss])
228         echo clearing /tmp
229         # prune quickly with one rm, then use find to clean up /tmp/[lq]*
230         # (not needed with mfs /tmp, but doesn't hurt there...)
231         (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
232                 find -d . ! -name . ! -name lost+found ! -name quota.user \
233                 ! -name quota.group -exec rm -rf -- {} \;)
234         ;;
235 esac
236
237 # Remove X lock files, since they will prevent you from restarting X11
238 # after a system crash.
239 #
240 rm -f /tmp/.X*-lock /tmp/.X11-unix/*
241
242 # Snapshot any kernel -c changes back to disk here <someday>.
243 # This has changed with ELF and /kernel.config.
244
245 echo -n 'additional daemons:'
246
247 # Start system logging and name service.  Named needs to start before syslogd
248 # if you don't have a /etc/resolv.conf.
249 #
250 case ${syslogd_enable} in
251 [Yy][Ee][Ss])
252         # Transitional symlink (for the next couple of years :) until all
253         # binaries have had a chance to move towards /var/run/log.
254         if [ ! -h /dev/log ]; then
255                 # might complain for r/o root f/s
256                 ln -sf /var/run/log /dev/log
257         fi
258
259         rm -f /var/run/log
260         echo -n ' syslogd';     syslogd ${syslogd_flags}
261         ;;
262 esac
263
264 echo '.'
265
266 # Enable dumpdev so that savecore can see it.
267 # /var/crash should be a directory or a symbolic link
268 # to the crash directory if core dumps are to be saved.
269 #
270 case ${dumpdev} in
271 [Nn][Oo] | '')
272         ;;
273 *)
274         if [ -e "${dumpdev}" -a -d /var/crash ]; then
275                 dumpon ${dumpdev}
276                 echo -n checking for core dump...
277                 savecore /var/crash
278         fi
279         ;;
280 esac
281
282 if [ -n "${network_pass1_done}" ]; then
283         network_pass2
284 fi
285
286 # Enable/Check the quotas (must be after ypbind if using NIS)
287 #
288 case ${enable_quotas} in
289 [Yy][Ee][Ss])
290         case ${check_quotas} in
291         [Yy][Ee][Ss])
292                 echo -n 'checking quotas:'
293                 quotacheck -a
294                 echo ' done.'
295                 ;;
296         esac
297
298         echo -n 'enabling quotas:'
299         quotaon -a
300         echo ' done.'
301         ;;
302 esac
303
304 if [ -n "${network_pass2_done}" ]; then
305         network_pass3
306 fi
307
308 # Build ps databases
309 #
310 dev_mkdb
311
312 # Check the password temp/lock file
313 #
314 if [ -e /etc/ptmp ]; then
315         logger -s -p auth.err \
316         "password file may be incorrect -- /etc/ptmp exists"
317 fi
318
319 case ${accounting_enable} in
320 [Yy][Ee][Ss])
321         if [ -d /var/account ]; then
322                 echo 'turning on accounting'
323                 if [ ! -e /var/account/acct ]; then
324                         touch /var/account/acct
325                 fi
326                 accton /var/account/acct
327         fi
328         ;;
329 esac
330
331 # Make shared lib searching a little faster.  Leave /usr/lib first if you
332 # add your own entries or you may come to grief.
333 #
334 if [ -x /sbin/ldconfig ]; then
335         case `/usr/bin/objformat` in
336         elf)
337                 _LDC=/usr/lib
338                 for i in ${ldconfig_paths}; do
339                         if [ -d "${i}" ]; then
340                                 _LDC="${_LDC} ${i}"
341                         fi
342                 done
343                 echo 'setting ELF ldconfig path:' ${_LDC}
344                 ldconfig -elf ${_LDC}
345                 ;;
346         esac
347
348         # Legacy aout support for i386 only
349         case `sysctl -n hw.machine` in
350         i386)
351                 # Default the a.out ldconfig path.
352                 : ${ldconfig_paths_aout=${ldconfig_paths}}
353                 _LDC=/usr/lib/aout
354                 for i in ${ldconfig_paths_aout}; do
355                         if [ -d "${i}" ]; then
356                                 _LDC="${_LDC} ${i}"
357                         fi
358                 done
359                 echo 'setting a.out ldconfig path:' ${_LDC}
360                 ldconfig -aout ${_LDC}
361                 ;;
362         esac
363 fi
364
365 # Now start up miscellaneous daemons that don't belong anywhere else
366 #
367 echo -n starting standard daemons:
368 case ${inetd_enable} in
369 [Nn][Oo])
370         ;;
371 *)
372         echo -n ' inetd';       inetd ${inetd_flags}
373         ;;
374 esac
375
376 case ${cron_enable} in
377 [Nn][Oo])
378         ;;
379 *)
380         echo -n ' cron';        cron
381         ;;
382 esac
383
384 case ${lpd_enable} in
385 [Yy][Ee][Ss])
386         echo -n ' printer';     ${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
387         ;;
388 esac
389
390 case ${sendmail_enable} in
391 [Yy][Ee][Ss])
392         if [ -r /etc/mail/sendmail.cf ]; then
393                 echo -n ' sendmail';    /usr/sbin/sendmail ${sendmail_flags}
394         fi
395         ;;
396 esac
397
398 case ${usbd_enable} in
399 [Yy][Ee][Ss])
400         echo -n ' usbd';        /usr/sbin/usbd ${usbd_flags}
401         ;;
402 esac
403
404 echo '.'
405
406 # Recover vi editor files.
407 find /var/tmp/vi.recover ! -type f -a ! -type d -delete
408 vibackup=`echo /var/tmp/vi.recover/vi.*`
409 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
410         echo 'Recovering vi editor sessions'
411         for i in /var/tmp/vi.recover/vi.*; do
412                 # Only test files that are readable.
413                 if [ ! -r "${i}" ]; then
414                         continue
415                 fi
416
417                 # Unmodified nvi editor backup files either have the
418                 # execute bit set or are zero length.  Delete them.
419                 if [ -x "${i}" -o ! -s "${i}" ]; then
420                         rm -f "${i}"
421                 fi
422         done
423
424         # It is possible to get incomplete recovery files, if the editor
425         # crashes at the right time.
426         virecovery=`echo /var/tmp/vi.recover/recover.*`
427         if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
428                 for i in /var/tmp/vi.recover/recover.*; do
429                         # Only test files that are readable.
430                         if [ ! -r "${i}" ]; then
431                                 continue
432                         fi
433
434                         # Delete any recovery files that are zero length,
435                         # corrupted, or that have no corresponding backup file.
436                         # Else send mail to the user.
437                         recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
438                         if [ -n "${recfile}" -a -s "${recfile}" ]; then
439                                 sendmail -t < "${i}"
440                         else
441                                 rm -f "${i}"
442                         fi
443                 done
444         fi
445 fi
446
447 # Make a bounds file for msgs(1) if there isn't one already
448 # "Delete important files with symlink" security hole?
449 #
450 if [ -d /var/msgs -a ! -f /var/msgs/bounds ]; then
451         echo 0 > /var/msgs/bounds
452 fi
453
454 case ${update_motd} in
455 [Nn][Oo] | '')
456         ;;
457 *)
458         if T=`mktemp /tmp/_motd.XXXXXX`; then
459                 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
460                 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
461                 cmp -s ${T} /etc/motd || {
462                         cp ${T} /etc/motd
463                         chmod 644 /etc/motd
464                 }
465                 rm -f ${T}
466         fi
467         ;;
468 esac
469
470 # Configure implementation specific stuff
471 #
472 arch=`uname -m`
473 if [ -r /etc/rc.${arch} ]; then
474         . /etc/rc.${arch}
475 fi
476
477 # Run rc.devfs if readable to customize devfs
478 #
479 if [ -r /etc/rc.devfs ]; then
480         sh /etc/rc.devfs
481 fi
482
483 # Do traditional (but rather obsolete) rc.local file if it exists.  If you
484 # use this file and want to make it programmatic, source /etc/defaults/rc.conf
485 # in /etc/rc.local and add your custom variables to /etc/rc.conf, as
486 # shown below.  Please do not put local extensions into /etc/rc itself.
487 # Use /etc/rc.local
488 #
489 # ---- rc.local ----
490 #       if [ -r /etc/defaults/rc.conf ]; then
491 #               . /etc/defaults/rc.conf
492 #       fi
493 #
494 #       ... additional startup conditionals ...
495 # ---- rc.local ----
496 #
497 if [ -r /etc/rc.local ]; then
498         echo -n 'starting local daemons:'
499         sh /etc/rc.local
500         echo '.'
501 fi
502
503 # For each valid dir in $local_startup, search for init scripts matching *.sh
504 #
505 case ${local_startup} in
506 [Nn][Oo] | '')
507         ;;
508 *)
509         echo -n 'Local package initialization:'
510         for dir in ${local_startup}; do
511                 if [ -d "${dir}" ]; then
512                         for script in ${dir}/*.sh; do
513                                 if [ -x "${script}" ]; then
514                                         (set -T
515                                          trap 'exit 1' 2
516                                          ${script} start)
517                                 fi
518                         done
519                 fi
520         done
521         echo .
522         ;;
523 esac
524
525 if [ -n "${network_pass3_done}" ]; then
526         network_pass4
527 fi
528
529 # Raise kernel security level.  This should be done only after `fsck' has
530 # repaired local file systems if you want the securelevel to be greater than 1.
531 #
532 case ${kern_securelevel_enable} in
533 [Yy][Ee][Ss])
534         if [ "${kern_securelevel}" -ge 0 ]; then
535                 echo 'Raising kernel security level'
536                 sysctl -w kern.securelevel=${kern_securelevel}
537         fi
538         ;;
539 esac
540
541 date
542 exit 0