rc revision 55453
190075Sobrien#!/bin/sh 2132718Skan# $FreeBSD: head/etc/rc 55453 2000-01-05 09:19:27Z peter $ 390075Sobrien# From: @(#)rc 5.27 (Berkeley) 6/5/91 490075Sobrien 590075Sobrien# System startup script run by init on autoboot 690075Sobrien# or after single-user. 790075Sobrien# Output and error are redirected to console by init, 890075Sobrien# and the console is the controlling terminal. 990075Sobrien 1090075Sobrien# Note that almost all of the user-configurable behavior is no longer in 1190075Sobrien# this file, but rather in /etc/defaults/rc.conf. Please check that file 1290075Sobrien# first before contemplating any changes here. If you do need to change 1390075Sobrien# this file for some reason, we would like to know about it. 1490075Sobrien 1590075Sobrienstty status '^T' 1690075Sobrien 1790075Sobrien# Set shell to ignore SIGINT (2), but not children; 1890075Sobrien# shell catches SIGQUIT (3) and returns to single user after fsck. 1990075Sobrien# 2090075Sobrientrap : 2 2190075Sobrientrap : 3 # shouldn't be needed 2290075Sobrien 2390075SobrienHOME=/ 2490075SobrienPATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin 2590075Sobrienexport HOME PATH 26132718Skan 27132718Skan# BOOTP diskless boot. We have to run the rc file early in order to 2890075Sobrien# retarget various config files. 2990075Sobrien# 3090075Sobrienif [ -r /etc/rc.diskless1 ]; then 3190075Sobrien dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 3290075Sobrien if [ ${dlv:=0} != 0 ]; then 3390075Sobrien . /etc/rc.diskless1 3490075Sobrien fi 3590075Sobrienfi 3690075Sobrien 3790075Sobrien# If there is a global system configuration file, suck it in. 3890075Sobrien# 3990075Sobrienif [ -r /etc/defaults/rc.conf ]; then 4090075Sobrien . /etc/defaults/rc.conf 4190075Sobrienelif [ -r /etc/rc.conf ]; then 42117395Skan . /etc/rc.conf 43132718Skanfi 4490075Sobrien 4590075Sobrien# Configure ccd devices. 46132718Skan# 47132718Skanif [ -r /etc/ccd.conf ]; then 4890075Sobrien ccdconfig -C 4990075Sobrienfi 5090075Sobrien 5190075Sobriencase ${start_vinum} in 5290075Sobrien[Yy][Ee][Ss]) 5390075Sobrien vinum start 5490075Sobrien ;; 5590075Sobrienesac 5690075Sobrien 5790075Sobrienswapon -a 5890075Sobrien 59132718Skancase $1 in 6090075Sobrienautoboot) 6190075Sobrien echo Automatic reboot in progress... 6290075Sobrien fsck -p 6390075Sobrien case $? in 6490075Sobrien 0) 6590075Sobrien ;; 6690075Sobrien 2) 6790075Sobrien exit 1 6890075Sobrien ;; 6990075Sobrien 4) 7090075Sobrien reboot 7190075Sobrien echo "reboot failed... help!" 7290075Sobrien exit 1 7390075Sobrien ;; 7490075Sobrien 8) 7590075Sobrien echo "Automatic file system check failed... help!" 7690075Sobrien exit 1 7790075Sobrien ;; 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# Early NFS mounts and clean up of /var/db/mounttab. 117# 118case ${early_nfs_mounts} in 119[Yy][Ee][Ss]) 120 case $1 in 121 autoboot) 122 if [ -f /var/db/mounttab ]; then 123 rpc.umntall -k 124 fi 125 ;; 126 esac 127 mount -a 128 ;; 129*) 130 mount -a -t nonfs 131 ;; 132esac 133 134case $? in 1350) 136 ;; 137*) 138 echo "Mounting /etc/fstab filesystems failed, startup aborted" 139 exit 1 140 ;; 141esac 142 143# Run custom disk mounting function here 144# 145if [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then 146 sh ${diskless_mount} 147fi 148 149adjkerntz -i 150 151clean_var() { 152 if [ ! -f /var/run/clean_var ]; then 153 rm -rf /var/run/* 154 rm -f /var/spool/lock/* 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 -b /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 209# Only mount NFS file systems if $early_nfs_mounts is false. 210# If there is a /var/db/mounttab, clean it up with rpc.umntall. 211# 212echo -n "Mounting NFS file systems" 213case ${early_nfs_mounts} in 214[Yy][Ee][Ss]) 215 ;; 216*) 217 case $1 in 218 autoboot) 219 case ${nfs_client_enable} in 220 [Yy][Ee][Ss]) 221 if [ -f /var/db/mounttab ]; then 222 rpc.umntall -k 223 fi 224 ;; 225 esac 226 ;; 227 esac 228 mount -a -t nfs 229 ;; 230esac 231echo . 232 233# Whack the pty perms back into shape. 234# 235chflags 0 /dev/tty[pqrsPQRS]* 236chmod 666 /dev/tty[pqrsPQRS]* 237chown root:wheel /dev/tty[pqrsPQRS]* 238 239# Clean up left-over files 240# 241clean_var # If it hasn't already been done 242rm /var/run/clean_var 243 244# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 245# help in any way for long-living systems, and it might accidentally 246# clobber files you would rather like to have preserved after a crash 247# (if not using mfs /tmp anyway). 248# 249# See also the example of another cleanup policy in /etc/periodic/daily. 250# 251case ${clear_tmp_enable} in 252[Yy][Ee][Ss]) 253 echo clearing /tmp 254 # prune quickly with one rm, then use find to clean up /tmp/[lq]* 255 # (not needed with mfs /tmp, but doesn't hurt there...) 256 (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 257 find -d . ! -name . ! -name lost+found ! -name quota.user \ 258 ! -name quota.group -exec rm -rf -- {} \;) 259 ;; 260esac 261 262# Remove X lock files, since they will prevent you from restarting X11 263# after a system crash. 264# 265rm -f /tmp/.X*-lock /tmp/.X11-unix/* 266 267# Snapshot any kernel -c changes back to disk here <someday>. 268# This has changed with ELF and /kernel.config. 269 270echo -n 'additional daemons:' 271 272# Start system logging and name service. Named needs to start before syslogd 273# if you don't have a /etc/resolv.conf. 274# 275case ${syslogd_enable} in 276[Yy][Ee][Ss]) 277 # Transitional symlink (for the next couple of years :) until all 278 # binaries have had a chance to move towards /var/run/log. 279 if [ ! -h /dev/log ]; then 280 # might complain for r/o root f/s 281 ln -sf /var/run/log /dev/log 282 fi 283 284 rm -f /var/run/log 285 echo -n ' syslogd'; syslogd ${syslogd_flags} 286 ;; 287esac 288 289echo '.' 290 291# Enable dumpdev so that savecore can see it. 292# /var/crash should be a directory or a symbolic link 293# to the crash directory if core dumps are to be saved. 294# 295case ${dumpdev} in 296[Nn][Oo] | '') 297 ;; 298*) 299 if [ -e "${dumpdev}" -a -d /var/crash ]; then 300 dumpon ${dumpdev} 301 echo -n checking for core dump... 302 savecore /var/crash 303 fi 304 ;; 305esac 306 307if [ -n "${network_pass1_done}" ]; then 308 network_pass2 309fi 310 311# Enable/Check the quotas (must be after ypbind if using NIS) 312# 313case ${enable_quotas} in 314[Yy][Ee][Ss]) 315 case ${check_quotas} in 316 [Yy][Ee][Ss]) 317 echo -n 'checking quotas:' 318 quotacheck -a 319 echo ' done.' 320 ;; 321 esac 322 323 echo -n 'enabling quotas:' 324 quotaon -a 325 echo ' done.' 326 ;; 327esac 328 329if [ -n "${network_pass2_done}" ]; then 330 network_pass3 331fi 332 333# Build ps databases 334# 335dev_mkdb 336 337# Check the password temp/lock file 338# 339if [ -e /etc/ptmp ]; then 340 logger -s -p auth.err \ 341 "password file may be incorrect -- /etc/ptmp exists" 342fi 343 344case ${accounting_enable} in 345[Yy][Ee][Ss]) 346 if [ -d /var/account ]; then 347 echo 'turning on accounting' 348 if [ ! -e /var/account/acct ]; then 349 touch /var/account/acct 350 fi 351 accton /var/account/acct 352 fi 353 ;; 354esac 355 356# Make shared lib searching a little faster. Leave /usr/lib first if you 357# add your own entries or you may come to grief. 358# 359if [ -x /sbin/ldconfig ]; then 360 case `/usr/bin/objformat` in 361 elf) 362 _LDC=/usr/lib 363 for i in ${ldconfig_paths}; do 364 if [ -d "${i}" ]; then 365 _LDC="${_LDC} ${i}" 366 fi 367 done 368 echo 'setting ELF ldconfig path:' ${_LDC} 369 ldconfig -elf ${_LDC} 370 ;; 371 esac 372 373 # Legacy aout support for i386 only 374 case `sysctl -n hw.machine` in 375 i386) 376 # Default the a.out ldconfig path. 377 : ${ldconfig_paths_aout=${ldconfig_paths}} 378 _LDC=/usr/lib/aout 379 for i in ${ldconfig_paths_aout}; do 380 if [ -d "${i}" ]; then 381 _LDC="${_LDC} ${i}" 382 fi 383 done 384 echo 'setting a.out ldconfig path:' ${_LDC} 385 ldconfig -aout ${_LDC} 386 ;; 387 esac 388fi 389 390# Now start up miscellaneous daemons that don't belong anywhere else 391# 392echo -n starting standard daemons: 393case ${inetd_enable} in 394[Nn][Oo]) 395 ;; 396*) 397 echo -n ' inetd'; inetd ${inetd_flags} 398 ;; 399esac 400 401case ${cron_enable} in 402[Nn][Oo]) 403 ;; 404*) 405 echo -n ' cron'; cron 406 ;; 407esac 408 409case ${lpd_enable} in 410[Yy][Ee][Ss]) 411 echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags} 412 ;; 413esac 414 415case ${sendmail_enable} in 416[Yy][Ee][Ss]) 417 if [ -r /etc/mail/sendmail.cf ]; then 418 echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags} 419 fi 420 ;; 421esac 422 423case ${usbd_enable} in 424[Yy][Ee][Ss]) 425 echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 426 ;; 427esac 428 429echo '.' 430 431# Recover vi editor files. 432find /var/tmp/vi.recover ! -type f -a ! -type d -delete 433vibackup=`echo /var/tmp/vi.recover/vi.*` 434if [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 435 echo 'Recovering vi editor sessions' 436 for i in ${vibackup}; do 437 # Only test files that are readable. 438 if [ ! -r "${i}" ]; then 439 continue 440 fi 441 442 # Unmodified nvi editor backup files either have the 443 # execute bit set or are zero length. Delete them. 444 if [ -x "${i}" -o ! -s "${i}" ]; then 445 rm -f "${i}" 446 fi 447 done 448 449 # It is possible to get incomplete recovery files, if the editor 450 # crashes at the right time. 451 virecovery=`echo /var/tmp/vi.recover/recover.*` 452 if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 453 for i in ${virecovery}; do 454 # Only test files that are readable. 455 if [ ! -r "${i}" ]; then 456 continue 457 fi 458 459 # Delete any recovery files that are zero length, 460 # corrupted, or that have no corresponding backup file. 461 # Else send mail to the user. 462 recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 463 if [ -n "${recfile}" -a -s "${recfile}" ]; then 464 sendmail -t < "${i}" 465 else 466 rm -f "${i}" 467 fi 468 done 469 fi 470fi 471 472# Make a bounds file for msgs(1) if there isn't one already 473# "Delete important files with symlink" security hole? 474# 475if [ -d /var/msgs -a ! -f /var/msgs/bounds ]; then 476 echo 0 > /var/msgs/bounds 477fi 478 479case ${update_motd} in 480[Nn][Oo] | '') 481 ;; 482*) 483 if T=`mktemp /tmp/_motd.XXXXXX`; then 484 uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T} 485 awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T} 486 cmp -s ${T} /etc/motd || { 487 cp ${T} /etc/motd 488 chmod 644 /etc/motd 489 } 490 rm -f ${T} 491 fi 492 ;; 493esac 494 495# Configure implementation specific stuff 496# 497arch=`uname -m` 498if [ -r /etc/rc.${arch} ]; then 499 . /etc/rc.${arch} 500fi 501 502# Run rc.devfs if readable to customize devfs 503# 504if [ -r /etc/rc.devfs ]; then 505 sh /etc/rc.devfs 506fi 507 508# Do traditional (but rather obsolete) rc.local file if it exists. If you 509# use this file and want to make it programmatic, source /etc/defaults/rc.conf 510# in /etc/rc.local and add your custom variables to /etc/rc.conf, as 511# shown below. Please do not put local extensions into /etc/rc itself. 512# Use /etc/rc.local 513# 514# ---- rc.local ---- 515# if [ -r /etc/defaults/rc.conf ]; then 516# . /etc/defaults/rc.conf 517# fi 518# 519# ... additional startup conditionals ... 520# ---- rc.local ---- 521# 522if [ -r /etc/rc.local ]; then 523 echo -n 'starting local daemons:' 524 sh /etc/rc.local 525 echo '.' 526fi 527 528# For each valid dir in $local_startup, search for init scripts matching *.sh 529# 530case ${local_startup} in 531[Nn][Oo] | '') 532 ;; 533*) 534 echo -n 'Local package initialization:' 535 for dir in ${local_startup}; do 536 if [ -d "${dir}" ]; then 537 for script in ${dir}/*.sh; do 538 if [ -x "${script}" ]; then 539 (set -T 540 trap 'exit 1' 2 541 ${script} start) 542 fi 543 done 544 fi 545 done 546 echo . 547 ;; 548esac 549 550if [ -n "${network_pass3_done}" ]; then 551 network_pass4 552fi 553 554# Raise kernel security level. This should be done only after `fsck' has 555# repaired local file systems if you want the securelevel to be greater than 1. 556# 557case ${kern_securelevel_enable} in 558[Yy][Ee][Ss]) 559 if [ "${kern_securelevel}" -ge 0 ]; then 560 echo 'Raising kernel security level' 561 sysctl -w kern.securelevel=${kern_securelevel} 562 fi 563 ;; 564esac 565 566date 567exit 0 568