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