rc revision 74075
1#!/bin/sh 2# 3# Copyright (c) 2000 The FreeBSD Project 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: head/etc/rc 74075 2001-03-10 13:45:28Z markm $ 28# From: @(#)rc 5.27 (Berkeley) 6/5/91 29# 30 31# System startup script run by init on autoboot 32# or after single-user. 33# Output and error are redirected to console by init, 34# and the console is the controlling terminal. 35 36# Note that almost all of the user-configurable behavior is no longer in 37# this file, but rather in /etc/defaults/rc.conf. Please check that file 38# first before contemplating any changes here. If you do need to change 39# this file for some reason, we would like to know about it. 40 41stty status '^T' 42 43# Set shell to ignore SIGINT (2), but not children; 44# shell catches SIGQUIT (3) and returns to single user after fsck. 45# 46trap : 2 47trap : 3 # shouldn't be needed 48 49bootmode=$1 50 51HOME=/ 52PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 53export HOME PATH 54 55# BOOTP diskless boot. We have to run the rc file early in order to 56# retarget various config files. 57# 58if [ -r /etc/rc.diskless1 ]; then 59 dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 60 if [ ${dlv:=0} != 0 ]; then 61 . /etc/rc.diskless1 62 fi 63fi 64 65# If there is a global system configuration file, suck it in. 66# 67if [ -r /etc/defaults/rc.conf ]; then 68 . /etc/defaults/rc.conf 69 source_rc_confs 70elif [ -r /etc/rc.conf ]; then 71 . /etc/rc.conf 72fi 73 74feed_dev_random() { 75 if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then 76 echo "Using ${1} as an entropy file" 77 cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null 78 fi 79} 80 81chkdepend() { 82 svc=$1 83 svc_var=$2 84 dep=$3 85 dep_var=$4 86 87 eval svc_val=\${$svc_var} 88 eval dep_val=\${$dep_var} 89 90 case ${svc_val} in 91 [Yy][Ee][Ss]) 92 case ${dep_val} in 93 [Yy][Ee][Ss]) 94 ;; 95 *) 96 eval ${dep_var}="YES" 97 echo "DEPENDENCY NOTE: ${dep} will be enabled" \ 98 "to support ${svc}" 99 ;; 100 esac 101 ;; 102 esac 103} 104 105chkdepend amd amd_enable portmap portmap_enable 106chkdepend NFS nfs_server_enable portmap portmap_enable 107chkdepend NIS nis_server_enable portmap portmap_enable 108chkdepend NIS nis_client_enable portmap portmap_enable 109 110# Enable harvesting of entropy via devices. The sooner this happens the 111# better so that we can take advantage of the boot process. 112# 113echo -n 'Entropy harvesting:' 114 115case ${harvest_interrupt} in 116[Nn][Oo]) 117 ;; 118*) 119 if [ -w /dev/random ]; then 120 /sbin/sysctl -w kern.random.sys.harvest.interrupt=1 >/dev/null 121 echo -n ' interrupts' 122 fi 123 ;; 124esac 125 126case ${harvest_ethernet} in 127[Nn][Oo]) 128 ;; 129*) 130 if [ -w /dev/random ]; then 131 /sbin/sysctl -w kern.random.sys.harvest.ethernet=1 >/dev/null 132 echo -n ' ethernet' 133 fi 134 ;; 135esac 136 137case ${harvest_p_to_p} in 138[Nn][Oo]) 139 ;; 140*) 141 if [ -w /dev/random ]; then 142 /sbin/sysctl -w kern.random.sys.harvest.point_to_point=1 >/dev/null 143 echo -n ' point_to_point' 144 fi 145 ;; 146esac 147 148echo '.' 149 150# First pass at reseeding /dev/random. 151# 152case ${entropy_file} in 153[Nn][Oo] | '') 154 ;; 155*) 156 if [ -w /dev/random ]; then 157 feed_dev_random "${entropy_file}" 158 fi 159 ;; 160esac 161 162# XXX temporary until we can get the entropy 163# harvesting rate up 164# Entropy below is not great, 165# but better than nothing. 166( ps -efauxww; sysctl -a; date; df -ib; dmesg; ps -efauxww; ) \ 167 | dd of=/dev/random bs=8k 2>/dev/null 168cat /bin/ls | dd of=/dev/random bs=8k 2>/dev/null 169 170# Configure ccd devices. 171# 172if [ -r /etc/ccd.conf ]; then 173 ccdconfig -C 174fi 175 176case ${start_vinum} in 177[Yy][Ee][Ss]) 178 vinum start 179 ;; 180esac 181 182swapon -a 183 184case ${bootmode} in 185autoboot) 186 echo 'Automatic boot in progress...' 187 fsck -p 188 case $? in 189 0) 190 ;; 191 2) 192 exit 1 193 ;; 194 4) 195 reboot 196 echo 'Reboot failed... help!' 197 exit 1 198 ;; 199 8) 200 case ${fsck_y_enable} in 201 [Yy][Ee][Ss]) 202 echo 'File system preen failed, trying fsck -y . . .' 203 fsck -y 204 case $? in 205 0) 206 ;; 207 *) 208 echo 'Automatic file system check failed . . . help!' 209 exit 1 210 ;; 211 esac 212 ;; 213 *) 214 echo 'Automatic file system check failed . . . help!' 215 exit 1 216 ;; 217 esac 218 ;; 219 12) 220 echo 'Reboot interrupted' 221 exit 1 222 ;; 223 130) 224 # interrupt before catcher installed 225 exit 1 226 ;; 227 *) 228 echo 'Unknown error in reboot' 229 exit 1 230 ;; 231 esac 232 ;; 233*) 234 echo 'Skipping disk checks ...' 235 ;; 236esac 237 238set -T 239trap "echo 'Reboot interrupted'; exit 1" 3 240 241# root normally must be read/write, but if this is a BOOTP NFS 242# diskless boot it does not have to be. 243# 244case ${root_rw_mount} in 245[Nn][Oo] | '') 246 ;; 247*) 248 if ! mount -u -o rw / ; then 249 echo 'Mounting root filesystem rw failed, startup aborted' 250 exit 1 251 fi 252 ;; 253esac 254 255umount -a >/dev/null 2>&1 256 257# Mount everything except nfs filesystems. 258mount -a -t nonfs 259 260case $? in 2610) 262 ;; 263*) 264 echo 'Mounting /etc/fstab filesystems failed, startup aborted' 265 exit 1 266 ;; 267esac 268 269# Run custom disk mounting function here 270# 271if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then 272 sh ${diskless_mount} 273fi 274 275# Reseed /dev/random with previously stored entropy. 276case ${entropy_dir} in 277[Nn][Oo]) 278 ;; 279*) 280 entropy_dir=${entropy_dir:-/var/db/entropy} 281 if [ -d "${entropy_dir}" ]; then 282 if [ -w /dev/random ]; then 283 for seedfile in ${entropy_dir}/*; do 284 feed_dev_random "${seedfile}" 285 done 286 fi 287 fi 288 ;; 289esac 290 291case ${entropy_file} in 292[Nn][Oo] | '') 293 ;; 294*) 295 if [ -w /dev/random ]; then 296 feed_dev_random "${entropy_file}" 297 fi 298 ;; 299esac 300 301adjkerntz -i 302 303purgedir() { 304 local dir file 305 306 if [ $# -eq 0 ]; then 307 purgedir . 308 else 309 for dir 310 do 311 ( 312 cd "$dir" && for file in .* * 313 do 314 [ ."$file" = .. -o ."$file" = ... ] && continue 315 [ -d "$file" -a ! -L "$file" ] && 316 purgedir "$file" 317 [ -f "$file" ] && rm -f -- "$file" 318 done 319 ) 320 done 321 fi 322} 323 324clean_var() { 325 if [ ! -f /var/run/clean_var ]; then 326 purgedir /var/run /var/spool/lock 327 rm -rf /var/spool/uucp/.Temp/* 328 # Keep a copy of the boot messages around 329 dmesg >/var/run/dmesg.boot 330 # And an initial utmp file 331 (cd /var/run && cp /dev/null utmp && chmod 644 utmp;) 332 >/var/run/clean_var 333 fi 334} 335 336if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then 337 # network_pass1() *may* end up writing stuff to /var - we don't want to 338 # remove it immediately afterwards - *nor* to we want to fail to clean 339 # an nfs-mounted /var. 340 clean_var 341fi 342 343# Add additional swapfile, if configured. 344# 345case ${swapfile} in 346[Nn][Oo] | '') 347 ;; 348*) 349 if [ -w "${swapfile}" -a -c /dev/vn0b ]; then 350 echo "Adding ${swapfile} as additional swap" 351 vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b 352 fi 353 ;; 354esac 355 356# Set sysctl variables as early as we can 357# 358if [ -r /etc/rc.sysctl ]; then 359 . /etc/rc.sysctl 360fi 361 362# Configure serial devices 363# 364if [ -r /etc/rc.serial ]; then 365 . /etc/rc.serial 366fi 367 368# Start up PC-card configuration 369# 370if [ -r /etc/rc.pccard ]; then 371 . /etc/rc.pccard 372fi 373 374# Start up the initial network configuration. 375# 376if [ -r /etc/rc.network ]; then 377 . /etc/rc.network # We only need to do this once. 378 network_pass1 379fi 380 381case ${ipv6_enable} in 382[Yy][Ee][Ss]) 383 if [ -r /etc/rc.network6 ]; then 384 . /etc/rc.network6 # We only need to do this once also. 385 network6_pass1 386 fi 387 ;; 388esac 389 390# Mount NFS filesystems if present in /etc/fstab 391case "`mount -d -a -t nfs`" in 392*mount_nfs*) 393 echo -n 'Mounting NFS file systems:' 394 mount -a -t nfs 395 echo '.' 396 ;; 397esac 398 399# Whack the pty perms back into shape. 400# 401if ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then 402 chflags 0 /dev/tty[pqrsPQRS]* 403 chmod 666 /dev/tty[pqrsPQRS]* 404 chown root:wheel /dev/tty[pqrsPQRS]* 405fi 406 407# Clean up left-over files 408# 409clean_var # If it hasn't already been done 410rm /var/run/clean_var 411 412# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 413# help in any way for long-living systems, and it might accidentally 414# clobber files you would rather like to have preserved after a crash 415# (if not using mfs /tmp anyway). 416# 417# See also the example of another cleanup policy in /etc/periodic/daily. 418# 419case ${clear_tmp_enable} in 420[Yy][Ee][Ss]) 421 echo -n 'Clearing /tmp:' 422 # prune quickly with one rm, then use find to clean up /tmp/[lq]* 423 # (not needed with mfs /tmp, but doesn't hurt there...) 424 (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 425 find -d . ! -name . ! -name lost+found ! -name quota.user \ 426 ! -name quota.group -exec rm -rf -- {} \;) 427 echo '.' 428 ;; 429esac 430 431# Remove X lock files, since they will prevent you from restarting X11 432# after a system crash. 433# 434rm -f /tmp/.X*-lock /tmp/.X11-unix/* 435 436# Snapshot any kernel -c changes back to disk here <someday>. 437# This has changed with ELF and /kernel.config. 438 439echo -n 'Additional daemons:' 440 441# Start system logging and name service. Named needs to start before syslogd 442# if you don't have a /etc/resolv.conf. 443# 444case ${syslogd_enable} in 445[Yy][Ee][Ss]) 446 # Transitional symlink (for the next couple of years :) until all 447 # binaries have had a chance to move towards /var/run/log. 448 if [ ! -h /dev/log ]; then 449 # might complain for r/o root f/s 450 ln -sf /var/run/log /dev/log 451 fi 452 453 rm -f /var/run/log 454 echo -n ' syslogd'; syslogd ${syslogd_flags} 455 ;; 456esac 457 458echo '.' 459 460# Build device name databases if we are not using DEVFS 461# 462if sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 463 rm -f /var/run/dev.db 464else 465 dev_mkdb 466fi 467 468# Enable dumpdev so that savecore can see it. 469# /var/crash should be a directory or a symbolic link 470# to the crash directory if core dumps are to be saved. 471# 472case ${dumpdev} in 473[Nn][Oo] | '') 474 ;; 475*) 476 if [ -e "${dumpdev}" -a -d /var/crash ]; then 477 dumpon -v ${dumpdev} 478 echo -n 'Checking for core dump: ' 479 savecore /var/crash 480 fi 481 ;; 482esac 483 484if [ -n "${network_pass1_done}" ]; then 485 network_pass2 486fi 487 488# Enable/Check the quotas (must be after ypbind if using NIS) 489# 490case ${enable_quotas} in 491[Yy][Ee][Ss]) 492 case ${check_quotas} in 493 [Yy][Ee][Ss]) 494 echo -n 'Checking quotas:' 495 quotacheck -a 496 echo ' done.' 497 ;; 498 esac 499 500 echo -n 'Enabling quotas:' 501 quotaon -a 502 echo ' done.' 503 ;; 504esac 505 506if [ -n "${network_pass2_done}" ]; then 507 network_pass3 508fi 509 510# Check the password temp/lock file 511# 512if [ -e /etc/ptmp ]; then 513 logger -s -p auth.err \ 514 "password file may be incorrect -- /etc/ptmp exists" 515fi 516 517case ${accounting_enable} in 518[Yy][Ee][Ss]) 519 if [ -d /var/account ]; then 520 echo 'Turning on accounting:' 521 if [ ! -e /var/account/acct ]; then 522 touch /var/account/acct 523 fi 524 accton /var/account/acct 525 fi 526 ;; 527esac 528 529# Make shared lib searching a little faster. Leave /usr/lib first if you 530# add your own entries or you may come to grief. 531# 532ldconfig="/sbin/ldconfig" 533case ${ldconfig_insecure} in 534[Yy][Ee][Ss]) 535 ldconfig="${ldconfig} -i" 536 ;; 537esac 538if [ -x /sbin/ldconfig ]; then 539 case `/usr/bin/objformat` in 540 elf) 541 _LDC=/usr/lib 542 for i in ${ldconfig_paths}; do 543 if [ -d "${i}" ]; then 544 _LDC="${_LDC} ${i}" 545 fi 546 done 547 echo 'ELF ldconfig path:' ${_LDC} 548 ${ldconfig} -elf ${_LDC} 549 ;; 550 esac 551 552 # Legacy aout support for i386 only 553 case `sysctl -n hw.machine` in 554 i386) 555 # Default the a.out ldconfig path. 556 : ${ldconfig_paths_aout=${ldconfig_paths}} 557 _LDC=/usr/lib/aout 558 for i in ${ldconfig_paths_aout}; do 559 if [ -d "${i}" ]; then 560 _LDC="${_LDC} ${i}" 561 fi 562 done 563 echo 'a.out ldconfig path:' ${_LDC} 564 ${ldconfig} -aout ${_LDC} 565 ;; 566 esac 567fi 568 569# Now start up miscellaneous daemons that don't belong anywhere else 570# 571echo -n 'Starting standard daemons:' 572case ${inetd_enable} in 573[Nn][Oo]) 574 ;; 575*) 576 echo -n ' inetd'; inetd ${inetd_flags} 577 ;; 578esac 579 580case ${cron_enable} in 581[Nn][Oo]) 582 ;; 583*) 584 echo -n ' cron'; ${cron_program:-/usr/sbin/cron} ${cron_flags} 585 ;; 586esac 587 588case ${lpd_enable} in 589[Yy][Ee][Ss]) 590 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags} 591 ;; 592esac 593 594case ${sendmail_enable} in 595[Yy][Ee][Ss]) 596 if [ -r /etc/mail/sendmail.cf ]; then 597 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 598 fi 599 ;; 600esac 601 602case ${sshd_enable} in 603[Yy][Ee][Ss]) 604 if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then 605 echo -n ' sshd'; 606 ${sshd_program:-/usr/sbin/sshd} ${sshd_flags} 607 fi 608 ;; 609esac 610 611case ${usbd_enable} in 612[Yy][Ee][Ss]) 613 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 614 ;; 615esac 616 617echo '.' 618 619# Recover vi editor files. 620find /var/tmp/vi.recover ! -type f -a ! -type d -delete 621vibackup=`echo /var/tmp/vi.recover/vi.*` 622if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 623 echo -n 'Recovering vi editor sessions:' 624 for i in /var/tmp/vi.recover/vi.*; do 625 # Only test files that are readable. 626 if [ ! -r "${i}" ]; then 627 continue 628 fi 629 630 # Unmodified nvi editor backup files either have the 631 # execute bit set or are zero length. Delete them. 632 if [ -x "${i}" -o ! -s "${i}" ]; then 633 rm -f "${i}" 634 fi 635 done 636 637 # It is possible to get incomplete recovery files, if the editor 638 # crashes at the right time. 639 virecovery=`echo /var/tmp/vi.recover/recover.*` 640 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 641 for i in /var/tmp/vi.recover/recover.*; do 642 # Only test files that are readable. 643 if [ ! -r "${i}" ]; then 644 continue 645 fi 646 647 # Delete any recovery files that are zero length, 648 # corrupted, or that have no corresponding backup file. 649 # Else send mail to the user. 650 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 651 if [ -n "${recfile}" -a -s "${recfile}" ]; then 652 sendmail -t < "${i}" 653 else 654 rm -f "${i}" 655 fi 656 done 657 fi 658 echo '.' 659fi 660 661# Make a bounds file for msgs(1) if there isn't one already 662# 663if [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then 664 echo 0 > /var/msgs/bounds 665fi 666 667case ${update_motd} in 668[Nn][Oo] | '') 669 ;; 670*) 671 if T=`mktemp /tmp/_motd.XXXXXX`; then 672 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T} 673 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T} 674 cmp -s ${T} /etc/motd || { 675 cp ${T} /etc/motd 676 chmod 644 /etc/motd 677 } 678 rm -f ${T} 679 fi 680 ;; 681esac 682 683# Configure implementation specific stuff 684# 685arch=`uname -m` 686if [ -r /etc/rc.${arch} ]; then 687 . /etc/rc.${arch} 688fi 689 690# Configure the system console 691# 692if [ -r /etc/rc.syscons ]; then 693 . /etc/rc.syscons 694fi 695 696# Run rc.devfs if readable to customize devfs 697# 698if [ -r /etc/rc.devfs ]; then 699 sh /etc/rc.devfs 700fi 701 702echo -n 'Additional ABI support:' 703 704# Load the SysV IPC API if requested. 705case ${sysvipc_enable} in 706[Yy][Ee][Ss]) 707 echo -n ' sysvipc' 708 kldload sysvmsg >/dev/null 2>&1 709 kldload sysvsem >/dev/null 2>&1 710 kldload sysvshm >/dev/null 2>&1 711 ;; 712esac 713 714# Start the Linux binary compatibility if requested. 715# 716case ${linux_enable} in 717[Yy][Ee][Ss]) 718 echo -n ' linux' 719 if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then 720 kldload linux > /dev/null 2>&1 721 fi 722 if [ -x /compat/linux/sbin/ldconfig ]; then 723 /compat/linux/sbin/ldconfig 724 fi 725 ;; 726esac 727 728# Start the SysVR4 binary emulation if requested. 729# 730case ${svr4_enable} in 731[Yy][Ee][Ss]) 732 echo -n ' svr4'; kldload svr4 > /dev/null 2>&1 733 ;; 734esac 735 736echo '.' 737 738# Do traditional (but rather obsolete) rc.local file if it exists. If you 739# use this file and want to make it programmatic, source /etc/defaults/rc.conf 740# in /etc/rc.local and add your custom variables to /etc/rc.conf, as 741# shown below. Please do not put local extensions into /etc/rc itself. 742# Use /etc/rc.local 743# 744# ---- rc.local ---- 745# if [ -r /etc/defaults/rc.conf ]; then 746# . /etc/defaults/rc.conf 747# source_rc_confs 748# elif [ -r /etc/rc.conf ]; then 749# . /etc/rc.conf 750# fi 751# 752# ... additional startup conditionals ... 753# ---- rc.local ---- 754# 755if [ -r /etc/rc.local ]; then 756 echo -n 'Starting local daemons:' 757 sh /etc/rc.local 758 echo '.' 759fi 760 761# For each valid dir in $local_startup, search for init scripts matching *.sh 762# 763case ${local_startup} in 764[Nn][Oo] | '') 765 ;; 766*) 767 echo -n 'Local package initialization:' 768 for dir in ${local_startup}; do 769 if [ -d "${dir}" ]; then 770 for script in ${dir}/*.sh; do 771 if [ -x "${script}" ]; then 772 (set -T 773 trap 'exit 1' 2 774 ${script} start) 775 fi 776 done 777 fi 778 done 779 echo '.' 780 ;; 781esac 782 783if [ -n "${network_pass3_done}" ]; then 784 network_pass4 785fi 786 787# Raise kernel security level. This should be done only after `fsck' has 788# repaired local file systems if you want the securelevel to be greater than 1. 789# 790case ${kern_securelevel_enable} in 791[Yy][Ee][Ss]) 792 if [ "${kern_securelevel}" -ge 0 ]; then 793 echo 'Raising kernel security level: ' 794 sysctl -w kern.securelevel=${kern_securelevel} 795 fi 796 ;; 797esac 798 799echo '' 800 801date 802 803exit 0 804 805