3 # Copyright (c) 2000 The FreeBSD Project
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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
27 # @(#)rc 5.27 (Berkeley) 6/5/91
28 # $FreeBSD: src/etc/rc,v 1.212.2.51 2002/10/17 17:25:07 schweikh Exp $
29 # $DragonFly: src/etc/rc,v 1.2 2003/06/17 04:24:45 dillon Exp $
32 # System startup script run by init on autoboot
33 # or after single-user.
34 # Output and error are redirected to console by init,
35 # and the console is the controlling terminal.
37 # Note that almost all of the user-configurable behavior is no longer in
38 # this file, but rather in /etc/defaults/rc.conf. Please check that file
39 # first before contemplating any changes here. If you do need to change
40 # this file for some reason, we would like to know about it.
44 # Set shell to ignore SIGINT (2), but not children;
45 # shell catches SIGQUIT (3) and returns to single user after fsck.
48 trap : 3 # shouldn't be needed
53 PATH=/sbin:/bin:/usr/sbin:/usr/bin
56 # BOOTP diskless boot. We have to run the rc file early in order to
57 # retarget various config files.
58 # See /usr/share/examples/diskless/clone_root for details on how
59 # to setup diskless on the client and the server.
61 if [ -r /etc/rc.diskless1 ]; then
62 dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null`
63 if [ ${dlv:=0} != 0 ]; then
68 # If there is a global system configuration file, suck it in.
70 if [ -r /etc/defaults/rc.conf ]; then
71 . /etc/defaults/rc.conf
73 elif [ -r /etc/rc.conf ]; then
83 eval svc_val=\${$svc_var}
84 eval dep_val=\${$dep_var}
93 echo "DEPENDENCY NOTE: ${dep} will be enabled" \
101 chkdepend amd amd_enable portmap portmap_enable
102 chkdepend amd amd_enable NFS nfs_client_enable
103 chkdepend NFS nfs_server_enable portmap portmap_enable
104 chkdepend NIS nis_server_enable portmap portmap_enable
105 chkdepend NIS nis_client_enable portmap portmap_enable
107 # Enable dumpdev early so that a crash during the boot process can be caught.
114 /sbin/dumpon -v ${dumpdev}
118 # Configure ccd devices.
120 if [ -r /etc/ccd.conf ]; then
124 case ${start_vinum} in
132 # Last chance to do things before potentially waiting for
133 # operator to do fsck related tasks
134 if [ -r /etc/rc.early ]; then
140 echo 'Automatic boot in progress...'
150 echo 'Reboot failed... help!'
154 case ${fsck_y_enable} in
156 echo 'File system preen failed, trying fsck -y . . .'
162 echo 'Automatic file system check failed . . . help!'
168 echo 'Automatic file system check failed . . . help!'
174 echo 'Reboot interrupted'
178 # interrupt before catcher installed
182 echo 'Unknown error in reboot'
188 echo 'Skipping disk checks ...'
193 trap "echo 'Reboot interrupted'; exit 1" 3
195 # root normally must be read/write, but if this is a BOOTP NFS
196 # diskless boot it does not have to be.
198 case ${root_rw_mount} in
202 if ! mount -u -o rw /; then
203 echo 'Mounting root filesystem rw failed, startup aborted'
209 umount -a >/dev/null 2>&1
211 # If using diskless, run custom disk mounting function here
213 if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then
216 # otherwise mount everything except nfs filesystems.
224 echo 'Mounting /etc/fstab filesystems failed, startup aborted'
234 if [ $# -eq 0 ]; then
240 cd "$dir" && for file in .* *
242 [ ."$file" = .. -o ."$file" = ... ] && continue
243 if [ -d "$file" -a ! -L "$file" ]; then
255 if [ -d /var/run -a ! -f /var/run/clean_var ]; then
257 # Keep a copy of the boot messages around
258 dmesg >/var/run/dmesg.boot
259 # And an initial utmp file
260 (cd /var/run && cp /dev/null utmp && chmod 644 utmp;)
263 if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then
264 purgedir /var/spool/lock
265 >/var/spool/lock/clean_var
267 rm -rf /var/spool/uucp/.Temp/*
270 # network_pass1() *may* end up writing stuff to /var - we don't want to
271 # remove it immediately afterwards - *nor* do we want to fail to clean
272 # an NFS-mounted /var.
273 rm -f /var/run/clean_var /var/spool/lock/clean_var
276 # Add additional swapfile, if configured.
282 if [ -w "${swapfile}" -a -c /dev/vn0b ]; then
283 echo "Adding ${swapfile} as additional swap"
284 vnconfig -e /dev/vn0b ${swapfile} swap
289 # Early pass to set the variables we can
291 if [ -r /etc/rc.sysctl ]; then
292 sh /etc/rc.sysctl first
295 # Configure serial devices
297 if [ -r /etc/rc.serial ]; then
301 # Start up PC-card configuration
303 if [ -r /etc/rc.pccard ]; then
307 # Start up the initial network configuration.
309 if [ -r /etc/rc.network ]; then
310 . /etc/rc.network # We only need to do this once.
314 case ${ipv6_enable} in
316 if [ -r /etc/rc.network6 ]; then
317 . /etc/rc.network6 # We only need to do this once also.
323 # Mount NFS filesystems if present in /etc/fstab
325 case "`mount -d -a -t nfs 2> /dev/null`" in
327 echo -n 'Mounting NFS file systems:'
333 # If we booted a special kernel remove the record so we will boot
334 # the default kernel next time
336 rm -f /boot/nextboot.conf
338 # Whack the pty perms back into shape.
340 if ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then
341 chflags 0 /dev/tty[pqrsPQRS]*
342 chmod 666 /dev/tty[pqrsPQRS]*
343 chown root:wheel /dev/tty[pqrsPQRS]*
346 # Clean up left-over files
348 clean_var # If it hasn't already been done
349 rm /var/run/clean_var /var/spool/lock/clean_var
351 # Clearing /tmp at boot-time seems to have a long tradition. It doesn't
352 # help in any way for long-living systems, and it might accidentally
353 # clobber files you would rather like to have preserved after a crash
354 # (if not using mfs /tmp anyway).
356 # See also the example of another cleanup policy in /etc/periodic/daily.
358 case ${clear_tmp_enable} in
360 echo -n 'Clearing /tmp:'
361 # prune quickly with one rm, then use find to clean up /tmp/[lq]*
362 # (not needed with mfs /tmp, but doesn't hurt there...)
363 (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
364 find -d . ! -name . ! -name lost+found ! -name quota.user \
365 ! -name quota.group -exec rm -rf -- {} \;)
370 # Remove X lock files, since they will prevent you from restarting X11
371 # after a system crash.
374 rm -fr /tmp/.X11-unix
375 mkdir -m 1777 /tmp/.X11-unix
377 # Snapshot any kernel -c changes back to disk here <someday>.
378 # This has changed with ELF and /kernel.config.
380 echo -n 'Additional daemons:'
382 # Start system logging and name service. Named needs to start before syslogd
383 # if you don't have a /etc/resolv.conf.
385 case ${syslogd_enable} in
387 # Transitional symlink (for the next couple of years :) until all
388 # binaries have had a chance to move towards /var/run/log.
389 if [ ! -L /dev/log ]; then
390 # might complain for r/o root f/s
391 ln -sf /var/run/log /dev/log
396 ${syslogd_program:-/usr/sbin/syslogd} ${syslogd_flags}
402 # Build devices database
406 # $dumpdir should be a directory or a symbolic link
407 # to the crash directory if core dumps are to be saved.
409 if [ "${dumpdev}" != 'NO' ]; then
419 if [ "${dumpdir}" != 'NO' ]; then
420 echo -n 'Checking for core dump: '
421 /sbin/savecore ${savecore_flags} "${dumpdir}"
425 if [ -n "${network_pass1_done}" ]; then
429 # Enable/Check the quotas (must be after ypbind if using NIS)
431 case ${enable_quotas} in
433 case ${check_quotas} in
435 echo -n 'Checking quotas:'
441 echo -n 'Enabling quotas:'
447 if [ -n "${network_pass2_done}" ]; then
451 # Check the password temp/lock file
453 if [ -e /etc/ptmp ]; then
454 logger -s -p auth.err \
455 "password file may be incorrect -- /etc/ptmp exists"
458 case ${accounting_enable} in
460 if [ -d /var/account ]; then
461 echo 'Turning on accounting:'
462 if [ ! -e /var/account/acct ]; then
463 touch /var/account/acct
465 accton /var/account/acct
470 # Make shared lib searching a little faster. Leave /usr/lib first if you
471 # add your own entries or you may come to grief.
473 ldconfig="/sbin/ldconfig"
474 case ${ldconfig_insecure} in
476 ldconfig="${ldconfig} -i"
479 if [ -x /sbin/ldconfig ]; then
480 case `/usr/bin/objformat` in
483 for i in ${ldconfig_paths}; do
484 if [ -d "${i}" ]; then
488 echo 'ELF ldconfig path:' ${_LDC}
489 ${ldconfig} -elf ${_LDC}
493 # Legacy aout support for i386 only
494 case `sysctl -n hw.machine_arch` in
496 # Default the a.out ldconfig path.
497 : ${ldconfig_paths_aout=${ldconfig_paths}}
499 for i in ${ldconfig_paths_aout}; do
500 if [ -d "${i}" ]; then
504 echo 'a.out ldconfig path:' ${_LDC}
505 ${ldconfig} -aout ${_LDC}
510 # Now start up miscellaneous daemons that don't belong anywhere else
512 echo -n 'Starting standard daemons:'
513 case ${inetd_enable} in
517 echo -n ' inetd'; ${inetd_program:-/usr/sbin/inetd} ${inetd_flags}
521 case ${cron_enable} in
525 echo -n ' cron'; ${cron_program:-/usr/sbin/cron} ${cron_flags}
529 case ${lpd_enable} in
531 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags}
535 case ${sshd_enable} in
537 if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then
539 ${sshd_program:-/usr/sbin/sshd} ${sshd_flags}
544 case ${usbd_enable} in
546 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags}
550 case ${mta_start_script} in
552 if [ -r ${mta_start_script} ]; then
553 sh ${mta_start_script}
560 # Recover vi editor files.
561 find /var/tmp/vi.recover ! -type f -a ! -type d -delete
562 vibackup=`echo /var/tmp/vi.recover/vi.*`
563 if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then
564 echo -n 'Recovering vi editor sessions:'
565 for i in /var/tmp/vi.recover/vi.*; do
566 # Only test files that are readable.
567 if [ ! -r "${i}" ]; then
571 # Unmodified nvi editor backup files either have the
572 # execute bit set or are zero length. Delete them.
573 if [ -x "${i}" -o ! -s "${i}" ]; then
578 # It is possible to get incomplete recovery files, if the editor
579 # crashes at the right time.
580 virecovery=`echo /var/tmp/vi.recover/recover.*`
581 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then
582 for i in /var/tmp/vi.recover/recover.*; do
583 # Only test files that are readable.
584 if [ ! -r "${i}" ]; then
588 # Delete any recovery files that are zero length,
589 # corrupted, or that have no corresponding backup file.
590 # Else send mail to the user.
591 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"`
592 if [ -n "${recfile}" -a -s "${recfile}" ]; then
602 # Make a bounds file for msgs(1) if there isn't one already
604 if [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then
605 echo 0 > /var/msgs/bounds
608 case ${update_motd} in
612 if T=`mktemp /tmp/_motd.XXXXXX`; then
613 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T}
614 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T}
615 cmp -s ${T} /etc/motd || {
624 # Configure implementation specific stuff
627 if [ -r /etc/rc.${arch} ]; then
631 # Configure the system console
633 if [ -r /etc/rc.syscons ]; then
637 echo -n 'Additional ABI support:'
639 # Start the Linux binary compatibility if requested.
641 case ${linux_enable} in
644 if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then
645 kldload linux > /dev/null 2>&1
647 if [ -x /compat/linux/sbin/ldconfig ]; then
648 /compat/linux/sbin/ldconfig
653 # Start the SysVR4 binary emulation if requested.
655 case ${svr4_enable} in
658 kldload streams > /dev/null 2>&1
659 kldload svr4 > /dev/null 2>&1
665 # Do traditional (but rather obsolete) rc.local file if it exists. If you
666 # use this file and want to make it programmatic, source /etc/defaults/rc.conf
667 # in /etc/rc.local and add your custom variables to /etc/rc.conf, as
668 # shown below. Please do not put local extensions into /etc/rc itself.
672 # if [ -r /etc/defaults/rc.conf ]; then
673 # . /etc/defaults/rc.conf
675 # elif [ -r /etc/rc.conf ]; then
679 # ... additional startup conditionals ...
682 if [ -r /etc/rc.local ]; then
683 echo -n 'Starting local daemons:'
688 # For each valid dir in $local_startup, search for init scripts matching *.sh
690 case ${local_startup} in
694 echo -n 'Local package initialization:'
696 if [ -z "${script_name_sep}" ]; then
699 for dir in ${local_startup}; do
700 if [ -d "${dir}" ]; then
701 for script in ${dir}/*.sh; do
702 slist="${slist}${script_name_sep}${script}"
706 script_save_sep="$IFS"
707 IFS="${script_name_sep}"
708 for script in ${slist}; do
709 if [ -x "${script}" ]; then
713 elif [ -f "${script}" -o -L "${script}" ]; then
714 echo -n " (skipping ${script##*/}, not executable)"
717 IFS="${script_save_sep}"
722 if [ -n "${network_pass3_done}" ]; then
726 # Late pass to set variables we missed the first time
728 if [ -r /etc/rc.sysctl ]; then
729 sh /etc/rc.sysctl last
732 # Raise kernel security level. This should be done only after `fsck' has
733 # repaired local file systems if you want the securelevel to be greater than 1.
735 case ${kern_securelevel_enable} in
737 if [ "${kern_securelevel}" -ge 0 ]; then
738 echo 'Raising kernel security level: '
739 sysctl kern.securelevel=${kern_securelevel}