1214501Srpaulo#!/bin/sh 2214501Srpaulo# 3214501Srpaulo# Copyright (c) 2000-2004 The FreeBSD Project 4214501Srpaulo# All rights reserved. 5214501Srpaulo# 6214501Srpaulo# Redistribution and use in source and binary forms, with or without 7252726Srpaulo# modification, are permitted provided that the following conditions 8252726Srpaulo# are met: 9214501Srpaulo# 1. Redistributions of source code must retain the above copyright 10214501Srpaulo# notice, this list of conditions and the following disclaimer. 11214501Srpaulo# 2. Redistributions in binary form must reproduce the above copyright 12214501Srpaulo# notice, this list of conditions and the following disclaimer in the 13214501Srpaulo# documentation and/or other materials provided with the distribution. 14214501Srpaulo# 15214501Srpaulo# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16214501Srpaulo# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17214501Srpaulo# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18214501Srpaulo# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19214501Srpaulo# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20214501Srpaulo# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21214501Srpaulo# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22214501Srpaulo# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23214501Srpaulo# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24214501Srpaulo# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25214501Srpaulo# SUCH DAMAGE. 26214501Srpaulo 27214501Srpaulo# System startup script run by init on autoboot 28214501Srpaulo# or after single-user. 29214501Srpaulo# Output and error are redirected to console by init, 30214501Srpaulo# and the console is the controlling terminal. 31214501Srpaulo 32214501Srpaulo# Note that almost all of the user-configurable behavior is no longer in 33214501Srpaulo# this file, but rather in /etc/defaults/rc.conf. Please check that file 34214501Srpaulo# first before contemplating any changes here. If you do need to change 35214501Srpaulo# this file for some reason, we would like to know about it. 36214501Srpaulo 37214501Srpaulostty status '^T' 2> /dev/null 38214501Srpaulo 39214501Srpaulo# Set shell to ignore SIGINT (2), but not children; 40214501Srpaulo# shell catches SIGQUIT (3) and returns to single user. 41214501Srpaulo# 42214501Srpaulotrap : 2 43214501Srpaulotrap "echo 'Boot interrupted'; exit 1" 3 44214501Srpaulo 45214501SrpauloHOME=/ 46214501SrpauloPATH=/sbin:/bin:/usr/sbin:/usr/bin 47214501Srpauloexport HOME PATH 48214501Srpaulo 49214501Srpauloif [ "$1" = autoboot ]; then 50214501Srpaulo autoboot=yes 51214501Srpaulo _boot="faststart" 52214501Srpaulo rc_fast=yes # run_rc_command(): do fast booting 53214501Srpauloelse 54214501Srpaulo autoboot=no 55214501Srpaulo _boot="quietstart" 56214501Srpaulofi 57214501Srpaulo 58214501Srpaulo_localbase=`/sbin/sysctl -n user.localbase 2> /dev/null` 59214501Srpaulo 60214501Srpaulodlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` 61214501Srpauloif [ ${dlv:=0} -ne 0 -o -f /etc/diskless ]; then 62214501Srpaulo sh /etc/rc.initdiskless 63214501Srpaulofi 64214501Srpaulo 65214501Srpaulo# Run these after determining whether we are booting diskless in order 66214501Srpaulo# to minimize the number of files that are needed on a diskless system, 67214501Srpaulo# and to make the configuration file variables available to rc itself. 68214501Srpaulo# 69214501Srpaulo# -o verify has no effect if mac_veriexec is not active 70214501Srpauloset -o verify 71214501Srpaulo. /etc/rc.subr 72214501Srpauloset +o verify 73214501Srpauloload_rc_config $rc_config_xtra 74214501Srpaulo 75214501Srpaulo# If we receive a SIGALRM, re-source /etc/rc.conf; this allows rc.d 76214501Srpaulo# scripts to perform "boot-time configuration" including enabling and 77214501Srpaulo# disabling rc.d scripts which appear later in the boot order. 78214501Srpaulotrap "_rc_conf_loaded=false; load_rc_config" ALRM 79214501Srpaulo 80214501Srpauloskip="-s nostart" 81214501Srpauloif [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then 82214501Srpaulo skip="$skip -s nojail" 83214501Srpaulo if [ `/sbin/sysctl -n security.jail.vnet` -ne 1 ]; then 84214501Srpaulo skip="$skip -s nojailvnet" 85214501Srpaulo fi 86214501Srpaulofi 87214501Srpaulo 88214501Srpaulo# If the firstboot sentinel doesn't exist, we want to skip firstboot scripts. 89214501Srpauloif ! [ -e ${firstboot_sentinel} ]; then 90214501Srpaulo skip_firstboot="-s firstboot" 91214501Srpaulofi 92214501Srpaulo 93214501Srpaulo# Do a first pass to get everything up to $early_late_divider so that 94214501Srpaulo# we can do a second pass that includes $local_startup directories 95214501Srpaulo# 96214501Srpaulounset system_rc 97214501Srpaulofind_system_scripts 98214501Srpaulofiles=`rcorder ${skip} ${skip_firstboot} ${system_rc} 2>/dev/null` 99214501Srpaulorun_rc_scripts --break ${early_late_divider} ${rc_early_flags} $files 100214501Srpaulo 101214501Srpaulounset files local_rc system_rc 102214501Srpaulo 103214501Srpaulo# Now that disks are mounted, for each dir in $local_startup 104214501Srpaulo# search for init scripts that use the new rc.d semantics. 105214501Srpaulo# 106214501Srpaulocase ${local_startup} in 107214501Srpaulo[Nn][Oo] | '') ;; 108214501Srpaulo*) find_local_scripts_new ;; 109214501Srpauloesac 110214501Srpaulo 111214501Srpaulo# The firstboot sentinel might be on a newly mounted filesystem; look for it 112214501Srpaulo# again and unset skip_firstboot if we find it. 113214501Srpauloif [ -e ${firstboot_sentinel} ]; then 114214501Srpaulo skip_firstboot="" 115214501Srpaulofi 116214501Srpaulo 117214501Srpaulofind_system_scripts 118214501Srpaulofiles=`rcorder ${skip} ${skip_firstboot} ${system_rc} ${local_rc} 2>/dev/null` 119214501Srpaulorun_rc_scripts ${rc_late_flags} $files 120214501Srpaulounset files local_rc system_rc 121214501Srpaulo 122214501Srpaulo# allow for more complicated setups 123214501Srpauloif have run_rc_scripts_final; then 124214501Srpaulo run_rc_scripts_final 125214501Srpaulofi 126214501Srpaulo 127214501Srpaulo# Remove the firstboot sentinel, and reboot if it was requested. 128214501Srpaulo# Be a bit paranoid about removing it to handle the common failure 129214501Srpaulo# modes since the consequence of failure can be big. 130214501Srpaulo# Note: this assumes firstboot_sentinel is on / when we have 131214501Srpaulo# a read-only /, or that it is on media that's writable. 132214501Srpauloif [ -e ${firstboot_sentinel} ]; then 133214501Srpaulo checkyesno root_rw_mount || mount -uw / 134214501Srpaulo chflags -R 0 ${firstboot_sentinel} 135214501Srpaulo rm -rf ${firstboot_sentinel} 136214501Srpaulo if [ -e ${firstboot_sentinel}-reboot ]; then 137214501Srpaulo chflags -R 0 ${firstboot_sentinel}-reboot 138214501Srpaulo rm -rf ${firstboot_sentinel}-reboot 139214501Srpaulo checkyesno root_rw_mount || mount -ur / 140214501Srpaulo kill -INT 1 141214501Srpaulo fi 142214501Srpaulo checkyesno root_rw_mount || mount -ur / 143214501Srpaulofi 144214501Srpaulo 145214501Srpauloecho '' 146214501Srpaulodate 147214501Srpauloexit 0 148214501Srpaulo