Merge pull request #1014 from BastilleBSD/parallel-startup

rc: Support parallel start/stop/restart
This commit is contained in:
tschettervictor
2025-05-03 19:22:27 -06:00
committed by GitHub
4 changed files with 53 additions and 23 deletions

View File

@@ -52,6 +52,15 @@ nextcloud will first be stopped because it "depends" on nginx.
Note that if we do a ``bastille restart nginx``, however, nextcloud will be stopped, because it "depends" on nginx, but will not be started again, because the jail we just restarted, nginx, does not depend on nextcloud.
Parallel Startup
----------------
Bastille supports starting, stopping and restarting jails in parallel mode using the ``rc`` service script. To enable this functionality, set
``bastille_parallel_limit`` to a numeric value. For example, if you run ``sysrc bastille_parallel_limit=4``, then Bastille will start 4
jails at a time on system startup, as well as stop or restart 4 jails at a time when ``service bastille...`` is called.
This value is set to 1 by default, to only start/stop/restart jail one at a time.
Startup Delay
-------------

View File

@@ -15,7 +15,7 @@ https://docs.bastillebsd.org.
chapters/gettingstarted
chapters/configuration
chapters/targeting
chapters/startup-configuration
chapters/jail-startup-configuration
chapters/networking
chapters/usage
chapters/upgrading

View File

@@ -32,7 +32,7 @@
PATH=${PATH}:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
BASTILLE_VERSION="0.14.20250420"
BASTILLE_VERSION=aec0630
## check for config existence
bastille_conf_check() {
@@ -253,14 +253,28 @@ case "${CMD}" in
shift 1
;;
*)
if ! set_target "${1}" >/dev/null 2>&1; then
OPTIONS="${OPTIONS} ${1}"
shift 1
else
XARGS_JAILS="${JAILS}"
shift 1
break
fi
case "${CMD}" in
stop|destroy)
if ! set_target "${1}" "reverse" >/dev/null 2>&1; then
OPTIONS="${OPTIONS} ${1}"
shift 1
else
XARGS_JAILS="${JAILS}"
shift 1
break
fi
;;
*)
if ! set_target "${1}" >/dev/null 2>&1; then
OPTIONS="${OPTIONS} ${1}"
shift 1
else
XARGS_JAILS="${JAILS}"
shift 1
break
fi
;;
esac
esac
done
;;
@@ -286,7 +300,5 @@ if [ -f "${SCRIPTPATH}" ]; then
fi
else
error_exit "${SCRIPTPATH} not found."
error_exit "${SCRIPTPATH} not found."
fi

View File

@@ -8,13 +8,16 @@
# Add the following to /etc/rc.conf[.local] to enable this service
#
# bastille_enable (bool): Set to "NO" by default.
# Set to "YES" to enable bastille.
# bastille_conf (bool): Set to "/usr/local/etc/bastille/bastille.conf" by default.
# Path to bastile.conf file.
# bastille_startup_delay (bool): Set to 0 by default.
# Set to a numerical value.
# This is the delay between startup of each jail.
# bastille_enable (bool): Set to "NO" by default.
# Set to "YES" to enable bastille.
# bastille_conf (bool): Set to "/usr/local/etc/bastille/bastille.conf" by default.
# Path to bastile.conf file.
# bastille_startup_delay (bool): Set to "0" by default.
# Set to a numerical value.
# This is the delay between startup of each jail.
# bastille_parallel_limit (bool): Set to "1" by default.
# Set to a numerical value.
# Number of processes to run in parallel when starting/stopping/restarting jails.
#
. /etc/rc.subr
@@ -25,20 +28,26 @@ rcvar=${name}_enable
: ${bastille_enable:="NO"}
: ${bastille_conf:="/usr/local/etc/bastille/bastille.conf"}
: ${bastille_startup_delay:=0}
: ${bastille_parallel_limit:=1}
command=/usr/local/bin/${name}
start_cmd="bastille_start"
stop_cmd="bastille_stop"
restart_cmd="bastille_stop && bastille_start"
restart_cmd="bastille_restart"
bastille_start()
{
${command} start --boot --delay ${bastille_startup_delay} ALL
${command} -p ${bastille_parallel_limit} start --boot --delay ${bastille_startup_delay} ALL
}
bastille_stop()
{
${command} stop ALL
${command} -p ${bastille_parallel_limit} stop ALL
}
bastille_restart()
{
${command} -p ${bastille_parallel_limit} restart --boot --delay ${bastille_startup_delay} ALL
}
load_rc_config ${name}