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