rc revision 63793
1243830Sdim#!/bin/sh 2226584Sdim# $FreeBSD: head/etc/rc 63793 2000-07-24 13:40:41Z sheldonh $ 3226584Sdim# From: @(#)rc 5.27 (Berkeley) 6/5/91 4226584Sdim 5226584Sdim# System startup script run by init on autoboot 6226584Sdim# or after single-user. 7226584Sdim# Output and error are redirected to console by init, 8226584Sdim# and the console is the controlling terminal. 9226584Sdim 10226584Sdim# Note that almost all of the user-configurable behavior is no longer in 11226584Sdim# this file, but rather in /etc/defaults/rc.conf. Please check that file 12226584Sdim# first before contemplating any changes here. If you do need to change 13226584Sdim# this file for some reason, we would like to know about it. 14251662Sdim 15249423Sdimstty status '^T' 16226584Sdim 17226584Sdim# Set shell to ignore SIGINT (2), but not children; 18226584Sdim# shell catches SIGQUIT (3) and returns to single user after fsck. 19226584Sdim# 20226584Sdimtrap : 2 21226584Sdimtrap : 3 # shouldn't be needed 22226584Sdim 23226584SdimHOME=/ 24226584SdimPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 25226584Sdimexport HOME PATH 26226584Sdim 27226584Sdim# BOOTP diskless boot. We have to run the rc file early in order to 28226584Sdim# retarget various config files. 29226584Sdim# 30234353Sdimif [ -r /etc/rc.diskless1 ]; then 31226584Sdim dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 32226584Sdim if [ ${dlv:=0} != 0 ]; then 33226584Sdim . /etc/rc.diskless1 34226584Sdim fi 35226584Sdimfi 36226584Sdim 37226584Sdim# If there is a global system configuration file, suck it in. 38226584Sdim# 39226584Sdimif [ -r /etc/defaults/rc.conf ]; then 40226584Sdim . /etc/defaults/rc.conf 41226584Sdim source_rc_confs 42226584Sdimelif [ -r /etc/rc.conf ]; then 43249423Sdim . /etc/rc.conf 44226584Sdimfi 45226584Sdim 46226584Sdim# Configure ccd devices. 47226584Sdim# 48226584Sdimif [ -r /etc/ccd.conf ]; then 49226584Sdim ccdconfig -C 50226584Sdimfi 51226584Sdim 52226584Sdimcase ${start_vinum} in 53226584Sdim[Yy][Ee][Ss]) 54226584Sdim vinum start 55226584Sdim ;; 56226584Sdimesac 57226584Sdim 58226584Sdimswapon -a 59226584Sdim 60226584Sdimcase $1 in 61226584Sdimautoboot) 62226584Sdim echo Automatic boot in progress... 63226584Sdim fsck -p 64226584Sdim case $? in 65226584Sdim 0) 66226584Sdim ;; 67226584Sdim 2) 68226584Sdim exit 1 69226584Sdim ;; 70226584Sdim 4) 71226584Sdim reboot 72226584Sdim echo "reboot failed... help!" 73226584Sdim exit 1 74226584Sdim ;; 75226584Sdim 8) 76226584Sdim echo "Automatic file system check failed... help!" 77226584Sdim exit 1 78226584Sdim ;; 79226584Sdim 12) 80226584Sdim echo "Reboot interrupted" 81226584Sdim exit 1 82226584Sdim ;; 83226584Sdim 130) 84226584Sdim # interrupt before catcher installed 85226584Sdim exit 1 86226584Sdim ;; 87226584Sdim *) 88226584Sdim echo "Unknown error in reboot" 89226584Sdim exit 1 90226584Sdim ;; 91226584Sdim esac 92226584Sdim ;; 93226584Sdim*) 94226584Sdim echo Skipping disk checks ... 95226584Sdim ;; 96226584Sdimesac 97251662Sdim 98251662Sdimset -T 99251662Sdimtrap "echo 'Reboot interrupted'; exit 1" 3 100251662Sdim 101251662Sdim# root normally must be read/write, but if this is a BOOTP NFS 102251662Sdim# diskless boot it does not have to be. 103251662Sdim# 104251662Sdimcase ${root_rw_mount} in 105251662Sdim[Nn][Oo] | '') 106251662Sdim ;; 107251662Sdim*) 108251662Sdim if ! mount -u -o rw / ; then 109251662Sdim echo "Mounting root filesystem rw failed, startup aborted" 110251662Sdim exit 1 111226584Sdim fi 112251662Sdim ;; 113251662Sdimesac 114251662Sdim 115226584Sdimumount -a >/dev/null 2>&1 116251662Sdim 117251662Sdim# Mount everything except nfs filesystems. 118251662Sdimmount -a -t nonfs 119251662Sdim 120251662Sdimcase $? in 121251662Sdim0) 122251662Sdim ;; 123251662Sdim*) 124251662Sdim echo "Mounting /etc/fstab filesystems failed, startup aborted" 125251662Sdim exit 1 126251662Sdim ;; 127251662Sdimesac 128226584Sdim 129226584Sdim# Run custom disk mounting function here 130251662Sdim# 131226584Sdimif [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then 132226584Sdim sh ${diskless_mount} 133226584Sdimfi 134251662Sdim 135251662Sdim# Recover some entropy so the rebooting /dev/random can reseed 136251662Sdim# 137251662Sdimcase ${entropy_file} in 138251662Sdim[Nn][Oo] | '') 139251662Sdim ;; 140251662Sdim*) 141251662Sdim if [ -f ${entropy_file} -a -r ${entropy_file} -a -w /dev/random ]; then 142251662Sdim echo "Reading entropy file" 143251662Sdim if ! cat ${entropy_file} 2>/dev/null >/dev/random; then 144251662Sdim if ! kldstat -n randomdev >/dev/null 2>&1; then 145251662Sdim kldload randomdev && \ 146251662Sdim cat ${entropy_file} 2>/dev/null >/dev/random 147251662Sdim fi 148251662Sdim fi 149251662Sdim if [ $? != 0 ]; then 150251662Sdim echo "Writing entropy file to /dev/random failed" 151251662Sdim fi 152251662Sdim rm -f ${entropy_file} 153251662Sdim fi 154251662Sdim ;; 155251662Sdimesac 156226584Sdim 157251662Sdimadjkerntz -i 158251662Sdim 159251662Sdimclean_var() { 160251662Sdim if [ ! -f /var/run/clean_var ]; then 161226584Sdim rm -rf /var/run/* 162251662Sdim find /var/spool/lock ! -type d -delete 163251662Sdim rm -rf /var/spool/uucp/.Temp/* 164251662Sdim # Keep a copy of the boot messages around 165251662Sdim dmesg >/var/run/dmesg.boot 166251662Sdim # And an initial utmp file 167251662Sdim (cd /var/run && cp /dev/null utmp && chmod 644 utmp;) 168251662Sdim >/var/run/clean_var 169226584Sdim fi 170251662Sdim} 171251662Sdim 172251662Sdimif [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then 173251662Sdim # network_pass1() *may* end up writing stuff to /var - we don't want to 174251662Sdim # remove it immediately afterwards - *nor* to we want to fail to clean 175226584Sdim # an nfs-mounted /var. 176226584Sdim clean_var 177251662Sdimfi 178226584Sdim 179226584Sdim# Add additional swapfile, if configured. 180243830Sdim# 181243830Sdimcase ${swapfile} in 182243830Sdim[Nn][Oo] | '') 183243830Sdim ;; 184243830Sdim*) 185243830Sdim if [ -w "${swapfile}" -a -c /dev/vn0b ]; then 186243830Sdim echo "Adding ${swapfile} as additional swap." 187243830Sdim vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b 188243830Sdim fi 189243830Sdim ;; 190226584Sdimesac 191226584Sdim 192226584Sdim# Set sysctl variables as early as we can 193226584Sdim# 194226584Sdimif [ -r /etc/rc.sysctl ]; then 195226584Sdim . /etc/rc.sysctl 196226584Sdimfi 197226584Sdim 198226584Sdim# Configure serial devices 199226584Sdim# 200226584Sdimif [ -r /etc/rc.serial ]; then 201226584Sdim . /etc/rc.serial 202226584Sdimfi 203226584Sdim 204226584Sdim# Start up PC-card configuration 205226584Sdim# 206226584Sdimif [ -r /etc/rc.pccard ]; then 207226584Sdim . /etc/rc.pccard 208226584Sdimfi 209226584Sdim 210226584Sdim# Start up the initial network configuration. 211226584Sdim# 212226584Sdimif [ -r /etc/rc.network ]; then 213226584Sdim . /etc/rc.network # We only need to do this once. 214226584Sdim network_pass1 215226584Sdimfi 216226584Sdim 217226584Sdimcase ${ipv6_enable} in 218226584Sdim[Yy][Ee][Ss]) 219226584Sdim if [ -r /etc/rc.network6 ]; then 220226584Sdim . /etc/rc.network6 # We only need to do this once also. 221226584Sdim network6_pass1 222226584Sdim fi 223226584Sdim ;; 224226584Sdimesac 225226584Sdim 226226584Sdim# Mount NFS filesystems if present in /etc/fstab 227243830Sdimcase "`mount -d -a -t nfs`" in 228243830Sdim*mount_nfs*) 229243830Sdim echo -n "Mounting NFS file systems" 230243830Sdim mount -a -t nfs 231226584Sdim echo . 232226584Sdim ;; 233249423Sdimesac 234226584Sdim 235226584Sdim# Whack the pty perms back into shape. 236226584Sdim# 237226584Sdimchflags 0 /dev/tty[pqrsPQRS]* 238226584Sdimchmod 666 /dev/tty[pqrsPQRS]* 239226584Sdimchown root:wheel /dev/tty[pqrsPQRS]* 240226584Sdim 241243830Sdim# Clean up left-over files 242243830Sdim# 243243830Sdimclean_var # If it hasn't already been done 244226584Sdimrm /var/run/clean_var 245226584Sdim 246226584Sdim# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 247226584Sdim# help in any way for long-living systems, and it might accidentally 248226584Sdim# clobber files you would rather like to have preserved after a crash 249226584Sdim# (if not using mfs /tmp anyway). 250226584Sdim# 251226584Sdim# See also the example of another cleanup policy in /etc/periodic/daily. 252243830Sdim# 253243830Sdimcase ${clear_tmp_enable} in 254243830Sdim[Yy][Ee][Ss]) 255226584Sdim echo clearing /tmp 256226584Sdim # prune quickly with one rm, then use find to clean up /tmp/[lq]* 257226584Sdim # (not needed with mfs /tmp, but doesn't hurt there...) 258226584Sdim (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 259226584Sdim find -d . ! -name . ! -name lost+found ! -name quota.user \ 260226584Sdim ! -name quota.group -exec rm -rf -- {} \;) 261226584Sdim ;; 262226584Sdimesac 263243830Sdim 264243830Sdim# Remove X lock files, since they will prevent you from restarting X11 265243830Sdim# after a system crash. 266243830Sdim# 267226584Sdimrm -f /tmp/.X*-lock /tmp/.X11-unix/* 268226584Sdim 269226584Sdim# Snapshot any kernel -c changes back to disk here <someday>. 270226584Sdim# This has changed with ELF and /kernel.config. 271226584Sdim 272226584Sdimecho -n 'additional daemons:' 273243830Sdim 274243830Sdim# Start system logging and name service. Named needs to start before syslogd 275243830Sdim# if you don't have a /etc/resolv.conf. 276243830Sdim# 277243830Sdimcase ${syslogd_enable} in 278243830Sdim[Yy][Ee][Ss]) 279243830Sdim # Transitional symlink (for the next couple of years :) until all 280243830Sdim # binaries have had a chance to move towards /var/run/log. 281243830Sdim if [ ! -h /dev/log ]; then 282243830Sdim # might complain for r/o root f/s 283226584Sdim ln -sf /var/run/log /dev/log 284243830Sdim fi 285243830Sdim 286226584Sdim rm -f /var/run/log 287226584Sdim echo -n ' syslogd'; syslogd ${syslogd_flags} 288243830Sdim ;; 289243830Sdimesac 290243830Sdim 291243830Sdimecho '.' 292243830Sdim 293243830Sdim# Enable dumpdev so that savecore can see it. 294226584Sdim# /var/crash should be a directory or a symbolic link 295226584Sdim# to the crash directory if core dumps are to be saved. 296226584Sdim# 297226584Sdimcase ${dumpdev} in 298243830Sdim[Nn][Oo] | '') 299226584Sdim ;; 300226584Sdim*) 301226584Sdim if [ -e "${dumpdev}" -a -d /var/crash ]; then 302226584Sdim dumpon ${dumpdev} 303239462Sdim echo -n checking for core dump... 304239462Sdim savecore /var/crash 305239462Sdim fi 306243830Sdim ;; 307243830Sdimesac 308243830Sdim 309243830Sdimif [ -n "${network_pass1_done}" ]; then 310243830Sdim network_pass2 311243830Sdimfi 312243830Sdim 313243830Sdim# Enable/Check the quotas (must be after ypbind if using NIS) 314243830Sdim# 315243830Sdimcase ${enable_quotas} in 316243830Sdim[Yy][Ee][Ss]) 317243830Sdim case ${check_quotas} in 318243830Sdim [Yy][Ee][Ss]) 319243830Sdim echo -n 'checking quotas:' 320239462Sdim quotacheck -a 321239462Sdim echo ' done.' 322239462Sdim ;; 323239462Sdim esac 324239462Sdim 325243830Sdim echo -n 'enabling quotas:' 326243830Sdim quotaon -a 327243830Sdim echo ' done.' 328239462Sdim ;; 329239462Sdimesac 330239462Sdim 331243830Sdimif [ -n "${network_pass2_done}" ]; then 332239462Sdim network_pass3 333243830Sdimfi 334239462Sdim 335243830Sdim# Build ps databases 336239462Sdim# 337239462Sdimdev_mkdb 338239462Sdim 339243830Sdim# Check the password temp/lock file 340239462Sdim# 341239462Sdimif [ -e /etc/ptmp ]; then 342243830Sdim logger -s -p auth.err \ 343243830Sdim "password file may be incorrect -- /etc/ptmp exists" 344239462Sdimfi 345239462Sdim 346239462Sdimcase ${accounting_enable} in 347239462Sdim[Yy][Ee][Ss]) 348239462Sdim if [ -d /var/account ]; then 349243830Sdim echo 'turning on accounting' 350239462Sdim if [ ! -e /var/account/acct ]; then 351239462Sdim touch /var/account/acct 352243830Sdim fi 353243830Sdim accton /var/account/acct 354239462Sdim fi 355239462Sdim ;; 356239462Sdimesac 357239462Sdim 358239462Sdim# Make shared lib searching a little faster. Leave /usr/lib first if you 359243830Sdim# add your own entries or you may come to grief. 360243830Sdim# 361243830Sdimif [ -x /sbin/ldconfig ]; then 362243830Sdim case `/usr/bin/objformat` in 363243830Sdim elf) 364243830Sdim _LDC=/usr/lib 365243830Sdim for i in ${ldconfig_paths}; do 366243830Sdim if [ -d "${i}" ]; then 367243830Sdim _LDC="${_LDC} ${i}" 368243830Sdim fi 369243830Sdim done 370243830Sdim echo 'setting ELF ldconfig path:' ${_LDC} 371243830Sdim ldconfig -elf ${_LDC} 372243830Sdim ;; 373243830Sdim esac 374243830Sdim 375243830Sdim # Legacy aout support for i386 only 376243830Sdim case `sysctl -n hw.machine` in 377243830Sdim i386) 378243830Sdim # Default the a.out ldconfig path. 379243830Sdim : ${ldconfig_paths_aout=${ldconfig_paths}} 380243830Sdim _LDC=/usr/lib/aout 381243830Sdim for i in ${ldconfig_paths_aout}; do 382243830Sdim if [ -d "${i}" ]; then 383243830Sdim _LDC="${_LDC} ${i}" 384243830Sdim fi 385243830Sdim done 386243830Sdim echo 'setting a.out ldconfig path:' ${_LDC} 387243830Sdim ldconfig -aout ${_LDC} 388243830Sdim ;; 389243830Sdim esac 390243830Sdimfi 391243830Sdim 392243830Sdim# Now start up miscellaneous daemons that don't belong anywhere else 393243830Sdim# 394243830Sdimecho -n starting standard daemons: 395243830Sdimcase ${inetd_enable} in 396243830Sdim[Nn][Oo]) 397243830Sdim ;; 398*) 399 echo -n ' inetd'; inetd ${inetd_flags} 400 ;; 401esac 402 403case ${cron_enable} in 404[Nn][Oo]) 405 ;; 406*) 407 echo -n ' cron'; cron 408 ;; 409esac 410 411case ${lpd_enable} in 412[Yy][Ee][Ss]) 413 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags} 414 ;; 415esac 416 417case ${sendmail_enable} in 418[Yy][Ee][Ss]) 419 if [ -r /etc/mail/sendmail.cf ]; then 420 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 421 fi 422 ;; 423esac 424 425case ${sshd_enable} in 426[Yy][Ee][Ss]) 427 if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then 428 echo -n ' sshd'; 429 ${sshd_program:-/usr/sbin/sshd} ${sshd_flags} 430 fi 431 ;; 432esac 433 434case ${usbd_enable} in 435[Yy][Ee][Ss]) 436 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 437 ;; 438esac 439 440echo '.' 441 442# Recover vi editor files. 443find /var/tmp/vi.recover ! -type f -a ! -type d -delete 444vibackup=`echo /var/tmp/vi.recover/vi.*` 445if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 446 echo 'Recovering vi editor sessions' 447 for i in /var/tmp/vi.recover/vi.*; do 448 # Only test files that are readable. 449 if [ ! -r "${i}" ]; then 450 continue 451 fi 452 453 # Unmodified nvi editor backup files either have the 454 # execute bit set or are zero length. Delete them. 455 if [ -x "${i}" -o ! -s "${i}" ]; then 456 rm -f "${i}" 457 fi 458 done 459 460 # It is possible to get incomplete recovery files, if the editor 461 # crashes at the right time. 462 virecovery=`echo /var/tmp/vi.recover/recover.*` 463 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 464 for i in /var/tmp/vi.recover/recover.*; do 465 # Only test files that are readable. 466 if [ ! -r "${i}" ]; then 467 continue 468 fi 469 470 # Delete any recovery files that are zero length, 471 # corrupted, or that have no corresponding backup file. 472 # Else send mail to the user. 473 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 474 if [ -n "${recfile}" -a -s "${recfile}" ]; then 475 sendmail -t < "${i}" 476 else 477 rm -f "${i}" 478 fi 479 done 480 fi 481fi 482 483# Make a bounds file for msgs(1) if there isn't one already 484# "Delete important files with symlink" security hole? 485# 486if [ -d /var/msgs -a ! -f /var/msgs/bounds ]; then 487 echo 0 > /var/msgs/bounds 488fi 489 490case ${update_motd} in 491[Nn][Oo] | '') 492 ;; 493*) 494 if T=`mktemp /tmp/_motd.XXXXXX`; then 495 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T} 496 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T} 497 cmp -s ${T} /etc/motd || { 498 cp ${T} /etc/motd 499 chmod 644 /etc/motd 500 } 501 rm -f ${T} 502 fi 503 ;; 504esac 505 506# Configure implementation specific stuff 507# 508arch=`uname -m` 509if [ -r /etc/rc.${arch} ]; then 510 . /etc/rc.${arch} 511fi 512 513# Run rc.devfs if readable to customize devfs 514# 515if [ -r /etc/rc.devfs ]; then 516 sh /etc/rc.devfs 517fi 518 519# Do traditional (but rather obsolete) rc.local file if it exists. If you 520# use this file and want to make it programmatic, source /etc/defaults/rc.conf 521# in /etc/rc.local and add your custom variables to /etc/rc.conf, as 522# shown below. Please do not put local extensions into /etc/rc itself. 523# Use /etc/rc.local 524# 525# ---- rc.local ---- 526# if [ -r /etc/defaults/rc.conf ]; then 527# . /etc/defaults/rc.conf 528# source_rc_confs 529# elif [ -r /etc/rc.conf ]; then 530# . /etc/rc.conf 531# fi 532# 533# ... additional startup conditionals ... 534# ---- rc.local ---- 535# 536if [ -r /etc/rc.local ]; then 537 echo -n 'starting local daemons:' 538 sh /etc/rc.local 539 echo '.' 540fi 541 542# For each valid dir in $local_startup, search for init scripts matching *.sh 543# 544case ${local_startup} in 545[Nn][Oo] | '') 546 ;; 547*) 548 echo -n 'Local package initialization:' 549 for dir in ${local_startup}; do 550 if [ -d "${dir}" ]; then 551 for script in ${dir}/*.sh; do 552 if [ -x "${script}" ]; then 553 (set -T 554 trap 'exit 1' 2 555 ${script} start) 556 fi 557 done 558 fi 559 done 560 echo . 561 ;; 562esac 563 564if [ -n "${network_pass3_done}" ]; then 565 network_pass4 566fi 567 568# Raise kernel security level. This should be done only after `fsck' has 569# repaired local file systems if you want the securelevel to be greater than 1. 570# 571case ${kern_securelevel_enable} in 572[Yy][Ee][Ss]) 573 if [ "${kern_securelevel}" -ge 0 ]; then 574 echo 'Raising kernel security level' 575 sysctl -w kern.securelevel=${kern_securelevel} 576 fi 577 ;; 578esac 579 580date 581exit 0 582