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