140123Sdes#!/bin/sh 266830Sobrien# 3126310Smtm# Copyright (c) 2000-2004 The FreeBSD Project 466830Sobrien# All rights reserved. 566830Sobrien# 666830Sobrien# Redistribution and use in source and binary forms, with or without 766830Sobrien# modification, are permitted provided that the following conditions 866830Sobrien# are met: 966830Sobrien# 1. Redistributions of source code must retain the above copyright 1066830Sobrien# notice, this list of conditions and the following disclaimer. 1166830Sobrien# 2. Redistributions in binary form must reproduce the above copyright 1266830Sobrien# notice, this list of conditions and the following disclaimer in the 1366830Sobrien# documentation and/or other materials provided with the distribution. 1466830Sobrien# 1566830Sobrien# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1666830Sobrien# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1766830Sobrien# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1866830Sobrien# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1966830Sobrien# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2066830Sobrien# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2166830Sobrien# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2266830Sobrien# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2366830Sobrien# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2466830Sobrien# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2566830Sobrien# SUCH DAMAGE. 2666830Sobrien# 2783871Sobrien# @(#)rc 5.27 (Berkeley) 6/5/91 2850472Speter# $FreeBSD$ 2966830Sobrien# 3037Srgrimes 3137Srgrimes# System startup script run by init on autoboot 3237Srgrimes# or after single-user. 3337Srgrimes# Output and error are redirected to console by init, 3437Srgrimes# and the console is the controlling terminal. 3537Srgrimes 3651231Ssheldonh# Note that almost all of the user-configurable behavior is no longer in 3751231Ssheldonh# this file, but rather in /etc/defaults/rc.conf. Please check that file 3851231Ssheldonh# first before contemplating any changes here. If you do need to change 3951231Ssheldonh# this file for some reason, we would like to know about it. 408460Sjkh 41232976Sedstty status '^T' 2> /dev/null 4237Srgrimes 4337Srgrimes# Set shell to ignore SIGINT (2), but not children; 44130161Smtm# shell catches SIGQUIT (3) and returns to single user. 4551231Ssheldonh# 4637Srgrimestrap : 2 47130161Smtmtrap "echo 'Boot interrupted'; exit 1" 3 4837Srgrimes 4951231SsheldonhHOME=/ 5092441ScjcPATH=/sbin:/bin:/usr/sbin:/usr/bin 5151231Ssheldonhexport HOME PATH 5237Srgrimes 53114492Sdougbif [ "$1" = autoboot ]; then 54114492Sdougb autoboot=yes 55114492Sdougb _boot="faststart" 56114492Sdougb rc_fast=yes # run_rc_command(): do fast booting 57108200Sdillonelse 58114492Sdougb autoboot=no 59175676Smtm _boot="quietstart" 6098189Sgordonfi 6198189Sgordon 62145693Sbrooksdlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 63145693Sbrooksif [ ${dlv:=0} -ne 0 -o -f /etc/diskless ]; then 64145693Sbrooks sh /etc/rc.initdiskless 65145693Sbrooksfi 66145693Sbrooks 67153298Sdougb# Run these after determining whether we are booting diskless in order 68153298Sdougb# to minimize the number of files that are needed on a diskless system, 69153298Sdougb# and to make the configuration file variables available to rc itself. 70153298Sdougb# 71153298Sdougb. /etc/rc.subr 72153298Sdougbload_rc_config 'XXX' 73153298Sdougb 74259040Scperciva# If we receive a SIGALRM, re-source /etc/rc.conf; this allows rc.d 75259040Scperciva# scripts to perform "boot-time configuration" including enabling and 76259040Scperciva# disabling rc.d scripts which appear later in the boot order. 77259040Scpercivatrap "_rc_conf_loaded=false; load_rc_config 'XXX'" ALRM 78259040Scperciva 79126743Spjdskip="-s nostart" 80155866Sdougbif [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then 81155866Sdougb skip="$skip -s nojail" 82168283Sdes if [ "$early_late_divider" = "FILESYSTEMS" ]; then 83155866Sdougb early_late_divider=NETWORKING 84155866Sdougb fi 85250804Sjamie if [ `/sbin/sysctl -n security.jail.vnet` -ne 1 ]; then 86250804Sjamie skip="$skip -s nojailvnet" 87250804Sjamie fi 88155866Sdougbfi 89153027Sdougb 90256916Scperciva# If the firstboot sentinel doesn't exist, we want to skip firstboot scripts. 91256916Scpercivaif ! [ -e ${firstboot_sentinel} ]; then 92256916Scperciva skip_firstboot="-s firstboot" 93256916Scpercivafi 94256916Scperciva 95153298Sdougb# Do a first pass to get everything up to $early_late_divider so that 96153027Sdougb# we can do a second pass that includes $local_startup directories 97153027Sdougb# 98256916Scpercivafiles=`rcorder ${skip} ${skip_firstboot} /etc/rc.d/* 2>/dev/null` 9998189Sgordon 100221227Sdougb_rc_elem_done=' ' 101114492Sdougbfor _rc_elem in ${files}; do 102114492Sdougb run_rc_script ${_rc_elem} ${_boot} 103221227Sdougb _rc_elem_done="${_rc_elem_done}${_rc_elem} " 104153027Sdougb 105153027Sdougb case "$_rc_elem" in 106153298Sdougb */${early_late_divider}) break ;; 107153027Sdougb esac 10888531Ssheldonhdone 10951231Ssheldonh 110153027Sdougbunset files local_rc 111153027Sdougb 112153027Sdougb# Now that disks are mounted, for each dir in $local_startup 113153027Sdougb# search for init scripts that use the new rc.d semantics. 114153027Sdougb# 115153027Sdougbcase ${local_startup} in 116153027Sdougb[Nn][Oo] | '') ;; 117153027Sdougb*) find_local_scripts_new ;; 118153027Sdougbesac 119153027Sdougb 120256916Scperciva# The firstboot sentinel might be on a newly mounted filesystem; look for it 121256916Scperciva# again and unset skip_firstboot if we find it. 122256916Scpercivaif [ -e ${firstboot_sentinel} ]; then 123256916Scperciva skip_firstboot="" 124256916Scpercivafi 125256916Scperciva 126256916Scpercivafiles=`rcorder ${skip} ${skip_firstboot} /etc/rc.d/* ${local_rc} 2>/dev/null` 127153027Sdougbfor _rc_elem in ${files}; do 128221227Sdougb case "$_rc_elem_done" in 129221227Sdougb *" $_rc_elem "*) continue ;; 130153027Sdougb esac 131153027Sdougb 132153027Sdougb run_rc_script ${_rc_elem} ${_boot} 133153027Sdougbdone 134153027Sdougb 135256916Scperciva# Remove the firstboot sentinel, and reboot if it was requested. 136256916Scpercivaif [ -e ${firstboot_sentinel} ]; then 137256916Scperciva rm ${firstboot_sentinel} 138256916Scperciva if [ -e ${firstboot_sentinel}-reboot ]; then 139256916Scperciva rm ${firstboot_sentinel}-reboot 140256916Scperciva kill -INT 1 141256916Scperciva fi 142256916Scpercivafi 143256916Scperciva 14470109Sdougbecho '' 14537Srgrimesdate 14637Srgrimesexit 0 147