Index: etc/Makefile =================================================================== --- etc/Makefile +++ etc/Makefile @@ -43,6 +43,7 @@ protocols \ rc \ rc.bsdextended \ + rc.delay \ rc.firewall \ rc.initdiskless \ rc.shutdown \ Index: etc/defaults/rc.conf =================================================================== --- etc/defaults/rc.conf +++ etc/defaults/rc.conf @@ -92,6 +92,12 @@ extra_netfs_types="NO" # List of network extra filesystem types for delayed # mount at startup (or NO). +### Fastboot settings ### +fastboot_enable="NO" # Enable / disable fastboot or delayed services +fastboot_delay="10" # Seconds to wait before starting delayed scripts +fastboot_rc_delay="/etc/rc.d/sshd /etc/rc.d/jail /etc/rc.d/iscsictl /etc/rc.d/ftpd /etc/rc.d/bluetooth" # Services to start delayed +fastboot_rc_early="" # Services to start early (before login is reached) + ############################################################## ### Network configuration sub-section ###################### ############################################################## Index: etc/rc =================================================================== --- etc/rc +++ etc/rc @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2000-2004 The FreeBSD Project +# Copyright (c) 2000-2015 The FreeBSD Project # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -114,6 +114,50 @@ *) find_local_scripts_new ;; esac +if [ "$fastboot_enable" = "YES" ]; then + # List of rc.d scripts we will start before login + _rc_preload=`rcorder ${skip} ${skip_firstboot} /etc/rc.d/* $fastboot_rc_early 2>/dev/null` + + # Don't wait for devd to do init + export devd_flags="-n $devd_flags" + + # Run the early scripts now + for _rc_elem in $_rc_preload + do + # Do we have something to delay to later? + case " $fastboot_rc_delay " in + *" $_rc_elem "*) continue ;; + esac + + # Save list of what we have already run + _rc_elem_run="$_rc_elem_run $_rc_elem" + + # Have we already started this? + case " $_rc_elem_done " in + *" $_rc_elem "*) continue ;; + esac + + # Skip full netif, run this in post + if [ "${_rc_elem}" = "/etc/rc.d/netif" ] ; then + /etc/rc.d/netif start lo0 + elif [ "${_rc_elem}" = "/etc/rc.d/defaultroute" ] ; then + continue + else + run_rc_script ${_rc_elem} ${_boot} + fi + done + + # Start the delayed services after the login is up + (sleep $fastboot_delay ; \ + nice /bin/sh /etc/rc.delay \ + "$_rc_elem_run" \ + "$_rc_network_up") & + + echo '' + date + exit 0 +fi + # The firstboot sentinel might be on a newly mounted filesystem; look for it # again and unset skip_firstboot if we find it. if [ -e ${firstboot_sentinel} ]; then Index: etc/rc.d/mountcritremote =================================================================== --- etc/rc.d/mountcritremote +++ etc/rc.d/mountcritremote @@ -40,6 +40,9 @@ '') ;; *) + if [ "$fastboot_enable" = "YES" -a -z "$_rc_network_up" ] ; then + _enable_full_networking + fi echo -n 'Mounting NFS file systems:' mount -a -t nfs echo '.' @@ -63,6 +66,9 @@ case "`mount -d -a -t ${fstype}`" in *mount_${fstype}*) + if [ "$fastboot_enable" = "YES" -a -z "$_rc_network_up" ] ; then + _enable_full_networking + fi echo -n "Mounting ${fsdecr} file systems:" mount -a -t ${fstype} echo '.' Index: etc/rc.delay =================================================================== --- /dev/null +++ etc/rc.delay @@ -0,0 +1,103 @@ +#!/bin/sh +# +# Copyright (c) 2000-2015 The FreeBSD Project +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# @(#)rc 5.27 (Berkeley) 6/5/91 +# $FreeBSD$ +# + +# Delayed system startup script run by /etc/rc after bootup +# Output and error are redirected to /var/log/rc_delay.log + +# Note that almost all of the user-configurable behavior is no longer in +# this file, but rather in /etc/defaults/rc.conf. Please check that file +# first before contemplating any changes here. If you do need to change +# this file for some reason, we would like to know about it. + +stty status '^T' + +# Set shell to ignore SIGINT (2), but not children; +# shell catches SIGQUIT (3) and returns to single user. +# +trap : 2 +trap "echo 'Boot interrupted'; exit 1" 3 + +HOME=/ +PATH=/sbin:/bin:/usr/sbin:/usr/bin +export HOME PATH + +autoboot=yes +_boot="faststart" +rc_fast=yes # run_rc_command(): do fast booting +rc_debug "Starting delayed services `date`" + +dlv=`/sbin/sysctl -n vfs.nfs.diskless_valid 2> /dev/null` +if [ ${dlv:=0} -ne 0 -o -f /etc/diskless ]; then + sh /etc/rc.initdiskless +fi + +# Run these after determining whether we are booting diskless in order +# to minimize the number of files that are needed on a diskless system, +# and to make the configuration file variables available to rc itself. +# +. /etc/rc.subr +load_rc_config 'XXX' + +skip="-s nostart" +if [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ]; then + skip="$skip -s nojail" + if [ "$early_late_divider" = "FILESYSTEMS" ]; then + early_late_divider=NETWORKING + fi +fi + +unset files local_rc +_rc_elem_done="$1" + +# Now that disks are mounted, for each dir in $local_startup +# search for init scripts that use the new rc.d semantics. +# +case ${local_startup} in +[Nn][Oo] | '') ;; +*) find_local_scripts_new ;; +esac + +# Start full networking, if it wasn't already started at boot +if [ -z "$2" ] ; then + _enable_full_networking +fi + +# Now run the rest of the delayed services +files=`rcorder ${skip} ${skip_firstboot} /etc/rc.d/* ${local_rc} 2>/dev/null` +for _rc_elem in ${files}; do + case " $_rc_elem_done " in + *" $_rc_elem "*) continue ;; + esac + + run_rc_script ${_rc_elem} ${_boot} +done + +rc_debug "Finished starting delayed services `date`" +exit 0 Index: etc/rc.subr =================================================================== --- etc/rc.subr +++ etc/rc.subr @@ -2082,6 +2082,17 @@ esac } +# _enable_full_networking +# When using fastboot, is called by by early scripts that require networking to finish +# such as mountcritremote when the user has NFS mounts +_enable_full_networking() +{ + run_rc_script /etc/rc.d/netif ${_boot} + run_rc_script /etc/rc.d/defaultroute ${_boot} + _rc_network_up="1" ; export _rc_network_up +} + + fi # [ -z "${_rc_subr_loaded}" ] _rc_subr_loaded=: Index: share/man/man5/rc.conf.5 =================================================================== --- share/man/man5/rc.conf.5 +++ share/man/man5/rc.conf.5 @@ -4446,12 +4446,27 @@ This variables contains the .Xr rctl.conf 5 ruleset to load for -.Xr rctl 8 . +.Xr rctl 8 .It Va iovctl_files .Pq Vt str A space-separated list of configuration files used by .Xr iovctl 8 . The default value is an empty string. +.It Va fastboot_enable +.Pq Vt bool +Set to +.Dq Li YES +to boot with minimal networking and delayed service startup. The full network and delayed services +will be started after the login prompt is reached. +.It Va fastboot_delay +.Pq Vt int +Set to the number of seconds to wait before starting delayed services. The default is 10. +.It Va fastboot_rc_delay +.Pq Vt str +Set to the list of services to delay starting when fastboot is enabled. +.It Va fastboot_rc_early +.Pq Vt str +Set to the list of services to start early when fastboot is enabled. .El .Sh FILES .Bl -tag -width ".Pa /etc/defaults/rc.conf" -compact