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