rc revision 63311
1#!/bin/sh 2# $FreeBSD: head/etc/rc 63311 2000-07-17 13:39:48Z 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} ]; 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 151clean_var() { 152 if [ ! -f /var/run/clean_var ]; then 153 rm -rf /var/run/* 154 find /var/spool/lock ! -type d -delete 155 rm -rf /var/spool/uucp/.Temp/* 156 # Keep a copy of the boot messages around 157 dmesg >/var/run/dmesg.boot 158 # And an initial utmp file 159 (cd /var/run && cp /dev/null utmp && chmod 644 utmp;) 160 >/var/run/clean_var 161 fi 162} 163 164if [ -d /var/run -a -d /var/spool/lock -a -d /var/spool/uucp/.Temp ]; then 165 # network_pass1() *may* end up writing stuff to /var - we don't want to 166 # remove it immediately afterwards - *nor* to we want to fail to clean 167 # an nfs-mounted /var. 168 clean_var 169fi 170 171# Add additional swapfile, if configured. 172# 173case ${swapfile} in 174[Nn][Oo] | '') 175 ;; 176*) 177 if [ -w "${swapfile}" -a -c /dev/vn0b ]; then 178 echo "Adding ${swapfile} as additional swap." 179 vnconfig /dev/vn0b ${swapfile} && swapon /dev/vn0b 180 fi 181 ;; 182esac 183 184# Set sysctl variables as early as we can 185# 186if [ -r /etc/rc.sysctl ]; then 187 . /etc/rc.sysctl 188fi 189 190# Configure serial devices 191# 192if [ -r /etc/rc.serial ]; then 193 . /etc/rc.serial 194fi 195 196# Start up PC-card configuration 197# 198if [ -r /etc/rc.pccard ]; then 199 . /etc/rc.pccard 200fi 201 202# Start up the initial network configuration. 203# 204if [ -r /etc/rc.network ]; then 205 . /etc/rc.network # We only need to do this once. 206 network_pass1 207fi 208 209case ${ipv6_enable} in 210[Yy][Ee][Ss]) 211 if [ -r /etc/rc.network6 ]; then 212 . /etc/rc.network6 # We only need to do this once also. 213 network6_pass1 214 fi 215 ;; 216esac 217 218# Mount NFS filesystems if present in /etc/fstab 219case "`mount -d -a -t nfs`" in 220*mount_nfs*) 221 echo -n "Mounting NFS file systems" 222 mount -a -t nfs 223 echo . 224 ;; 225esac 226 227# Whack the pty perms back into shape. 228# 229chflags 0 /dev/tty[pqrsPQRS]* 230chmod 666 /dev/tty[pqrsPQRS]* 231chown root:wheel /dev/tty[pqrsPQRS]* 232 233# Clean up left-over files 234# 235clean_var # If it hasn't already been done 236rm /var/run/clean_var 237 238# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 239# help in any way for long-living systems, and it might accidentally 240# clobber files you would rather like to have preserved after a crash 241# (if not using mfs /tmp anyway). 242# 243# See also the example of another cleanup policy in /etc/periodic/daily. 244# 245case ${clear_tmp_enable} in 246[Yy][Ee][Ss]) 247 echo clearing /tmp 248 # prune quickly with one rm, then use find to clean up /tmp/[lq]* 249 # (not needed with mfs /tmp, but doesn't hurt there...) 250 (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 251 find -d . ! -name . ! -name lost+found ! -name quota.user \ 252 ! -name quota.group -exec rm -rf -- {} \;) 253 ;; 254esac 255 256# Remove X lock files, since they will prevent you from restarting X11 257# after a system crash. 258# 259rm -f /tmp/.X*-lock /tmp/.X11-unix/* 260 261# Snapshot any kernel -c changes back to disk here <someday>. 262# This has changed with ELF and /kernel.config. 263 264echo -n 'additional daemons:' 265 266# Start system logging and name service. Named needs to start before syslogd 267# if you don't have a /etc/resolv.conf. 268# 269case ${syslogd_enable} in 270[Yy][Ee][Ss]) 271 # Transitional symlink (for the next couple of years :) until all 272 # binaries have had a chance to move towards /var/run/log. 273 if [ ! -h /dev/log ]; then 274 # might complain for r/o root f/s 275 ln -sf /var/run/log /dev/log 276 fi 277 278 rm -f /var/run/log 279 echo -n ' syslogd'; syslogd ${syslogd_flags} 280 ;; 281esac 282 283echo '.' 284 285# Enable dumpdev so that savecore can see it. 286# /var/crash should be a directory or a symbolic link 287# to the crash directory if core dumps are to be saved. 288# 289case ${dumpdev} in 290[Nn][Oo] | '') 291 ;; 292*) 293 if [ -e "${dumpdev}" -a -d /var/crash ]; then 294 dumpon ${dumpdev} 295 echo -n checking for core dump... 296 savecore /var/crash 297 fi 298 ;; 299esac 300 301if [ -n "${network_pass1_done}" ]; then 302 network_pass2 303fi 304 305# Enable/Check the quotas (must be after ypbind if using NIS) 306# 307case ${enable_quotas} in 308[Yy][Ee][Ss]) 309 case ${check_quotas} in 310 [Yy][Ee][Ss]) 311 echo -n 'checking quotas:' 312 quotacheck -a 313 echo ' done.' 314 ;; 315 esac 316 317 echo -n 'enabling quotas:' 318 quotaon -a 319 echo ' done.' 320 ;; 321esac 322 323if [ -n "${network_pass2_done}" ]; then 324 network_pass3 325fi 326 327# Build ps databases 328# 329dev_mkdb 330 331# Check the password temp/lock file 332# 333if [ -e /etc/ptmp ]; then 334 logger -s -p auth.err \ 335 "password file may be incorrect -- /etc/ptmp exists" 336fi 337 338case ${accounting_enable} in 339[Yy][Ee][Ss]) 340 if [ -d /var/account ]; then 341 echo 'turning on accounting' 342 if [ ! -e /var/account/acct ]; then 343 touch /var/account/acct 344 fi 345 accton /var/account/acct 346 fi 347 ;; 348esac 349 350# Make shared lib searching a little faster. Leave /usr/lib first if you 351# add your own entries or you may come to grief. 352# 353if [ -x /sbin/ldconfig ]; then 354 case `/usr/bin/objformat` in 355 elf) 356 _LDC=/usr/lib 357 for i in ${ldconfig_paths}; do 358 if [ -d "${i}" ]; then 359 _LDC="${_LDC} ${i}" 360 fi 361 done 362 echo 'setting ELF ldconfig path:' ${_LDC} 363 ldconfig -elf ${_LDC} 364 ;; 365 esac 366 367 # Legacy aout support for i386 only 368 case `sysctl -n hw.machine` in 369 i386) 370 # Default the a.out ldconfig path. 371 : ${ldconfig_paths_aout=${ldconfig_paths}} 372 _LDC=/usr/lib/aout 373 for i in ${ldconfig_paths_aout}; do 374 if [ -d "${i}" ]; then 375 _LDC="${_LDC} ${i}" 376 fi 377 done 378 echo 'setting a.out ldconfig path:' ${_LDC} 379 ldconfig -aout ${_LDC} 380 ;; 381 esac 382fi 383 384# Now start up miscellaneous daemons that don't belong anywhere else 385# 386echo -n starting standard daemons: 387case ${inetd_enable} in 388[Nn][Oo]) 389 ;; 390*) 391 echo -n ' inetd'; inetd ${inetd_flags} 392 ;; 393esac 394 395case ${cron_enable} in 396[Nn][Oo]) 397 ;; 398*) 399 echo -n ' cron'; cron 400 ;; 401esac 402 403case ${lpd_enable} in 404[Yy][Ee][Ss]) 405 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags} 406 ;; 407esac 408 409case ${sendmail_enable} in 410[Yy][Ee][Ss]) 411 if [ -r /etc/mail/sendmail.cf ]; then 412 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 413 fi 414 ;; 415esac 416 417case ${sshd_enable} in 418[Yy][Ee][Ss]) 419 if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then 420 echo -n ' sshd'; 421 ${sshd_program:-/usr/sbin/sshd} ${sshd_flags} 422 fi 423 ;; 424esac 425 426case ${usbd_enable} in 427[Yy][Ee][Ss]) 428 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 429 ;; 430esac 431 432echo '.' 433 434# Recover vi editor files. 435find /var/tmp/vi.recover ! -type f -a ! -type d -delete 436vibackup=`echo /var/tmp/vi.recover/vi.*` 437if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 438 echo 'Recovering vi editor sessions' 439 for i in /var/tmp/vi.recover/vi.*; do 440 # Only test files that are readable. 441 if [ ! -r "${i}" ]; then 442 continue 443 fi 444 445 # Unmodified nvi editor backup files either have the 446 # execute bit set or are zero length. Delete them. 447 if [ -x "${i}" -o ! -s "${i}" ]; then 448 rm -f "${i}" 449 fi 450 done 451 452 # It is possible to get incomplete recovery files, if the editor 453 # crashes at the right time. 454 virecovery=`echo /var/tmp/vi.recover/recover.*` 455 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 456 for i in /var/tmp/vi.recover/recover.*; do 457 # Only test files that are readable. 458 if [ ! -r "${i}" ]; then 459 continue 460 fi 461 462 # Delete any recovery files that are zero length, 463 # corrupted, or that have no corresponding backup file. 464 # Else send mail to the user. 465 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 466 if [ -n "${recfile}" -a -s "${recfile}" ]; then 467 sendmail -t < "${i}" 468 else 469 rm -f "${i}" 470 fi 471 done 472 fi 473fi 474 475# Make a bounds file for msgs(1) if there isn't one already 476# "Delete important files with symlink" security hole? 477# 478if [ -d /var/msgs -a ! -f /var/msgs/bounds ]; then 479 echo 0 > /var/msgs/bounds 480fi 481 482case ${update_motd} in 483[Nn][Oo] | '') 484 ;; 485*) 486 if T=`mktemp /tmp/_motd.XXXXXX`; then 487 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T} 488 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T} 489 cmp -s ${T} /etc/motd || { 490 cp ${T} /etc/motd 491 chmod 644 /etc/motd 492 } 493 rm -f ${T} 494 fi 495 ;; 496esac 497 498# Configure implementation specific stuff 499# 500arch=`uname -m` 501if [ -r /etc/rc.${arch} ]; then 502 . /etc/rc.${arch} 503fi 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# source_rc_confs 521# elif [ -r /etc/rc.conf ]; then 522# . /etc/rc.conf 523# fi 524# 525# ... additional startup conditionals ... 526# ---- rc.local ---- 527# 528if [ -r /etc/rc.local ]; then 529 echo -n 'starting local daemons:' 530 sh /etc/rc.local 531 echo '.' 532fi 533 534# For each valid dir in $local_startup, search for init scripts matching *.sh 535# 536case ${local_startup} in 537[Nn][Oo] | '') 538 ;; 539*) 540 echo -n 'Local package initialization:' 541 for dir in ${local_startup}; do 542 if [ -d "${dir}" ]; then 543 for script in ${dir}/*.sh; do 544 if [ -x "${script}" ]; then 545 (set -T 546 trap 'exit 1' 2 547 ${script} start) 548 fi 549 done 550 fi 551 done 552 echo . 553 ;; 554esac 555 556if [ -n "${network_pass3_done}" ]; then 557 network_pass4 558fi 559 560# Raise kernel security level. This should be done only after `fsck' has 561# repaired local file systems if you want the securelevel to be greater than 1. 562# 563case ${kern_securelevel_enable} in 564[Yy][Ee][Ss]) 565 if [ "${kern_securelevel}" -ge 0 ]; then 566 echo 'Raising kernel security level' 567 sysctl -w kern.securelevel=${kern_securelevel} 568 fi 569 ;; 570esac 571 572date 573exit 0 574