rc revision 104423
1127664Sbms#!/bin/sh 2127664Sbms# 3127664Sbms# Copyright (c) 2000 The FreeBSD Project 4127664Sbms# All rights reserved. 5127664Sbms# 6127664Sbms# Redistribution and use in source and binary forms, with or without 7127664Sbms# modification, are permitted provided that the following conditions 8127664Sbms# are met: 9127664Sbms# 1. Redistributions of source code must retain the above copyright 10127664Sbms# notice, this list of conditions and the following disclaimer. 11127664Sbms# 2. Redistributions in binary form must reproduce the above copyright 12146768Ssam# notice, this list of conditions and the following disclaimer in the 13162012Ssam# documentation and/or other materials provided with the distribution. 14162012Ssam# 15162012Ssam# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16127664Sbms# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17127664Sbms# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18127664Sbms# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19127664Sbms# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20172677Smlaier# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21127664Sbms# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22127664Sbms# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23127664Sbms# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24127664Sbms# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25127664Sbms# SUCH DAMAGE. 26127664Sbms# 27127664Sbms# @(#)rc 5.27 (Berkeley) 6/5/91 28127664Sbms# $FreeBSD: head/etc/rc 104423 2002-10-03 20:39:29Z schweikh $ 29127664Sbms# 30127664Sbms 31127664Sbms# System startup script run by init on autoboot 32127664Sbms# or after single-user. 33127664Sbms# Output and error are redirected to console by init, 34127664Sbms# and the console is the controlling terminal. 35127664Sbms 36127664Sbms# Note that almost all of the user-configurable behavior is no longer in 37127664Sbms# this file, but rather in /etc/defaults/rc.conf. Please check that file 38127664Sbms# first before contemplating any changes here. If you do need to change 39127664Sbms# this file for some reason, we would like to know about it. 40127664Sbms 41127664Sbmsstty status '^T' 42127664Sbms 43127664Sbms# Set shell to ignore SIGINT (2), but not children; 44127664Sbms# shell catches SIGQUIT (3) and returns to single user after fsck. 45127664Sbms# 46146768Ssamtrap : 2 47146768Ssamtrap : 3 # shouldn't be needed 48127664Sbms 49146768SsamHOME=/ 50146768SsamPATH=/sbin:/bin:/usr/sbin:/usr/bin 51127664Sbmsexport HOME PATH 52172677Smlaier 53172677Smlaier# If there is a global system configuration file, suck it in. 54172677Smlaier# XXX - The only purpose of duplicating it here is to catch rc_ng="YES" 55172677Smlaier# 56172677Smlaierif [ -r /etc/defaults/rc.conf ]; then 57172677Smlaier . /etc/defaults/rc.conf 58172677Smlaier source_rc_confs 59172677Smlaierelif [ -r /etc/rc.conf ]; then 60172677Smlaier . /etc/rc.conf 61172677Smlaierfi 62172677Smlaier 63172677Smlaier# Diskless setups have to depend on a different mechanism since 64146768Ssam# their config files haven't been retargeted yet. 65146768Ssam# 66146768Ssam[ -e /.rcng_yes ] && rc_ng="YES" 67146768Ssam 68146768Ssamcase ${rc_ng} in 69146768Ssam[Yy][Ee][Ss]) 70146768Ssam . /etc/rc.subr 71127664Sbms 72146768Ssam # Load system configuration files. The 'XXX' is there because 73146768Ssam # the function requires an argument that we don't need to use. 74146768Ssam # 75127664Sbms load_rc_config 'XXX' 76127664Sbms 77127664Sbms if [ "$1" = autoboot ]; then 78127664Sbms autoboot=yes 79127664Sbms _boot="faststart" 80127664Sbms rc_fast=yes # run_rc_command(): do fast booting 81127664Sbms else 82127664Sbms autoboot=no 83127664Sbms _boot="start" 84127664Sbms fi 85127664Sbms 86127664Sbms os=`eval ${CMD_OSTYPE}` 87127664Sbms files=`rcorder -k ${os} -s nostart /etc/rc.d/* 2>/dev/null` 88127664Sbms 89127664Sbms for _rc_elem in ${files}; do 90127664Sbms run_rc_script ${_rc_elem} ${_boot} 91127664Sbms # Local FreeBSD hack to reload the rc.conf on 92127664Sbms # a return status of 2 93172677Smlaier if [ $? -eq 2 ]; then 94172677Smlaier unset _rc_conf_loaded 95172677Smlaier load_rc_config 'XXX' 96172677Smlaier echo "Reloading rc.conf" 97127664Sbms fi 98127664Sbms done 99127664Sbms 100127664Sbms echo '' 101127664Sbms date 102127664Sbms exit 0 103146768Ssam ;; 104146768Ssam*) 105146768Ssam # fall-through to the old rc scripts 106146768Ssam ;; 107127664Sbmsesac 108146768Ssam 109146768Ssambootmode=$1 110146768Ssam 111127664Sbms# BOOTP diskless boot. We have to run the rc file early in order to 112146768Ssam# retarget various config files. 113146768Ssam# 114146768Ssamif [ -r /etc/rc.diskless1 ]; then 115146768Ssam dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 116146768Ssam if [ ${dlv:=0} != 0 ]; then 117146768Ssam . /etc/rc.diskless1 118146768Ssam fi 119127664Sbmsfi 120127664Sbms 121127664Sbms# If there is a global system configuration file, suck it in. 122127664Sbms# 123127664Sbmsif [ -r /etc/defaults/rc.conf ]; then 124127664Sbms . /etc/defaults/rc.conf 125127664Sbms source_rc_confs 126146768Ssamelif [ -r /etc/rc.conf ]; then 127146768Ssam . /etc/rc.conf 128146768Ssamfi 129162012Ssam 130162012Ssam# XXX - Deprecated variable name support 131162012Ssam# for rpcbind and ntpd 132162012Ssam# 133162012Ssam[ -n "$portmap_enable" ] && rpcbind_enable="$portmap_enable" 134146768Ssam[ -n "$portmap_program" ] && rpcbind_program="$portmap_program" 135162012Ssam[ -n "$portmap_flags" ] && rpcbind_flags="$portmap_flags" 136162012Ssam[ -n "$single_mountd_enable" ] && mountd_enable="$single_mountd_enable" 137127664Sbms[ -n "$xntpd_enable" ] && ntpd_enable="$xntpd_enable" 138146768Ssam[ -n "$xntpd_program" ] && ntpd_program="$xntpd_program" 139146768Ssam[ -n "$xntpd_flags" ] && ntpd_flags="$xntpd_flags" 140162012Ssam 141146768Ssamfeed_dev_random() { 142146768Ssam if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then 143146768Ssam# echo "Using ${1} as an entropy file" 144146768Ssam cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null 145146768Ssam fi 146127664Sbms} 147127664Sbms 148146768Ssamchkdepend() { 149146768Ssam svc=$1 150146768Ssam svc_var=$2 151146768Ssam dep=$3 152146768Ssam dep_var=$4 153146768Ssam 154146768Ssam eval svc_val=\${$svc_var} 155146768Ssam eval dep_val=\${$dep_var} 156146768Ssam 157146768Ssam case ${svc_val} in 158127664Sbms [Yy][Ee][Ss]) 159127664Sbms case ${dep_val} in 160146768Ssam [Yy][Ee][Ss]) 161146768Ssam ;; 162146768Ssam *) 163146768Ssam eval ${dep_var}="YES" 164127664Sbms echo "DEPENDENCY NOTE: ${dep} will be enabled" \ 165146768Ssam "to support ${svc}" 166146768Ssam ;; 167146768Ssam esac 168127664Sbms ;; 169146768Ssam esac 170146768Ssam} 171146768Ssam 172146768Ssamchkdepend amd amd_enable rpcbind rpcbind_enable 173127664Sbmschkdepend amd amd_enable NFS nfs_client_enable 174146768Ssamchkdepend NFS nfs_server_enable rpcbind rpcbind_enable 175146768Ssamchkdepend NIS nis_server_enable rpcbind rpcbind_enable 176146768Ssamchkdepend NIS nis_client_enable rpcbind rpcbind_enable 177127664Sbms 178146768Ssam# Enable dumpdev early so that a crash during the boot process can be caught. 179127664Sbms# 180146768Ssamcase ${dumpdev} in 181127664Sbms[Nn][Oo] | '') 182127664Sbms dumpdev='NO' 183127664Sbms ;; 184127664Sbms*) 185127664Sbms /sbin/dumpon -v ${dumpdev} 186127664Sbms ;; 187127664Sbmsesac 188146768Ssam 189146768Ssam# Enable harvesting of entropy via devices. The sooner this happens the 190146768Ssam# better so that we can take advantage of the boot process. 191127664Sbms# 192127664Sbmsecho -n 'Entropy harvesting:' 193127664Sbms 194127664Sbmscase ${harvest_interrupt} in 195162012Ssam[Nn][Oo]) 196162012Ssam ;; 197127664Sbms*) 198162012Ssam if [ -w /dev/random ]; then 199162012Ssam /sbin/sysctl kern.random.sys.harvest.interrupt=1 >/dev/null 200162012Ssam echo -n ' interrupts' 201162012Ssam fi 202127664Sbms ;; 203162012Ssamesac 204162012Ssam 205162012Ssamcase ${harvest_ethernet} in 206127664Sbms[Nn][Oo]) 207162012Ssam ;; 208162012Ssam*) 209162012Ssam if [ -w /dev/random ]; then 210127664Sbms /sbin/sysctl kern.random.sys.harvest.ethernet=1 >/dev/null 211162012Ssam echo -n ' ethernet' 212162012Ssam fi 213162012Ssam ;; 214162012Ssamesac 215162012Ssam 216162012Ssamcase ${harvest_p_to_p} in 217162012Ssam[Nn][Oo]) 218162012Ssam ;; 219162012Ssam*) 220162012Ssam if [ -w /dev/random ]; then 221162012Ssam /sbin/sysctl kern.random.sys.harvest.point_to_point=1 >/dev/null 222162012Ssam echo -n ' point_to_point' 223172677Smlaier fi 224162012Ssam ;; 225162012Ssamesac 226162012Ssam 227162012Ssamecho '.' 228162012Ssam 229162012Ssam# First pass at reseeding /dev/random. 230162012Ssam# 231162012Ssamcase ${entropy_file} in 232162012Ssam[Nn][Oo] | '') 233127664Sbms ;; 234162012Ssam*) 235162012Ssam if [ -w /dev/random ]; then 236162012Ssam feed_dev_random "${entropy_file}" 237162012Ssam fi 238162012Ssam ;; 239162012Ssamesac 240162012Ssam 241162012Ssam# XXX temporary until we can get the entropy 242162012Ssam# harvesting rate up 243162012Ssam# Entropy below is not great, 244146768Ssam# but better than nothing. 245162012Ssam( ps -fauxww; sysctl -a; date; df -ib; dmesg; ps -fauxww; ) \ 246162012Ssam | dd of=/dev/random bs=8k 2>/dev/null 247127664Sbmscat /bin/ls | dd of=/dev/random bs=8k 2>/dev/null 248162012Ssam 249162012Ssam# Configure ccd devices. 250162012Ssam# 251127664Sbmsif [ -r /etc/ccd.conf ]; then 252162012Ssam ccdconfig -C 253162012Ssamfi 254162012Ssam 255162012Ssamcase ${start_vinum} in 256162012Ssam[Yy][Ee][Ss]) 257162012Ssam vinum start 258162012Ssam ;; 259162012Ssamesac 260127664Sbms 261162012Ssamswapon -a 262162012Ssam 263162012Ssam# Last chance to do things before potentially waiting for 264162012Ssam# operator to do fsck related tasks 265127664Sbmsif [ -r /etc/rc.early ]; then 266162012Ssam . /etc/rc.early 267162012Ssamfi 268162012Ssam 269127664Sbmscase ${bootmode} in 270162012Ssamautoboot) 271162012Ssam echo 'Automatic boot in progress...' 272162012Ssam case ${background_fsck} in 273127664Sbms [Yy][Ee][Ss]) 274162012Ssam fsck -F -p 275162012Ssam ;; 276162012Ssam *) 277162012Ssam fsck -p 278162012Ssam ;; 279162012Ssam esac 280162012Ssam case $? in 281162012Ssam 0) 282162012Ssam ;; 283172677Smlaier 2) 284172677Smlaier exit 1 285162012Ssam ;; 286172677Smlaier 4) 287172677Smlaier reboot 288172677Smlaier echo 'Reboot failed... help!' 289172677Smlaier exit 1 290172677Smlaier ;; 291162012Ssam 8) 292162012Ssam case ${fsck_y_enable} in 293162012Ssam [Yy][Ee][Ss]) 294162012Ssam echo 'File system preen failed, trying fsck -y . . .' 295162012Ssam fsck -y 296127664Sbms case $? in 297162012Ssam 0) 298162012Ssam ;; 299162012Ssam *) 300162012Ssam echo 'Automatic filesystem check failed . . . help!' 301162012Ssam exit 1 302162012Ssam ;; 303162012Ssam esac 304162012Ssam ;; 305162012Ssam *) 306172677Smlaier echo 'Automatic filesystem check failed . . . help!' 307162012Ssam exit 1 308162012Ssam ;; 309162012Ssam esac 310162012Ssam ;; 311162012Ssam 12) 312146768Ssam echo 'Reboot interrupted' 313162012Ssam exit 1 314162012Ssam ;; 315162012Ssam 130) 316162012Ssam # interrupt before catcher installed 317162012Ssam exit 1 318162012Ssam ;; 319162012Ssam *) 320162012Ssam echo 'Unknown error in reboot' 321162012Ssam exit 1 322146768Ssam ;; 323162012Ssam esac 324162012Ssam ;; 325162012Ssam*) 326162012Ssam echo 'Skipping disk checks ...' 327162012Ssam ;; 328162012Ssamesac 329127664Sbms 330172677Smlaierset -T 331172677Smlaiertrap "echo 'Reboot interrupted'; exit 1" 3 332172677Smlaier 333162012Ssam# root normally must be read/write, but if this is a BOOTP NFS 334162012Ssam# diskless boot it does not have to be. 335162012Ssam# 336162012Ssamcase ${root_rw_mount} in 337162012Ssam[Nn][Oo] | '') 338162012Ssam ;; 339162012Ssam*) 340162012Ssam if ! mount -u -o rw / ; then 341162012Ssam echo 'Mounting root filesystem rw failed, startup aborted' 342127664Sbms exit 1 343162012Ssam fi 344162012Ssam ;; 345172677Smlaieresac 346172677Smlaier 347172677Smlaierumount -a >/dev/null 2>&1 348162012Ssam 349162012Ssam# Set up the list of network filesystem types for which mounting should be 350162012Ssam# delayed until after network initialization. 351162012Ssamnetworkfs_types='nfs:NFS smbfs:SMB portalfs:PORTAL' 352162012Ssamcase ${extra_netfs_types} in 353162012Ssam[Nn][Oo]) 354162012Ssam ;; 355162012Ssam*) 356162012Ssam networkfs_types="${networkfs_types} ${extra_netfs_types}" 357162012Ssam ;; 358162012Ssamesac 359172677Smlaier 360172677Smlaier# Mount everything except nfs filesystems. 361172677Smlaiermount_excludes='no' 362162012Ssamfor i in ${networkfs_types}; do 363162012Ssam fstype=${i%:*} 364162012Ssam mount_excludes="${mount_excludes}${fstype}," 365162012Ssamdone 366162012Ssammount_excludes=${mount_excludes%,} 367162012Ssammount -a -t ${mount_excludes} 368162012Ssam 369162012Ssamcase $? in 370172677Smlaier0) 371162012Ssam ;; 372172677Smlaier*) 373172677Smlaier echo 'Mounting /etc/fstab filesystems failed, startup aborted' 374172677Smlaier exit 1 375172677Smlaier ;; 376172677Smlaieresac 377172677Smlaier 378172677Smlaier# Run custom disk mounting function here 379172677Smlaier# 380172677Smlaierif [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then 381172677Smlaier sh ${diskless_mount} 382172677Smlaierfi 383172677Smlaier 384162012Ssam# If we booted a special kernel remove the record so we will boot 385162012Ssam# the default kernel next time 386172677Smlaierrm -f /boot/nextboot.conf 387172677Smlaier 388172677Smlaier# Reseed /dev/random with previously stored entropy. 389172677Smlaiercase ${entropy_dir} in 390172677Smlaier[Nn][Oo]) 391162012Ssam ;; 392127664Sbms*) 393162012Ssam entropy_dir=${entropy_dir:-/var/db/entropy} 394162012Ssam if [ -d "${entropy_dir}" ]; then 395127664Sbms if [ -w /dev/random ]; then 396162012Ssam for seedfile in ${entropy_dir}/*; do 397162012Ssam feed_dev_random "${seedfile}" 398162012Ssam done 399162012Ssam fi 400162012Ssam fi 401162012Ssam ;; 402162012Ssamesac 403162012Ssam 404162012Ssamcase ${entropy_file} in 405162012Ssam[Nn][Oo] | '') 406162012Ssam ;; 407162012Ssam*) 408172677Smlaier if [ -w /dev/random ]; then 409172677Smlaier feed_dev_random "${entropy_file}" 410172677Smlaier fi 411172677Smlaier ;; 412172677Smlaieresac 413172677Smlaier 414172677Smlaieradjkerntz -i 415172677Smlaier 416172677Smlaierpurgedir() { 417172677Smlaier local dir file 418172677Smlaier 419172677Smlaier if [ $# -eq 0 ]; then 420172677Smlaier purgedir . 421172677Smlaier else 422172677Smlaier for dir 423162012Ssam do 424127664Sbms ( 425146768Ssam cd "$dir" && for file in .* * 426127664Sbms do 427127664Sbms [ ."$file" = .. -o ."$file" = ... ] && continue 428146768Ssam if [ -d "$file" -a ! -L "$file" ] 429127664Sbms then 430127664Sbms purgedir "$file" 431162012Ssam else 432127664Sbms rm -f -- "$file" 433162012Ssam fi 434162012Ssam done 435127664Sbms ) 436162012Ssam done 437162012Ssam fi 438127664Sbms} 439162012Ssam 440172677Smlaierclean_var() { 441162012Ssam if [ -d /var/run -a ! -f /var/run/clean_var ]; then 442162012Ssam purgedir /var/run 443162012Ssam # Keep a copy of the boot messages around 444127664Sbms dmesg >/var/run/dmesg.boot 445162012Ssam # And an initial utmp file 446162012Ssam (cd /var/run && cp /dev/null utmp && chmod 644 utmp;) 447162012Ssam >/var/run/clean_var 448162012Ssam fi 449162012Ssam if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then 450162012Ssam purgedir /var/spool/lock 451162012Ssam >/var/spool/lock/clean_var 452162012Ssam fi 453127664Sbms rm -rf /var/spool/uucp/.Temp/* 454162012Ssam} 455162012Ssam 456162012Ssam# network_pass1() *may* end up writing stuff to /var - we don't want to 457146768Ssam# remove it immediately afterwards - *nor* do we want to fail to clean 458162012Ssam# an NFS-mounted /var. 459162012Ssamrm -f /var/run/clean_var /var/spool/lock/clean_var 460146768Ssamclean_var 461162012Ssam 462162012Ssam# Add additional swapfile, if configured. 463146768Ssam# 464162012Ssamcase ${swapfile} in 465162012Ssam[Nn][Oo] | '') 466162012Ssam ;; 467162012Ssam*) 468162012Ssam if [ -w "${swapfile}" -a -c /dev/mdctl ]; then 469162012Ssam echo "Adding ${swapfile} as additional swap" 470127664Sbms mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev} 471127664Sbms fi 472162012Ssam ;; 473127664Sbmsesac 474127664Sbms 475127664Sbms# Early pass to set the variables we can 476127664Sbms# 477146768Ssamif [ -r /etc/rc.sysctl ]; then 478146768Ssam sh /etc/rc.sysctl first 479146768Ssamfi 480146768Ssam 481146768Ssam# Configure serial devices 482146768Ssam# 483146768Ssamif [ -r /etc/rc.serial ]; then 484146768Ssam . /etc/rc.serial 485127664Sbmsfi 486127664Sbms 487127664Sbms# Start up PC-card configuration 488127664Sbms# 489127664Sbmsif [ -r /etc/rc.pccard ]; then 490127664Sbms . /etc/rc.pccard 491172677Smlaierfi 492172677Smlaier 493172677Smlaier# Start up the initial network configuration. 494127664Sbms# 495127664Sbmsif [ -r /etc/rc.network ]; then 496146768Ssam . /etc/rc.network # We only need to do this once. 497146768Ssam network_pass1 498146768Ssamfi 499146768Ssam 500146768Ssamcase ${ipv6_enable} in 501146768Ssam[Yy][Ee][Ss]) 502146768Ssam if [ -r /etc/rc.network6 ]; then 503146768Ssam . /etc/rc.network6 # We only need to do this once also. 504172677Smlaier network6_pass1 505162012Ssam fi 506162012Ssam ;; 507162012Ssamesac 508162012Ssam 509162012Ssam# Mount NFS filesystems if present in /etc/fstab 510162012Ssam# 511146768Ssam# XXX When the vfsload() issues with nfsclient support and related sysctls 512146768Ssam# have been resolved, this block can be removed, and the condition that 513146768Ssam# skips nfs in the following block (for "other network filesystems") can 514146768Ssam# be removed. 515146768Ssamcase "`mount -d -a -t nfs 2> /dev/null`" in 516127664Sbms*mount_nfs*) 517146768Ssam # Handle absent nfs client support 518146768Ssam nfsclient_in_kernel=0 519146768Ssam if sysctl vfs.nfs >/dev/null 2>&1; then 520146768Ssam nfsclient_in_kernel=1 521146768Ssam else 522146768Ssam kldload nfsclient && nfsclient_in_kernel=1 523146768Ssam fi 524146768Ssam 525146768Ssam case ${nfsclient_in_kernel} in 526127664Sbms 1) 527172677Smlaier echo -n 'Mounting NFS filesystem:' 528162012Ssam mount -a -t nfs 529172677Smlaier echo '.' 530172677Smlaier ;; 531172677Smlaier *) 532172677Smlaier echo 'Warning: nfs mount requested, but no nfs client in kernel' 533162012Ssam ;; 534162012Ssam esac 535162012Ssam ;; 536162012Ssamesac 537162012Ssam 538162012Ssam# Mount other network filesystems if present in /etc/fstab 539162012Ssamfor i in ${networkfs_types}; do 540162012Ssam fstype=${i%:*} 541162012Ssam fsdecr=${i#*:} 542162012Ssam 543162012Ssam if [ "${fstype}" = "nfs" ]; then 544162012Ssam continue 545162012Ssam fi 546172677Smlaier case "`mount -d -a -t ${fstype}`" in 547172677Smlaier *mount_${fstype}*) 548172677Smlaier echo -n "Mounting ${fsdecr} filesystems:" 549172677Smlaier mount -a -t ${fstype} 550172677Smlaier echo '.' 551172677Smlaier ;; 552172677Smlaier esac 553172677Smlaierdone 554146768Ssam 555146768Ssam# Whack the pty perms back into shape. 556162012Ssam# 557127664Sbmsif ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then 558146768Ssam chflags 0 /dev/tty[pqrsPQRS]* 559146768Ssam chmod 666 /dev/tty[pqrsPQRS]* 560146768Ssam chown root:wheel /dev/tty[pqrsPQRS]* 561146768Ssamfi 562146768Ssam 563127664Sbms# Clean up left-over files 564162012Ssam# 565162012Ssamclean_var # If it hasn't already been done 566162012Ssamrm /var/run/clean_var /var/spool/lock/clean_var 567162012Ssam 568172677Smlaier# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 569162012Ssam# help in any way for long-living systems, and it might accidentally 570162012Ssam# clobber files you would rather like to have preserved after a crash 571162012Ssam# (if not using mfs /tmp anyway). 572162012Ssam# 573162012Ssam# See also the example of another cleanup policy in /etc/periodic/daily. 574162012Ssam# 575162012Ssamcase ${clear_tmp_enable} in 576162012Ssam[Yy][Ee][Ss]) 577172677Smlaier echo -n 'Clearing /tmp:' 578162012Ssam # prune quickly with one rm, then use find to clean up /tmp/[lq]* 579162012Ssam # (not needed with mfs /tmp, but doesn't hurt there...) 580162012Ssam (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 581162012Ssam find -d . ! -name . ! -name lost+found ! -name quota.user \ 582162012Ssam ! -name quota.group -exec rm -rf -- {} \;) 583162012Ssam echo '.' 584162012Ssam ;; 585162012Ssamesac 586162012Ssam 587162012Ssam# Remove X lock files, since they will prevent you from restarting X11 588162012Ssam# after a system crash. 589162012Ssam# 590162012Ssamrm -f /tmp/.X*-lock 591162012Ssamrm -fr /tmp/.X11-unix 592162012Ssammkdir -m 1777 /tmp/.X11-unix 593162012Ssam 594162012Ssam# Snapshot any kernel -c changes back to disk here <someday>. 595172677Smlaier# This has changed with ELF and /kernel.config. 596162012Ssam 597162012Ssam# Load LOMAC(4) security if wanted. 598162012Ssamcase ${lomac_enable} in 599162012Ssam[Yy][Ee][Ss]) 600162012Ssam kldload lomac >/dev/null 2>&1 601172677Smlaier ;; 602162012Ssamesac 603162012Ssam 604162012Ssamecho -n 'Additional daemons:' 605162012Ssam 606172677Smlaier# Start system logging and name service. Named needs to start before syslogd 607172677Smlaier# if you don't have a /etc/resolv.conf. 608172677Smlaier# 609172677Smlaiercase ${syslogd_enable} in 610172677Smlaier[Yy][Ee][Ss]) 611146768Ssam # Transitional symlink (for the next couple of years :) until all 612172677Smlaier # binaries have had a chance to move towards /var/run/log. 613172677Smlaier if [ ! -L /dev/log ]; then 614146768Ssam # might complain for r/o root f/s 615146768Ssam ln -sf /var/run/log /dev/log 616146768Ssam fi 617146768Ssam 618146768Ssam rm -f /var/run/log 619146768Ssam echo -n ' syslogd'; 620146768Ssam ${syslogd_program:-/usr/sbin/syslogd} ${syslogd_flags} 621127664Sbms ;; 622146768Ssamesac 623146768Ssam 624172677Smlaierecho '.' 625146768Ssam 626172677Smlaier# Build device name databases if we are not using DEVFS 627172677Smlaier# 628162012Ssamif sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 629162012Ssam rm -f /var/run/dev.db 630162012Ssamelse 631172677Smlaier dev_mkdb 632146768Ssamfi 633162012Ssam 634146768Ssam# $dumpdir should be a directory or a symbolic link 635146768Ssam# to the crash directory if core dumps are to be saved. 636172677Smlaier# 637146768Ssamif [ "${dumpdev}" != 'NO' ]; then 638162012Ssam case ${dumpdir} in 639127664Sbms '') 640146768Ssam dumpdir='/var/crash' 641146768Ssam ;; 642146768Ssam [Nn][Oo]) 643146768Ssam dumpdir='NO' 644146768Ssam ;; 645146768Ssam esac 646146768Ssam 647146768Ssam if [ "${dumpdir}" != 'NO' ]; then 648127664Sbms echo -n 'Checking for core dump: ' 649146768Ssam /sbin/savecore ${savecore_flags} "${dumpdir}" 650146768Ssam fi 651146768Ssamfi 652146768Ssam 653146768Ssamif [ -n "${network_pass1_done}" ]; then 654146768Ssam network_pass2 655146768Ssamfi 656127664Sbms 657146768Ssam# Enable/Check the quotas (must be after ypbind if using NIS) 658146768Ssam# 659146768Ssamcase ${enable_quotas} in 660146768Ssam[Yy][Ee][Ss]) 661146768Ssam case ${check_quotas} in 662146768Ssam [Yy][Ee][Ss]) 663146768Ssam echo -n 'Checking quotas:' 664172677Smlaier quotacheck -a 665146768Ssam echo ' done.' 666146768Ssam ;; 667127664Sbms esac 668146768Ssam 669162012Ssam echo -n 'Enabling quotas:' 670127664Sbms quotaon -a 671146768Ssam echo ' done.' 672146768Ssam ;; 673146768Ssamesac 674172677Smlaier 675146768Ssamif [ -n "${network_pass2_done}" ]; then 676146768Ssam network_pass3 677146768Ssamfi 678127664Sbms 679146768Ssam# Check the password temp/lock file 680146768Ssam# 681172677Smlaierif [ -e /etc/ptmp ]; then 682146768Ssam logger -s -p auth.err \ 683127664Sbms "password file may be incorrect -- /etc/ptmp exists" 684146768Ssamfi 685162012Ssam 686146768Ssamcase ${accounting_enable} in 687146768Ssam[Yy][Ee][Ss]) 688146768Ssam if [ -d /var/account ]; then 689172677Smlaier echo 'Turning on accounting:' 690172677Smlaier if [ ! -e /var/account/acct ]; then 691172677Smlaier touch /var/account/acct 692127664Sbms fi 693146768Ssam accton /var/account/acct 694146768Ssam fi 695146768Ssam ;; 696147894Ssamesac 697146768Ssam 698146768Ssam# Make shared lib searching a little faster. Leave /usr/lib first if you 699146768Ssam# add your own entries or you may come to grief. 700146768Ssam# 701146768Ssamldconfig="/sbin/ldconfig" 702172677Smlaiercase ${ldconfig_insecure} in 703172677Smlaier[Yy][Ee][Ss]) 704146768Ssam ldconfig="${ldconfig} -i" 705127664Sbms ;; 706172677Smlaieresac 707172677Smlaierif [ -x /sbin/ldconfig ]; then 708172677Smlaier _LDC=/usr/lib 709172677Smlaier for i in ${ldconfig_paths}; do 710172677Smlaier if [ -d "${i}" ]; then 711172677Smlaier _LDC="${_LDC} ${i}" 712172677Smlaier fi 713172677Smlaier done 714172677Smlaier echo 'ELF ldconfig path:' ${_LDC} 715172677Smlaier ${ldconfig} ${_LDC} 716172677Smlaier 717172677Smlaier # Legacy aout support for i386 only 718172677Smlaier case `sysctl -n hw.machine_arch` in 719172677Smlaier i386) 720172677Smlaier # Default the a.out ldconfig path. 721172677Smlaier : ${ldconfig_paths_aout=${ldconfig_paths}} 722172677Smlaier _LDC=/usr/lib/aout 723172677Smlaier for i in ${ldconfig_paths_aout}; do 724172677Smlaier if [ -d "${i}" ]; then 725172677Smlaier _LDC="${_LDC} ${i}" 726172677Smlaier fi 727172677Smlaier done 728172677Smlaier echo 'a.out ldconfig path:' ${_LDC} 729172677Smlaier ${ldconfig} -aout ${_LDC} 730172677Smlaier ;; 731172677Smlaier esac 732172677Smlaierfi 733172677Smlaier 734127664Sbms# Now start up miscellaneous daemons that don't belong anywhere else 735162012Ssam# 736162012Ssamecho -n 'Starting standard daemons:' 737146768Ssamcase ${inetd_enable} in 738146768Ssam[Nn][Oo]) 739146768Ssam ;; 740146768Ssam*) 741146768Ssam echo -n ' inetd'; ${inetd_program:-/usr/sbin/inetd} ${inetd_flags} 742146768Ssam ;; 743146768Ssamesac 744146768Ssam 745146768Ssamcase ${cron_enable} in 746146768Ssam[Nn][Oo]) 747127664Sbms ;; 748146768Ssam*) 749127664Sbms echo -n ' cron'; ${cron_program:-/usr/sbin/cron} ${cron_flags} 750127664Sbms ;; 751146768Ssamesac 752146768Ssam 753146768Ssamcase ${lpd_enable} in 754146768Ssam[Yy][Ee][Ss]) 755146768Ssam echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags} 756146768Ssam ;; 757146768Ssamesac 758146768Ssam 759146768Ssamcase ${sshd_enable} in 760127664Sbms[Yy][Ee][Ss]) 761146768Ssam if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then 762127664Sbms echo -n ' sshd'; 763127664Sbms ${sshd_program:-/usr/sbin/sshd} ${sshd_flags} 764127664Sbms fi 765162012Ssam ;; 766162012Ssamesac 767162012Ssam 768162012Ssamcase ${usbd_enable} in 769127664Sbms[Yy][Ee][Ss]) 770127664Sbms echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 771127664Sbms ;; 772127664Sbmsesac 773162012Ssam 774146768Ssamcase ${mta_start_script} in 775162012Ssam/*) 776127664Sbms if [ -r ${mta_start_script} ]; then 777162012Ssam sh ${mta_start_script} 778162012Ssam fi 779162012Ssam ;; 780162012Ssamesac 781146768Ssam 782146768Ssamecho '.' 783146768Ssam 784146768Ssam# Recover vi editor files. 785146768Ssamfind /var/tmp/vi.recover ! -type f -a ! -type d -delete 786162012Ssamvibackup=`echo /var/tmp/vi.recover/vi.*` 787162012Ssamif [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 788162012Ssam echo -n 'Recovering vi editor sessions:' 789162012Ssam for i in /var/tmp/vi.recover/vi.*; do 790162012Ssam # Only test files that are readable. 791162012Ssam if [ ! -r "${i}" ]; then 792162012Ssam continue 793162012Ssam fi 794162012Ssam 795162012Ssam # Unmodified nvi editor backup files either have the 796162012Ssam # execute bit set or are zero length. Delete them. 797162012Ssam if [ -x "${i}" -o ! -s "${i}" ]; then 798146768Ssam rm -f "${i}" 799162012Ssam fi 800146768Ssam done 801146768Ssam 802127664Sbms # It is possible to get incomplete recovery files, if the editor 803127664Sbms # crashes at the right time. 804127664Sbms virecovery=`echo /var/tmp/vi.recover/recover.*` 805127664Sbms if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 806127664Sbms for i in /var/tmp/vi.recover/recover.*; do 807127664Sbms # Only test files that are readable. 808127664Sbms if [ ! -r "${i}" ]; then 809146768Ssam continue 810146768Ssam fi 811146768Ssam 812146768Ssam # Delete any recovery files that are zero length, 813146768Ssam # corrupted, or that have no corresponding backup file. 814146768Ssam # Else send mail to the user. 815146768Ssam recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 816146768Ssam if [ -n "${recfile}" -a -s "${recfile}" ]; then 817146768Ssam sendmail -t < "${i}" 818146768Ssam else 819127664Sbms rm -f "${i}" 820146768Ssam fi 821127664Sbms done 822146768Ssam fi 823146768Ssam echo '.' 824127664Sbmsfi 825146768Ssam 826127664Sbms# Make a bounds file for msgs(1) if there isn't one already 827146768Ssam# 828127664Sbmsif [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then 829127664Sbms echo 0 > /var/msgs/bounds 830127664Sbmsfi 831127664Sbms 832127664Sbmscase ${update_motd} in 833146768Ssam[Nn][Oo] | '') 834146768Ssam ;; 835127664Sbms*) 836127664Sbms if T=`mktemp /tmp/_motd.XXXXXX`; then 837127664Sbms uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T} 838127664Sbms awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T} 839127664Sbms cmp -s ${T} /etc/motd || { 840127664Sbms cp ${T} /etc/motd 841127664Sbms chmod 644 /etc/motd 842127664Sbms } 843127664Sbms rm -f ${T} 844127664Sbms fi 845127664Sbms ;; 846127664Sbmsesac 847127664Sbms 848127664Sbms# Run rc.devfs if readable to customize devfs 849162012Ssam# 850162012Ssamif [ -r /etc/rc.devfs ]; then 851162012Ssam sh /etc/rc.devfs 852162012Ssamfi 853162012Ssam 854162012Ssam# Configure implementation specific stuff 855162012Ssam# 856162012Ssamarch=`uname -p` 857162012Ssamif [ -r /etc/rc.${arch} ]; then 858162012Ssam . /etc/rc.${arch} 859162012Ssamfi 860162012Ssam 861162012Ssam# Configure the system console 862162012Ssam# 863162012Ssamif [ -r /etc/rc.syscons ]; then 864162012Ssam . /etc/rc.syscons 865162012Ssamfi 866162012Ssam 867162012Ssamecho -n 'Additional ABI support:' 868162012Ssam 869162012Ssam# Load the SysV IPC API if requested. 870162012Ssamcase ${sysvipc_enable} in 871162012Ssam[Yy][Ee][Ss]) 872162012Ssam echo -n ' sysvipc' 873162012Ssam kldload sysvmsg >/dev/null 2>&1 874162012Ssam kldload sysvsem >/dev/null 2>&1 875162012Ssam kldload sysvshm >/dev/null 2>&1 876162012Ssam ;; 877127664Sbmsesac 878127664Sbms 879127664Sbms# Start the Linux binary compatibility if requested. 880127664Sbms# 881127664Sbmscase ${linux_enable} in 882127664Sbms[Yy][Ee][Ss]) 883127664Sbms echo -n ' linux' 884127664Sbms if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then 885127664Sbms kldload linux > /dev/null 2>&1 886127664Sbms fi 887127664Sbms if [ -x /compat/linux/sbin/ldconfig ]; then 888172677Smlaier /compat/linux/sbin/ldconfig 889172677Smlaier fi 890127664Sbms ;; 891172677Smlaieresac 892172677Smlaier 893172677Smlaier# Start the SysVR4 binary emulation if requested. 894146768Ssam# 895146768Ssamcase ${svr4_enable} in 896146768Ssam[Yy][Ee][Ss]) 897127664Sbms echo -n ' svr4'; kldload svr4 > /dev/null 2>&1 898172677Smlaier ;; 899172677Smlaieresac 900172677Smlaier 901172677Smlaierecho '.' 902172677Smlaier 903172677Smlaier# Do traditional (but rather obsolete) rc.local file if it exists. If you 904172677Smlaier# use this file and want to make it programmatic, source /etc/defaults/rc.conf 905172677Smlaier# in /etc/rc.local and add your custom variables to /etc/rc.conf, as 906172677Smlaier# shown below. Please do not put local extensions into /etc/rc itself. 907172677Smlaier# Use /etc/rc.local 908172677Smlaier# 909146768Ssam# ---- rc.local ---- 910172677Smlaier# if [ -r /etc/defaults/rc.conf ]; then 911127664Sbms# . /etc/defaults/rc.conf 912172677Smlaier# source_rc_confs 913172677Smlaier# elif [ -r /etc/rc.conf ]; then 914172677Smlaier# . /etc/rc.conf 915127664Sbms# fi 916172677Smlaier# 917172677Smlaier# ... additional startup conditionals ... 918172677Smlaier# ---- rc.local ---- 919172677Smlaier# 920172677Smlaierif [ -r /etc/rc.local ]; then 921172677Smlaier echo -n 'Starting local daemons:' 922172677Smlaier sh /etc/rc.local 923172677Smlaier echo '.' 924172677Smlaierfi 925172677Smlaier 926172677Smlaier# For each valid dir in $local_startup, search for init scripts matching *.sh 927172677Smlaier# 928172677Smlaiercase ${local_startup} in 929172677Smlaier[Nn][Oo] | '') 930172677Smlaier ;; 931146768Ssam*) 932172677Smlaier echo -n 'Local package initialization:' 933172677Smlaier slist="" 934172677Smlaier if [ -z "${script_name_sep}" ]; then 935172677Smlaier script_name_sep=" " 936172677Smlaier fi 937172677Smlaier for dir in ${local_startup}; do 938172677Smlaier if [ -d "${dir}" ]; then 939172677Smlaier for script in ${dir}/*.sh; do 940172677Smlaier slist="${slist}${script_name_sep}${script}" 941172677Smlaier done 942172677Smlaier fi 943172677Smlaier done 944172677Smlaier script_save_sep="$IFS" 945172677Smlaier IFS="${script_name_sep}" 946172677Smlaier for script in ${slist}; do 947172677Smlaier if [ -x "${script}" ]; then 948172677Smlaier (set -T 949172677Smlaier trap 'exit 1' 2 950172677Smlaier ${script} start) 951172677Smlaier elif [ -f "${script}" -o -L "${script}" ]; then 952172677Smlaier echo -n " (skipping ${script##*/}, not executable)" 953172677Smlaier fi 954172677Smlaier done 955172677Smlaier IFS="${script_save_sep}" 956146768Ssam echo '.' 957172677Smlaier ;; 958172677Smlaieresac 959172677Smlaier 960172677Smlaierif [ -n "${network_pass3_done}" ]; then 961172677Smlaier network_pass4 962172677Smlaierfi 963172677Smlaier 964172677Smlaier# Late pass to set variables we missed the first time 965172677Smlaier# 966172677Smlaierif [ -r /etc/rc.sysctl ]; then 967172677Smlaier sh /etc/rc.sysctl last 968172677Smlaierfi 969172677Smlaier 970172677Smlaier# Raise kernel security level. This should be done only after `fsck' has 971172677Smlaier# repaired local filesystems if you want the securelevel to be greater than 1. 972172677Smlaier# 973172677Smlaiercase ${kern_securelevel_enable} in 974146768Ssam[Yy][Ee][Ss]) 975172677Smlaier if [ "${kern_securelevel}" -ge 0 ]; then 976172677Smlaier echo 'Raising kernel security level: ' 977172677Smlaier sysctl kern.securelevel=${kern_securelevel} 978172677Smlaier fi 979172677Smlaier ;; 980172677Smlaieresac 981172677Smlaier 982172677Smlaier# Start background fsck checks if necessary 983172677Smlaiercase ${background_fsck} in 984172677Smlaier[Yy][Ee][Ss]) 985172677Smlaier echo 'Starting background filesystem checks' 986172677Smlaier nice -4 fsck -B -p 2>&1 | logger -p daemon.notice & 987172677Smlaier ;; 988172677Smlaieresac 989172677Smlaier 990172677Smlaierecho '' 991146768Ssam 992172677Smlaierdate 993172677Smlaier 994172677Smlaierexit 0 995172677Smlaier 996146768Ssam