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