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