rc revision 95531
1239310Sdim#!/bin/sh 2239310Sdim# 3239310Sdim# Copyright (c) 2000 The FreeBSD Project 4239310Sdim# All rights reserved. 5239310Sdim# 6239310Sdim# Redistribution and use in source and binary forms, with or without 7239310Sdim# modification, are permitted provided that the following conditions 8239310Sdim# are met: 9239310Sdim# 1. Redistributions of source code must retain the above copyright 10239310Sdim# notice, this list of conditions and the following disclaimer. 11239310Sdim# 2. Redistributions in binary form must reproduce the above copyright 12239310Sdim# notice, this list of conditions and the following disclaimer in the 13239310Sdim# documentation and/or other materials provided with the distribution. 14252723Sdim# 15239310Sdim# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16239310Sdim# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17239310Sdim# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18239310Sdim# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19239310Sdim# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20239310Sdim# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21239310Sdim# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22239310Sdim# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23239310Sdim# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24252723Sdim# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25252723Sdim# SUCH DAMAGE. 26252723Sdim# 27252723Sdim# @(#)rc 5.27 (Berkeley) 6/5/91 28252723Sdim# $FreeBSD: head/etc/rc 95531 2002-04-26 22:32:15Z wes $ 29252723Sdim# 30252723Sdim 31252723Sdim# System startup script run by init on autoboot 32239310Sdim# or after single-user. 33252723Sdim# Output and error are redirected to console by init, 34252723Sdim# and the console is the controlling terminal. 35239310Sdim 36239310Sdim# Note that almost all of the user-configurable behavior is no longer in 37239310Sdim# this file, but rather in /etc/defaults/rc.conf. Please check that file 38239310Sdim# first before contemplating any changes here. If you do need to change 39239310Sdim# this file for some reason, we would like to know about it. 40239310Sdim 41239310Sdimstty status '^T' 42239310Sdim 43239310Sdim# Set shell to ignore SIGINT (2), but not children; 44239310Sdim# shell catches SIGQUIT (3) and returns to single user after fsck. 45239310Sdim# 46252723Sdimtrap : 2 47252723Sdimtrap : 3 # shouldn't be needed 48252723Sdim 49239310Sdimbootmode=$1 50252723Sdim 51252723SdimHOME=/ 52252723SdimPATH=/sbin:/bin:/usr/sbin:/usr/bin 53252723Sdimexport HOME PATH 54263509Sdim 55263509Sdim# BOOTP diskless boot. We have to run the rc file early in order to 56252723Sdim# retarget various config files. 57252723Sdim# 58252723Sdimif [ -r /etc/rc.diskless1 ]; then 59252723Sdim dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 60252723Sdim if [ ${dlv:=0} != 0 ]; then 61252723Sdim . /etc/rc.diskless1 62252723Sdim fi 63252723Sdimfi 64252723Sdim 65252723Sdim# If there is a global system configuration file, suck it in. 66252723Sdim# 67252723Sdimif [ -r /etc/defaults/rc.conf ]; then 68252723Sdim . /etc/defaults/rc.conf 69239310Sdim source_rc_confs 70263509Sdimelif [ -r /etc/rc.conf ]; then 71263509Sdim . /etc/rc.conf 72263509Sdimfi 73263509Sdim 74263509Sdimfeed_dev_random() { 75263509Sdim if [ -f "${1}" -a -r "${1}" -a -s "${1}" ]; then 76263509Sdim# echo "Using ${1} as an entropy file" 77263509Sdim cat "${1}" | dd of=/dev/random bs=8k 2>/dev/null 78263509Sdim fi 79263509Sdim} 80263509Sdim 81263509Sdimchkdepend() { 82263509Sdim svc=$1 83263509Sdim svc_var=$2 84263509Sdim dep=$3 85263509Sdim dep_var=$4 86263509Sdim 87263509Sdim eval svc_val=\${$svc_var} 88263509Sdim eval dep_val=\${$dep_var} 89263509Sdim 90263509Sdim case ${svc_val} in 91263509Sdim [Yy][Ee][Ss]) 92263509Sdim case ${dep_val} in 93263509Sdim [Yy][Ee][Ss]) 94263509Sdim ;; 95263509Sdim *) 96263509Sdim eval ${dep_var}="YES" 97263509Sdim echo "DEPENDENCY NOTE: ${dep} will be enabled" \ 98263509Sdim "to support ${svc}" 99263509Sdim ;; 100263509Sdim esac 101239310Sdim ;; 102239310Sdim esac 103252723Sdim} 104252723Sdim 105239310Sdimchkdepend amd amd_enable portmap portmap_enable 106239310Sdimchkdepend amd amd_enable NFS nfs_client_enable 107239310Sdimchkdepend NFS nfs_server_enable portmap portmap_enable 108239310Sdimchkdepend NIS nis_server_enable portmap portmap_enable 109252723Sdimchkdepend NIS nis_client_enable portmap portmap_enable 110252723Sdim 111252723Sdim# Enable dumpdev early so that a crash during the boot process can be caught. 112239310Sdim# 113239310Sdimcase ${dumpdev} in 114239310Sdim[Nn][Oo] | '') 115239310Sdim dumpdev='NO' 116239310Sdim ;; 117239310Sdim*) 118239310Sdim /sbin/dumpon -v ${dumpdev} 119239310Sdim ;; 120239310Sdimesac 121239310Sdim 122239310Sdim# Enable harvesting of entropy via devices. The sooner this happens the 123239310Sdim# better so that we can take advantage of the boot process. 124239310Sdim# 125239310Sdimecho -n 'Entropy harvesting:' 126239310Sdim 127239310Sdimcase ${harvest_interrupt} in 128239310Sdim[Nn][Oo]) 129239310Sdim ;; 130239310Sdim*) 131239310Sdim if [ -w /dev/random ]; then 132239310Sdim /sbin/sysctl kern.random.sys.harvest.interrupt=1 >/dev/null 133252723Sdim echo -n ' interrupts' 134252723Sdim fi 135252723Sdim ;; 136252723Sdimesac 137252723Sdim 138252723Sdimcase ${harvest_ethernet} in 139252723Sdim[Nn][Oo]) 140252723Sdim ;; 141263509Sdim*) 142263509Sdim if [ -w /dev/random ]; then 143263509Sdim /sbin/sysctl kern.random.sys.harvest.ethernet=1 >/dev/null 144263509Sdim echo -n ' ethernet' 145263509Sdim fi 146263509Sdim ;; 147252723Sdimesac 148239310Sdim 149239310Sdimcase ${harvest_p_to_p} in 150252723Sdim[Nn][Oo]) 151252723Sdim ;; 152252723Sdim*) 153252723Sdim if [ -w /dev/random ]; then 154252723Sdim /sbin/sysctl kern.random.sys.harvest.point_to_point=1 >/dev/null 155239310Sdim echo -n ' point_to_point' 156239310Sdim fi 157252723Sdim ;; 158252723Sdimesac 159252723Sdim 160252723Sdimecho '.' 161252723Sdim 162239310Sdim# First pass at reseeding /dev/random. 163239310Sdim# 164252723Sdimcase ${entropy_file} in 165252723Sdim[Nn][Oo] | '') 166252723Sdim ;; 167252723Sdim*) 168252723Sdim if [ -w /dev/random ]; then 169252723Sdim feed_dev_random "${entropy_file}" 170252723Sdim fi 171239310Sdim ;; 172239310Sdimesac 173239310Sdim 174252723Sdim# XXX temporary until we can get the entropy 175252723Sdim# harvesting rate up 176239310Sdim# Entropy below is not great, 177252723Sdim# but better than nothing. 178252723Sdim( ps -fauxww; sysctl -a; date; df -ib; dmesg; ps -fauxww; ) \ 179239310Sdim | dd of=/dev/random bs=8k 2>/dev/null 180239310Sdimcat /bin/ls | dd of=/dev/random bs=8k 2>/dev/null 181239310Sdim 182239310Sdim# Configure ccd devices. 183239310Sdim# 184239310Sdimif [ -r /etc/ccd.conf ]; then 185239310Sdim ccdconfig -C 186239310Sdimfi 187239310Sdim 188239310Sdimcase ${start_vinum} in 189239310Sdim[Yy][Ee][Ss]) 190245431Sdim vinum start 191245431Sdim ;; 192245431Sdimesac 193239310Sdim 194239310Sdimswapon -a 195239310Sdim 196239310Sdim# Last chance to do things before potentially waiting for 197239310Sdim# operator to do fsck related tasks 198239310Sdimif [ -r /etc/rc.early ]; then 199239310Sdim . /etc/rc.early 200239310Sdimfi 201252723Sdim 202252723Sdimcase ${bootmode} in 203239310Sdimautoboot) 204239310Sdim echo 'Automatic boot in progress...' 205252723Sdim case ${background_fsck} in 206239310Sdim [Yy][Ee][Ss]) 207263509Sdim fsck -F -p 208263509Sdim ;; 209263509Sdim *) 210252723Sdim fsck -p 211252723Sdim ;; 212252723Sdim esac 213252723Sdim case $? in 214252723Sdim 0) 215252723Sdim ;; 216252723Sdim 2) 217252723Sdim exit 1 218252723Sdim ;; 219252723Sdim 4) 220239310Sdim reboot 221263509Sdim echo 'Reboot failed... help!' 222263509Sdim exit 1 223263509Sdim ;; 224263509Sdim 8) 225263509Sdim case ${fsck_y_enable} in 226263509Sdim [Yy][Ee][Ss]) 227263509Sdim echo 'File system preen failed, trying fsck -y . . .' 228263509Sdim fsck -y 229263509Sdim case $? in 230263509Sdim 0) 231263509Sdim ;; 232263509Sdim *) 233263509Sdim echo 'Automatic file system check failed . . . help!' 234263509Sdim exit 1 235263509Sdim ;; 236263509Sdim esac 237263509Sdim ;; 238263509Sdim *) 239263509Sdim echo 'Automatic file system check failed . . . help!' 240239310Sdim exit 1 241239310Sdim ;; 242239310Sdim esac 243239310Sdim ;; 244239310Sdim 12) 245239310Sdim echo 'Reboot interrupted' 246239310Sdim exit 1 247252723Sdim ;; 248252723Sdim 130) 249252723Sdim # interrupt before catcher installed 250252723Sdim exit 1 251252723Sdim ;; 252252723Sdim *) 253252723Sdim echo 'Unknown error in reboot' 254252723Sdim exit 1 255252723Sdim ;; 256252723Sdim esac 257239310Sdim ;; 258239310Sdim*) 259252723Sdim echo 'Skipping disk checks ...' 260252723Sdim ;; 261252723Sdimesac 262252723Sdim 263252723Sdimset -T 264252723Sdimtrap "echo 'Reboot interrupted'; exit 1" 3 265252723Sdim 266252723Sdim# root normally must be read/write, but if this is a BOOTP NFS 267263509Sdim# diskless boot it does not have to be. 268263509Sdim# 269263509Sdimcase ${root_rw_mount} in 270263509Sdim[Nn][Oo] | '') 271252723Sdim ;; 272252723Sdim*) 273263509Sdim if ! mount -u -o rw / ; then 274263509Sdim echo 'Mounting root filesystem rw failed, startup aborted' 275263509Sdim exit 1 276263509Sdim fi 277252723Sdim ;; 278252723Sdimesac 279252723Sdim 280252723Sdimumount -a >/dev/null 2>&1 281252723Sdim 282252723Sdim# Set up the list of network filesystem types for which mounting should be 283252723Sdim# delayed until after network initialization. 284252723Sdimnetworkfs_types='nfs:NFS smbfs:SMB portalfs:PORTAL' 285252723Sdimcase ${extra_netfs_types} in 286252723Sdim[Nn][Oo]) 287252723Sdim ;; 288252723Sdim*) 289252723Sdim networkfs_types="${networkfs_types} ${extra_netfs_types}" 290252723Sdim ;; 291252723Sdimesac 292252723Sdim 293252723Sdim# Mount everything except nfs filesystems. 294252723Sdimmount_excludes='no' 295252723Sdimfor i in ${networkfs_types}; do 296252723Sdim fstype=${i%:*} 297252723Sdim mount_excludes="${mount_excludes}${fstype}," 298252723Sdimdone 299252723Sdimmount_excludes=${mount_excludes%,} 300252723Sdimmount -a -t ${mount_excludes} 301263509Sdim 302263509Sdimcase $? in 303263509Sdim0) 304263509Sdim ;; 305252723Sdim*) 306252723Sdim echo 'Mounting /etc/fstab filesystems failed, startup aborted' 307252723Sdim exit 1 308252723Sdim ;; 309252723Sdimesac 310252723Sdim 311252723Sdim# Run custom disk mounting function here 312252723Sdim# 313263509Sdimif [ -n "${diskless_mount}" -a -r "${diskless_mount}" ]; then 314263509Sdim sh ${diskless_mount} 315252723Sdimfi 316252723Sdim 317252723Sdim# If we booted a special kernel remove the record so we will boot 318252723Sdim# the default kernel next time 319252723Sdimrm -f /boot/nextboot.conf 320252723Sdim 321252723Sdim# Reseed /dev/random with previously stored entropy. 322252723Sdimcase ${entropy_dir} in 323252723Sdim[Nn][Oo]) 324252723Sdim ;; 325252723Sdim*) 326252723Sdim entropy_dir=${entropy_dir:-/var/db/entropy} 327252723Sdim if [ -d "${entropy_dir}" ]; then 328252723Sdim if [ -w /dev/random ]; then 329252723Sdim for seedfile in ${entropy_dir}/*; do 330252723Sdim feed_dev_random "${seedfile}" 331239310Sdim done 332239310Sdim fi 333239310Sdim fi 334252723Sdim ;; 335252723Sdimesac 336252723Sdim 337239310Sdimcase ${entropy_file} in 338239310Sdim[Nn][Oo] | '') 339239310Sdim ;; 340263509Sdim*) 341239310Sdim if [ -w /dev/random ]; then 342239310Sdim feed_dev_random "${entropy_file}" 343239310Sdim fi 344239310Sdim ;; 345239310Sdimesac 346263509Sdim 347263509Sdimadjkerntz -i 348263509Sdim 349263509Sdimpurgedir() { 350263509Sdim local dir file 351239310Sdim 352239310Sdim if [ $# -eq 0 ]; then 353263509Sdim purgedir . 354263509Sdim else 355263509Sdim for dir 356239310Sdim do 357239310Sdim ( 358239310Sdim cd "$dir" && for file in .* * 359239310Sdim do 360263509Sdim [ ."$file" = .. -o ."$file" = ... ] && continue 361239310Sdim if [ -d "$file" -a ! -L "$file" ] 362263509Sdim then 363239310Sdim purgedir "$file" 364263509Sdim else 365263509Sdim rm -f -- "$file" 366263509Sdim fi 367263509Sdim done 368263509Sdim ) 369263509Sdim done 370263509Sdim fi 371263509Sdim} 372263509Sdim 373263509Sdimclean_var() { 374263509Sdim if [ -d /var/run -a ! -f /var/run/clean_var ]; then 375239310Sdim purgedir /var/run 376263509Sdim # Keep a copy of the boot messages around 377263509Sdim dmesg >/var/run/dmesg.boot 378263509Sdim # And an initial utmp file 379263509Sdim (cd /var/run && cp /dev/null utmp && chmod 644 utmp;) 380263509Sdim >/var/run/clean_var 381263509Sdim fi 382263509Sdim if [ -d /var/spool/lock -a ! -f /var/spool/lock/clean_var ]; then 383263509Sdim purgedir /var/spool/lock 384263509Sdim >/var/spool/lock/clean_var 385263509Sdim fi 386263509Sdim rm -rf /var/spool/uucp/.Temp/* 387263509Sdim} 388263509Sdim 389263509Sdim# network_pass1() *may* end up writing stuff to /var - we don't want to 390239310Sdim# remove it immediately afterwards - *nor* do we want to fail to clean 391263509Sdim# an NFS-mounted /var. 392263509Sdimrm -f /var/run/clean_var /var/spool/lock/clean_var 393263509Sdimclean_var 394263509Sdim 395263509Sdim# Add additional swapfile, if configured. 396263509Sdim# 397263509Sdimcase ${swapfile} in 398239310Sdim[Nn][Oo] | '') 399263509Sdim ;; 400263509Sdim*) 401263509Sdim if [ -w "${swapfile}" -a -c /dev/mdctl ]; then 402239310Sdim echo "Adding ${swapfile} as additional swap" 403239310Sdim mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev} 404239310Sdim fi 405239310Sdim ;; 406239310Sdimesac 407239310Sdim 408239310Sdim# Early pass to set the variables we can 409239310Sdim# 410239310Sdimif [ -r /etc/rc.sysctl ]; then 411263509Sdim sh /etc/rc.sysctl first 412263509Sdimfi 413263509Sdim 414239310Sdim# Configure serial devices 415239310Sdim# 416239310Sdimif [ -r /etc/rc.serial ]; then 417239310Sdim . /etc/rc.serial 418239310Sdimfi 419263509Sdim 420263509Sdim# Start up PC-card configuration 421263509Sdim# 422263509Sdimif [ -r /etc/rc.pccard ]; then 423263509Sdim . /etc/rc.pccard 424263509Sdimfi 425263509Sdim 426263509Sdim# Start up the initial network configuration. 427263509Sdim# 428263509Sdimif [ -r /etc/rc.network ]; then 429263509Sdim . /etc/rc.network # We only need to do this once. 430263509Sdim network_pass1 431263509Sdimfi 432263509Sdim 433263509Sdimcase ${ipv6_enable} in 434263509Sdim[Yy][Ee][Ss]) 435263509Sdim if [ -r /etc/rc.network6 ]; then 436263509Sdim . /etc/rc.network6 # We only need to do this once also. 437263509Sdim network6_pass1 438263509Sdim fi 439263509Sdim ;; 440263509Sdimesac 441263509Sdim 442263509Sdim# Mount NFS filesystems if present in /etc/fstab 443239310Sdim# 444239310Sdim# XXX When the vfsload() issues with nfsclient support and related sysctls 445239310Sdim# have been resolved, this block can be removed, and the condition that 446252723Sdim# skips nfs in the following block (for "other network filesystems") can 447252723Sdim# be removed. 448252723Sdimcase "`mount -d -a -t nfs 2> /dev/null`" in 449239310Sdim*mount_nfs*) 450239310Sdim # Handle absent nfs client support 451239310Sdim nfsclient_in_kernel=0 452263509Sdim if sysctl vfs.nfs >/dev/null 2>&1; then 453239310Sdim nfsclient_in_kernel=1 454239310Sdim else 455239310Sdim kldload nfsclient && nfsclient_in_kernel=1 456239310Sdim fi 457252723Sdim 458239310Sdim case ${nfsclient_in_kernel} in 459239310Sdim 1) 460263509Sdim echo -n 'Mounting NFS file systems:' 461263509Sdim mount -a -t nfs 462263509Sdim echo '.' 463263509Sdim ;; 464263509Sdim *) 465263509Sdim echo 'Warning: nfs mount requested, but no nfs client in kernel' 466263509Sdim ;; 467263509Sdim esac 468263509Sdim ;; 469239310Sdimesac 470263509Sdim 471263509Sdim# Mount other network filesystems if present in /etc/fstab 472263509Sdimfor i in ${networkfs_types}; do 473263509Sdim fstype=${i%:*} 474263509Sdim fsdecr=${i#*:} 475263509Sdim 476263509Sdim if [ "${fstype}" = "nfs" ]; then 477263509Sdim continue 478263509Sdim fi 479263509Sdim case "`mount -d -a -t ${fstype}`" in 480263509Sdim *mount_${fstype}*) 481263509Sdim echo -n "Mounting ${fsdecr} file systems:" 482263509Sdim mount -a -t ${fstype} 483263509Sdim echo '.' 484263509Sdim ;; 485263509Sdim esac 486263509Sdimdone 487263509Sdim 488263509Sdim# Whack the pty perms back into shape. 489263509Sdim# 490263509Sdimif ls /dev/tty[pqrsPQRS]* > /dev/null 2>&1; then 491263509Sdim chflags 0 /dev/tty[pqrsPQRS]* 492263509Sdim chmod 666 /dev/tty[pqrsPQRS]* 493263509Sdim chown root:wheel /dev/tty[pqrsPQRS]* 494263509Sdimfi 495263509Sdim 496263509Sdim# Clean up left-over files 497263509Sdim# 498263509Sdimclean_var # If it hasn't already been done 499239310Sdimrm /var/run/clean_var /var/spool/lock/clean_var 500263509Sdim 501263509Sdim# Clearing /tmp at boot-time seems to have a long tradition. It doesn't 502263509Sdim# help in any way for long-living systems, and it might accidentally 503263509Sdim# clobber files you would rather like to have preserved after a crash 504263509Sdim# (if not using mfs /tmp anyway). 505239310Sdim# 506239310Sdim# See also the example of another cleanup policy in /etc/periodic/daily. 507263509Sdim# 508263509Sdimcase ${clear_tmp_enable} in 509263509Sdim[Yy][Ee][Ss]) 510263509Sdim echo -n 'Clearing /tmp:' 511263509Sdim # prune quickly with one rm, then use find to clean up /tmp/[lq]* 512263509Sdim # (not needed with mfs /tmp, but doesn't hurt there...) 513263509Sdim (cd /tmp && rm -rf [a-km-pr-zA-Z]* && 514263509Sdim find -d . ! -name . ! -name lost+found ! -name quota.user \ 515263509Sdim ! -name quota.group -exec rm -rf -- {} \;) 516263509Sdim echo '.' 517239310Sdim ;; 518239310Sdimesac 519252723Sdim 520252723Sdim# Remove X lock files, since they will prevent you from restarting X11 521252723Sdim# after a system crash. 522263509Sdim# 523263509Sdimrm -f /tmp/.X*-lock /tmp/.X11-unix/* 524263509Sdim 525263509Sdim# Snapshot any kernel -c changes back to disk here <someday>. 526252723Sdim# This has changed with ELF and /kernel.config. 527252723Sdim 528252723Sdim# Load LOMAC(4) security if wanted. 529252723Sdimcase ${lomac_enable} in 530252723Sdim[Yy][Ee][Ss]) 531252723Sdim kldload lomac >/dev/null 2>&1 532239310Sdim ;; 533239310Sdimesac 534263509Sdim 535263509Sdimecho -n 'Additional daemons:' 536263509Sdim 537263509Sdim# Start system logging and name service. Named needs to start before syslogd 538263509Sdim# if you don't have a /etc/resolv.conf. 539263509Sdim# 540239310Sdimcase ${syslogd_enable} in 541239310Sdim[Yy][Ee][Ss]) 542252723Sdim # Transitional symlink (for the next couple of years :) until all 543263509Sdim # binaries have had a chance to move towards /var/run/log. 544263509Sdim if [ ! -L /dev/log ]; then 545239310Sdim # might complain for r/o root f/s 546239310Sdim ln -sf /var/run/log /dev/log 547239310Sdim fi 548263509Sdim 549263509Sdim rm -f /var/run/log 550263509Sdim echo -n ' syslogd'; 551263509Sdim ${syslogd_program:-/usr/sbin/syslogd} ${syslogd_flags} 552263509Sdim ;; 553263509Sdimesac 554263509Sdim 555263509Sdimecho '.' 556263509Sdim 557263509Sdim# Build device name databases if we are not using DEVFS 558239310Sdim# 559239310Sdimif sysctl vfs.devfs.generation > /dev/null 2>&1 ; then 560263509Sdim rm -f /var/run/dev.db 561263509Sdimelse 562263509Sdim dev_mkdb 563239310Sdimfi 564263509Sdim 565263509Sdim# $dumpdir should be a directory or a symbolic link 566263509Sdim# to the crash directory if core dumps are to be saved. 567263509Sdim# 568263509Sdimif [ "${dumpdev}" != 'NO' ]; then 569263509Sdim case ${dumpdir} in 570263509Sdim '') 571263509Sdim dumpdir='/var/crash' 572263509Sdim ;; 573263509Sdim [Nn][Oo]) 574263509Sdim dumpdir='NO' 575263509Sdim ;; 576263509Sdim esac 577263509Sdim 578263509Sdim if [ "${dumpdir}" != 'NO' ]; then 579263509Sdim echo -n 'Checking for core dump: ' 580263509Sdim /sbin/savecore ${savecore_flags} "${dumpdir}" 581263509Sdim fi 582263509Sdimfi 583263509Sdim 584263509Sdimif [ -n "${network_pass1_done}" ]; then 585263509Sdim network_pass2 586263509Sdimfi 587263509Sdim 588263509Sdim# Enable/Check the quotas (must be after ypbind if using NIS) 589263509Sdim# 590263509Sdimcase ${enable_quotas} in 591263509Sdim[Yy][Ee][Ss]) 592263509Sdim case ${check_quotas} in 593263509Sdim [Yy][Ee][Ss]) 594263509Sdim echo -n 'Checking quotas:' 595263509Sdim quotacheck -a 596263509Sdim echo ' done.' 597263509Sdim ;; 598263509Sdim esac 599263509Sdim 600263509Sdim echo -n 'Enabling quotas:' 601263509Sdim quotaon -a 602263509Sdim echo ' done.' 603263509Sdim ;; 604263509Sdimesac 605263509Sdim 606263509Sdimif [ -n "${network_pass2_done}" ]; then 607263509Sdim network_pass3 608263509Sdimfi 609263509Sdim 610263509Sdim# Check the password temp/lock file 611263509Sdim# 612263509Sdimif [ -e /etc/ptmp ]; then 613263509Sdim logger -s -p auth.err \ 614263509Sdim "password file may be incorrect -- /etc/ptmp exists" 615263509Sdimfi 616263509Sdim 617263509Sdimcase ${accounting_enable} in 618263509Sdim[Yy][Ee][Ss]) 619263509Sdim if [ -d /var/account ]; then 620263509Sdim echo 'Turning on accounting:' 621263509Sdim if [ ! -e /var/account/acct ]; then 622263509Sdim touch /var/account/acct 623263509Sdim fi 624263509Sdim accton /var/account/acct 625263509Sdim fi 626263509Sdim ;; 627263509Sdimesac 628263509Sdim 629263509Sdim# Make shared lib searching a little faster. Leave /usr/lib first if you 630263509Sdim# add your own entries or you may come to grief. 631263509Sdim# 632263509Sdimldconfig="/sbin/ldconfig" 633263509Sdimcase ${ldconfig_insecure} in 634263509Sdim[Yy][Ee][Ss]) 635263509Sdim ldconfig="${ldconfig} -i" 636263509Sdim ;; 637263509Sdimesac 638263509Sdimif [ -x /sbin/ldconfig ]; then 639263509Sdim case `/usr/bin/objformat` in 640263509Sdim elf) 641263509Sdim _LDC=/usr/lib 642263509Sdim for i in ${ldconfig_paths}; do 643263509Sdim if [ -d "${i}" ]; then 644263509Sdim _LDC="${_LDC} ${i}" 645263509Sdim fi 646263509Sdim done 647263509Sdim echo 'ELF ldconfig path:' ${_LDC} 648263509Sdim ${ldconfig} -elf ${_LDC} 649263509Sdim ;; 650263509Sdim esac 651263509Sdim 652263509Sdim # Legacy aout support for i386 only 653263509Sdim case `sysctl -n hw.machine_arch` in 654263509Sdim i386) 655263509Sdim # Default the a.out ldconfig path. 656263509Sdim : ${ldconfig_paths_aout=${ldconfig_paths}} 657263509Sdim _LDC=/usr/lib/aout 658263509Sdim for i in ${ldconfig_paths_aout}; do 659263509Sdim if [ -d "${i}" ]; then 660263509Sdim _LDC="${_LDC} ${i}" 661263509Sdim fi 662263509Sdim done 663263509Sdim echo 'a.out ldconfig path:' ${_LDC} 664263509Sdim ${ldconfig} -aout ${_LDC} 665263509Sdim ;; 666263509Sdim esac 667263509Sdimfi 668263509Sdim 669263509Sdim# Now start up miscellaneous daemons that don't belong anywhere else 670263509Sdim# 671263509Sdimecho -n 'Starting standard daemons:' 672263509Sdimcase ${inetd_enable} in 673263509Sdim[Nn][Oo]) 674263509Sdim ;; 675263509Sdim*) 676263509Sdim echo -n ' inetd'; ${inetd_program:-/usr/sbin/inetd} ${inetd_flags} 677263509Sdim ;; 678263509Sdimesac 679263509Sdim 680263509Sdimcase ${cron_enable} in 681263509Sdim[Nn][Oo]) 682263509Sdim ;; 683263509Sdim*) 684263509Sdim echo -n ' cron'; ${cron_program:-/usr/sbin/cron} ${cron_flags} 685263509Sdim ;; 686263509Sdimesac 687263509Sdim 688263509Sdimcase ${lpd_enable} in 689263509Sdim[Yy][Ee][Ss]) 690263509Sdim echo -n ' printer'; ${lpd_program:-/usr/sbin/lpd} ${lpd_flags} 691263509Sdim ;; 692263509Sdimesac 693263509Sdim 694263509Sdimcase ${sshd_enable} in 695263509Sdim[Yy][Ee][Ss]) 696263509Sdim if [ -x ${sshd_program:-/usr/sbin/sshd} ]; then 697263509Sdim echo -n ' sshd'; 698263509Sdim ${sshd_program:-/usr/sbin/sshd} ${sshd_flags} 699263509Sdim fi 700263509Sdim ;; 701263509Sdimesac 702263509Sdim 703263509Sdimcase ${usbd_enable} in 704263509Sdim[Yy][Ee][Ss]) 705263509Sdim echo -n ' usbd'; /usr/sbin/usbd ${usbd_flags} 706263509Sdim ;; 707263509Sdimesac 708263509Sdim 709263509Sdimcase ${mta_start_script} in 710263509Sdim/*) 711263509Sdim if [ -r ${mta_start_script} ]; then 712263509Sdim sh ${mta_start_script} 713263509Sdim fi 714263509Sdim ;; 715263509Sdimesac 716263509Sdim 717263509Sdimecho '.' 718263509Sdim 719263509Sdim# Recover vi editor files. 720263509Sdimfind /var/tmp/vi.recover ! -type f -a ! -type d -delete 721263509Sdimvibackup=`echo /var/tmp/vi.recover/vi.*` 722263509Sdimif [ "${vibackup}" != '/var/tmp/vi.recover/vi.*' ]; then 723263509Sdim echo -n 'Recovering vi editor sessions:' 724263509Sdim for i in /var/tmp/vi.recover/vi.*; do 725263509Sdim # Only test files that are readable. 726263509Sdim if [ ! -r "${i}" ]; then 727263509Sdim continue 728263509Sdim fi 729263509Sdim 730263509Sdim # Unmodified nvi editor backup files either have the 731263509Sdim # execute bit set or are zero length. Delete them. 732263509Sdim if [ -x "${i}" -o ! -s "${i}" ]; then 733263509Sdim rm -f "${i}" 734263509Sdim fi 735263509Sdim done 736263509Sdim 737263509Sdim # It is possible to get incomplete recovery files, if the editor 738263509Sdim # crashes at the right time. 739263509Sdim virecovery=`echo /var/tmp/vi.recover/recover.*` 740263509Sdim if [ "${virecovery}" != "/var/tmp/vi.recover/recover.*" ]; then 741263509Sdim for i in /var/tmp/vi.recover/recover.*; do 742263509Sdim # Only test files that are readable. 743263509Sdim if [ ! -r "${i}" ]; then 744263509Sdim continue 745263509Sdim fi 746263509Sdim 747263509Sdim # Delete any recovery files that are zero length, 748263509Sdim # corrupted, or that have no corresponding backup file. 749239310Sdim # Else send mail to the user. 750239310Sdim recfile=`awk '/^X-vi-recover-path:/{print $2}' < "${i}"` 751239310Sdim if [ -n "${recfile}" -a -s "${recfile}" ]; then 752263509Sdim sendmail -t < "${i}" 753263509Sdim else 754263509Sdim rm -f "${i}" 755263509Sdim fi 756263509Sdim done 757263509Sdim fi 758263509Sdim echo '.' 759239310Sdimfi 760239310Sdim 761239310Sdim# Make a bounds file for msgs(1) if there isn't one already 762239310Sdim# 763263509Sdimif [ -d /var/msgs -a ! -f /var/msgs/bounds -a ! -L /var/msgs/bounds ]; then 764239310Sdim echo 0 > /var/msgs/bounds 765239310Sdimfi 766239310Sdim 767263509Sdimcase ${update_motd} in 768263509Sdim[Nn][Oo] | '') 769263509Sdim ;; 770263509Sdim*) 771263509Sdim if T=`mktemp /tmp/_motd.XXXXXX`; then 772263509Sdim uname -v | sed -e 's,^\([^#]*\) #\(.* [1-2][0-9][0-9][0-9]\).*/\([^\]*\) $,\1 (\3) #\2,' > ${T} 773263509Sdim awk '{if (NR == 1) {if ($1 == "FreeBSD") {next} else {print "\n"$0}} else {print}}' < /etc/motd >> ${T} 774263509Sdim cmp -s ${T} /etc/motd || { 775239310Sdim cp ${T} /etc/motd 776239310Sdim chmod 644 /etc/motd 777263509Sdim } 778239310Sdim rm -f ${T} 779239310Sdim fi 780263509Sdim ;; 781263509Sdimesac 782263509Sdim 783263509Sdim# Run rc.devfs if readable to customize devfs 784263509Sdim# 785263509Sdimif [ -r /etc/rc.devfs ]; then 786239310Sdim sh /etc/rc.devfs 787239310Sdimfi 788239310Sdim 789239310Sdim# Configure implementation specific stuff 790239310Sdim# 791239310Sdimarch=`uname -p` 792239310Sdimif [ -r /etc/rc.${arch} ]; then 793239310Sdim . /etc/rc.${arch} 794252723Sdimfi 795239310Sdim 796239310Sdim# Configure the system console 797263509Sdim# 798263509Sdimif [ -r /etc/rc.syscons ]; then 799263509Sdim . /etc/rc.syscons 800263509Sdimfi 801263509Sdim 802263509Sdimecho -n 'Additional ABI support:' 803263509Sdim 804263509Sdim# Load the SysV IPC API if requested. 805263509Sdimcase ${sysvipc_enable} in 806263509Sdim[Yy][Ee][Ss]) 807263509Sdim echo -n ' sysvipc' 808263509Sdim kldload sysvmsg >/dev/null 2>&1 809263509Sdim kldload sysvsem >/dev/null 2>&1 810263509Sdim kldload sysvshm >/dev/null 2>&1 811239310Sdim ;; 812252723Sdimesac 813239310Sdim 814239310Sdim# Start the Linux binary compatibility if requested. 815239310Sdim# 816239310Sdimcase ${linux_enable} in 817239310Sdim[Yy][Ee][Ss]) 818239310Sdim echo -n ' linux' 819252723Sdim if ! kldstat -v | grep -E 'linux(aout|elf)' > /dev/null; then 820239310Sdim kldload linux > /dev/null 2>&1 821263509Sdim fi 822263509Sdim if [ -x /compat/linux/sbin/ldconfig ]; then 823252723Sdim /compat/linux/sbin/ldconfig 824263509Sdim fi 825252723Sdim ;; 826263509Sdimesac 827263509Sdim 828263509Sdim# Start the SysVR4 binary emulation if requested. 829263509Sdim# 830263509Sdimcase ${svr4_enable} in 831263509Sdim[Yy][Ee][Ss]) 832239310Sdim echo -n ' svr4'; kldload svr4 > /dev/null 2>&1 833239310Sdim ;; 834263509Sdimesac 835239310Sdim 836263509Sdimecho '.' 837263509Sdim 838263509Sdim# Do traditional (but rather obsolete) rc.local file if it exists. If you 839263509Sdim# use this file and want to make it programmatic, source /etc/defaults/rc.conf 840239310Sdim# in /etc/rc.local and add your custom variables to /etc/rc.conf, as 841263509Sdim# shown below. Please do not put local extensions into /etc/rc itself. 842239310Sdim# Use /etc/rc.local 843239310Sdim# 844263509Sdim# ---- rc.local ---- 845239310Sdim# if [ -r /etc/defaults/rc.conf ]; then 846239310Sdim# . /etc/defaults/rc.conf 847239310Sdim# source_rc_confs 848239310Sdim# elif [ -r /etc/rc.conf ]; then 849239310Sdim# . /etc/rc.conf 850239310Sdim# fi 851239310Sdim# 852239310Sdim# ... additional startup conditionals ... 853239310Sdim# ---- rc.local ---- 854239310Sdim# 855263509Sdimif [ -r /etc/rc.local ]; then 856263509Sdim echo -n 'Starting local daemons:' 857263509Sdim sh /etc/rc.local 858263509Sdim echo '.' 859263509Sdimfi 860263509Sdim 861263509Sdim# For each valid dir in $local_startup, search for init scripts matching *.sh 862263509Sdim# 863263509Sdimcase ${local_startup} in 864263509Sdim[Nn][Oo] | '') 865263509Sdim ;; 866263509Sdim*) 867263509Sdim echo -n 'Local package initialization:' 868263509Sdim slist="" 869263509Sdim if [ -z "${script_name_sep}" ]; then 870263509Sdim script_name_sep=" " 871263509Sdim fi 872263509Sdim for dir in ${local_startup}; do 873263509Sdim if [ -d "${dir}" ]; then 874263509Sdim for script in ${dir}/*.sh; do 875263509Sdim slist="${slist}${script_name_sep}${script}" 876263509Sdim done 877263509Sdim fi 878263509Sdim done 879263509Sdim script_save_sep="$IFS" 880263509Sdim IFS="${script_name_sep}" 881239310Sdim for script in ${slist}; do 882239310Sdim if [ -x "${script}" ]; then 883239310Sdim (set -T 884239310Sdim trap 'exit 1' 2 885239310Sdim ${script} start) 886239310Sdim elif [ -f "${script}" -o -L "${script}" ]; then 887239310Sdim echo -n " (skipping ${script##*/}, not executable)" 888239310Sdim fi 889239310Sdim done 890263509Sdim IFS="${script_save_sep}" 891263509Sdim echo '.' 892263509Sdim ;; 893263509Sdimesac 894263509Sdim 895263509Sdimif [ -n "${network_pass3_done}" ]; then 896263509Sdim network_pass4 897263509Sdimfi 898252723Sdim 899263509Sdim# Late pass to set variables we missed the first time 900239310Sdim# 901239310Sdimif [ -r /etc/rc.sysctl ]; then 902239310Sdim sh /etc/rc.sysctl last 903239310Sdimfi 904252723Sdim 905263509Sdim# Raise kernel security level. This should be done only after `fsck' has 906252723Sdim# repaired local file systems if you want the securelevel to be greater than 1. 907252723Sdim# 908252723Sdimcase ${kern_securelevel_enable} in 909239310Sdim[Yy][Ee][Ss]) 910239310Sdim if [ "${kern_securelevel}" -ge 0 ]; then 911239310Sdim echo 'Raising kernel security level: ' 912239310Sdim sysctl kern.securelevel=${kern_securelevel} 913239310Sdim fi 914239310Sdim ;; 915239310Sdimesac 916239310Sdim 917239310Sdim# Start background fsck checks if necessary 918239310Sdimcase ${background_fsck} in 919239310Sdim[Yy][Ee][Ss]) 920239310Sdim echo 'Starting background filesystem checks' 921239310Sdim nice -4 fsck -B -p 2>&1 | logger -p daemon.notice & 922239310Sdim ;; 923239310Sdimesac 924252723Sdim 925239310Sdimecho '' 926252723Sdim 927239310Sdimdate 928239310Sdim 929239310Sdimexit 0 930239310Sdim 931239310Sdim