Merge pull request #1209 from BastilleBSD/deprecate-parallel

This commit is contained in:
tschettervictor
2025-08-08 10:07:45 -06:00
committed by GitHub
22 changed files with 108 additions and 232 deletions

View File

@@ -157,8 +157,6 @@ Available Commands:
Use "bastille -v|--version" for version information.
Use "bastille command -h|--help" for more information about a command.
Use "bastille -c|--config config.conf command" to specify a non-default config file.
Use "bastille -p|--parallel VALUE command" to run bastille in parallel mode.
```
## 1.0.x

View File

@@ -43,19 +43,6 @@ This value can be changed using ``bastille config TARGET set priority VALUE``.
This value will be shown using ``bastille list all``.
Parallel Mode
-------------
Any command that supports multiple targets, also supports parallel mode. This
means that Bastille will run the command on multiple jails at a single time,
depending on the value given.
To use parallel mode, run ``bastille -p 4 pkg ALL update``, for example, to start
updating packages in all jails, 4 processes at a time.
Note that the ``-p`` option should follow the main ``bastille`` command, and not
the sub-command.
Examples: Containers
--------------------

View File

@@ -53,4 +53,3 @@ Usage
Use "bastille -v|--version" for version information.
Use "bastille command -h|--help" for more information about a command.
Use "bastille -c|--config config.conf command" to specify a non-default config file.
Use "bastille -p|--parallel VALUE command" to run bastille in parallel mode.

View File

@@ -119,7 +119,6 @@ Available Commands:
Use "bastille -v|--version" for version information.
Use "bastille command -h|--help" for more information about a command.
Use "bastille -c|--config FILE command" to specify a non-default config file.
Use "bastille -p|--parallel VALUE command" to run bastille in parallel mode.
EOF
exit 1
@@ -146,8 +145,6 @@ bastille_perms_check
. /usr/local/share/bastille/common.sh
# Handle options
bastille_parallel_mode=0
bastille_process_limit="${bastille_process_limit:-1}"
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
@@ -170,15 +167,6 @@ while [ "$#" -gt 0 ]; do
. /usr/local/share/bastille/common.sh
shift 2
;;
-p|--parallel)
bastille_parallel_mode=1
bastille_process_limit="${2}"
if ! echo "${bastille_process_limit}" | grep -Eq "^[0-9]+$"; then
error_exit "Not a valid process limit: ${bastille_process_limit}"
else
shift 2
fi
;;
-*)
error_exit "Unknown Option: \"${1}\""
;;
@@ -188,9 +176,6 @@ while [ "$#" -gt 0 ]; do
esac
done
# Export parallel and limit
export bastille_process_limit
if [ "$#" -lt 1 ]; then
usage
else
@@ -200,12 +185,14 @@ fi
# Handle sub-commands.
case "${CMD}" in
# Commands that don't allow parallel mode
# 38 total commands
bootstrap| \
clone| \
cmd| \
config| \
console| \
convert| \
cp| \
create| \
destroy| \
edit| \
@@ -213,38 +200,30 @@ case "${CMD}" in
export| \
htop| \
import| \
jcp| \
limits| \
list| \
migrate| \
mount| \
network| \
pkg| \
rcp| \
rdr| \
rename| \
restart| \
service| \
setup| \
top| \
update| \
upgrade| \
verify| \
zfs)
if [ "${bastille_parallel_mode}" -eq 1 ]; then
error_exit "Command does not support parallel mode: ${CMD}"
fi
;;
# Commands that allow parallel mode
config| \
cp| \
jcp| \
limits| \
mount| \
restart| \
start| \
stop| \
sysrc| \
tags| \
template| \
umount)
top| \
umount| \
update| \
upgrade| \
verify| \
zfs)
;;
*)
usage

View File

@@ -29,25 +29,46 @@ rcvar=${name}_enable
: ${bastille_conf:="/usr/local/etc/bastille/bastille.conf"}
: ${bastille_startup_delay:=0}
: ${bastille_parallel_limit:=1}
: ${bastille_jail_list:=ALL}
command=/usr/local/bin/${name}
start_cmd="bastille_start"
stop_cmd="bastille_stop"
restart_cmd="bastille_restart"
bastille_start()
{
${command} -p ${bastille_parallel_limit} start --boot --delay ${bastille_startup_delay} ALL
list_jails() {
local _jailsdir=$(. $bastille_conf; echo $bastille_jailsdir)
local _jail_list=$(find ${_jailsdir}/* -mindepth 1 -maxdepth 1 -type f -name jail.conf | xargs -n1 dirname | xargs -n1 basename)
for _jail in ${_jail_list}; do
_priority="$(sysrc -f ${_jailsdir}/${_jail}/settings.conf -n priority)"
echo "${_jail} ${_priority}"
done
}
bastille_stop()
{
${command} -p ${bastille_parallel_limit} stop ALL
sort_jails() {
local _order="${1}"
if [ "${_order}" = "forward" ]; then
bastille_jail_list="$(list_jails | sort -k2 -n | awk '{print $1}')"
elif [ "${_order}" = "reverse" ]; then
bastille_jail_list="$(list_jails | sort -k2 -nr | awk '{print $1}')"
else
echo "[ERROR]: Fatal error, could not get jail list."
fi
}
bastille_restart()
{
${command} -p ${bastille_parallel_limit} restart --boot --delay ${bastille_startup_delay} ALL
bastille_start() {
sort_jails "forward"
echo "${bastille_jail_list}" | xargs -P ${bastille_parallel_limit} -I JAIL ${command} start --boot --delay ${bastille_startup_delay} JAIL
}
bastille_stop() {
sort_jails "reverse"
echo "${bastille_jail_list}" | xargs -P ${bastille_parallel_limit} -I JAIL ${command} stop JAIL
}
bastille_restart() {
sort_jails "forward"
echo "${bastille_jail_list}" | xargs -P ${bastille_parallel_limit} -I JAIL ${command} restart --boot --delay ${bastille_startup_delay} JAIL
}
load_rc_config ${name}

View File

@@ -84,10 +84,7 @@ bastille_root_check
TARGET="${1}"
shift 1
# Use mktemp to store exit codes
export TMP_BASTILLE_EXIT_CODE="$(mktemp)"
echo 0 > "${TMP_BASTILLE_EXIT_CODE}"
ERRORS=0
set_target "${TARGET}"
@@ -111,8 +108,14 @@ for _jail in ${JAILS}; do
jexec -l -U root "${_jail}" "$@"
fi
bastille_check_exit_code "${_jail}" "$?"
if [ "$?" -ne 0 ]; then
ERRORS=$((ERRORS + 1))
fi
done
bastille_return_exit_code
if [ "${ERRORS}" -ne 0 ]; then
error_exit "[ERROR]: Command failed on ${ERRORS} jails."
fi
echo

View File

@@ -93,54 +93,6 @@ warn() {
echo -e "${COLOR_YELLOW}$*${COLOR_RESET}"
}
# This function checks and adds any error code
# that is not "0" to the tmp file
bastille_check_exit_code() {
local jail="${1}"
local exit_code="${2}"
# Set exit code variable
if [ -z "${TMP_BASTILLE_EXIT_CODE}" ]; then
error_exit "[ERROR]: Exit code status not set."
else
local old_exit_code="$(cat ${TMP_BASTILLE_EXIT_CODE})"
fi
if [ "${exit_code}" -ne 0 ]; then
local new_exit_code="$(( ${old_exit_code} + ${exit_code} ))"
echo "${new_exit_code}" > "${TMP_BASTILLE_EXIT_CODE}"
error_notify "[ERROR CODE]: ${exit_code}"
fi
}
# This needs to be the last function called
# if used on any command
bastille_return_exit_code() {
local exit_code="$(cat ${TMP_BASTILLE_EXIT_CODE})"
rm -f ${TMP_BASTILLE_EXIT_CODE}
return "${exit_code}"
}
# Parallel mode, don't exceed process limit
bastille_running_jobs() {
_process_limit="${1}"
_running_jobs=$((_running_jobs + 1))
if [ "${_running_jobs}" -ge "${_process_limit}" ]; then
# Wait for at least one process to finish
wait 2>/dev/null || wait
_running_jobs=$((_running_jobs - 1))
fi
}
check_target_exists() {
local _TARGET="${1}"
local _jaillist="$(bastille list jails)"

View File

@@ -88,13 +88,12 @@ shift 2
set_target "${TARGET}"
case "${ACTION}" in
get)
get|remove)
if [ "$#" -ne 1 ]; then
error_notify 'Too many parameters for [get|remove] operation.'
usage
error_exit "[ERROR]: Too many parameters for [get|remove] operation."
fi
;;
add|set|remove)
add|set)
;;
*)
error_exit "[ERROR]: Only (add|set), get and remove are supported."
@@ -126,8 +125,6 @@ print_jail_conf() {
for _jail in ${JAILS}; do
(
# Backwards compatibility for specifying only an IP with ip[4|6].addr
if [ "${ACTION}" = "set" ] && [ "${PROPERTY}" = "ip4.addr" ]; then
if ! echo "${VALUE}" | grep -q "|"; then
@@ -311,12 +308,7 @@ for _jail in ${JAILS}; do
fi
fi
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait
# Only display this message once at the end (not for every jail). -- cwells
if { [ "${ACTION}" = "set" ] || [ "${ACTION}" = "remove" ]; } && [ "${BASTILLE_PROPERTY}" -eq 0 ]; then

View File

@@ -140,7 +140,7 @@ for _jail in ${JAILS}; do
else
check_fib "${_jail}"
LOGIN="$(jexec -l "${_jail}" which login)"
${_setfib} jexec -l "${_jail}" $LOGIN -f root
${_setfib} jexec -l "${_jail}" ${LOGIN} -f root
fi
done

View File

@@ -83,26 +83,25 @@ fi
TARGET="${1}"
HOST_PATH="${2}"
JAIL_PATH="${3}"
ERRORS=0
bastille_root_check
set_target "${TARGET}"
for _jail in ${JAILS}; do
(
info "\n[${_jail}]:"
host_path="${HOST_PATH}"
jail_path="$(echo ${bastille_jailsdir}/${_jail}/root/${JAIL_PATH} | sed 's#//#/#g')"
if ! cp "${OPTION}" "${host_path}" "${jail_path}"; then
ERRORS=$((ERRORS + 1))
error_continue "[ERROR]: CP failed: ${host_path} -> ${jail_path}"
fi
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait
if [ "${ERRORS}" -ne 0 ]; then
error_exit "[ERROR]: Command failed on ${ERRORS} jails."
fi

View File

@@ -84,6 +84,7 @@ SOURCE_TARGET="${1}"
SOURCE_PATH="${2}"
DEST_TARGET="${3}"
DEST_PATH="${4}"
ERRORS=0
bastille_root_check
set_target_single "${SOURCE_TARGET}" && SOURCE_TARGET="${TARGET}"
@@ -91,8 +92,6 @@ set_target "${DEST_TARGET}" && DEST_TARGET="${JAILS}"
for _jail in ${DEST_TARGET}; do
(
if [ "${_jail}" = "${SOURCE_TARGET}" ]; then
continue
else
@@ -103,14 +102,14 @@ for _jail in ${DEST_TARGET}; do
dest_path="$(echo ${bastille_jailsdir}/${_jail}/root/${DEST_PATH} | sed 's#//#/#g')"
if ! cp "${OPTION}" "${source_path}" "${dest_path}"; then
ERRORS=$((ERRORS + 1))
error_continue "[ERROR]: JCP failed: ${source_path} -> ${dest_path}"
fi
fi
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait
if [ "${ERRORS}" -ne 0 ]; then
error_exit "[ERROR]: Command failed on ${ERRORS} jails."
fi

View File

@@ -139,8 +139,6 @@ add_cpuset() {
for _jail in ${JAILS}; do
(
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
bastille start "${_jail}"
else
@@ -302,9 +300,4 @@ for _jail in ${JAILS}; do
esac
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait

View File

@@ -144,8 +144,6 @@ fi
for _jail in ${JAILS}; do
(
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
bastille start "${_jail}"
else
@@ -203,9 +201,4 @@ for _jail in ${JAILS}; do
mount -F "${bastille_jailsdir}/${_jail}/fstab" -a || error_continue "Failed to mount volume: ${_fullpath}"
echo "Added: ${_fstab_entry}"
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait

View File

@@ -96,14 +96,12 @@ fi
TARGET="${1}"
shift
# Use mktemp to store exit codes
export TMP_BASTILLE_EXIT_CODE="$(mktemp)"
echo 0 > "${TMP_BASTILLE_EXIT_CODE}"
ERRORS=0
bastille_root_check
set_target "${TARGET}"
pkg_run_command() {
for _jail in ${JAILS}; do
# Validate jail state
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
@@ -136,12 +134,14 @@ pkg_run_command() {
fi
fi
bastille_check_exit_code "${_jail}" "$?"
}
if [ "$?" -ne 0 ]; then
ERRORS=$((ERRORS + 1))
fi
for _jail in ${JAILS}; do
pkg_run_command "$@"
done
echo
bastille_return_exit_code
if [ "${ERRORS}" -ne 0 ]; then
error_exit "[ERROR]: Command failed on ${ERRORS} jails."
fi
echo

View File

@@ -112,17 +112,12 @@ set_target "${TARGET}"
for _jail in ${JAILS}; do
(
# Only restart running jails
if check_target_is_running "${_jail}"; then
bastille stop ${_stop_options} ${_jail}
bastille start ${_start_options} ${_jail}
fi
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait
echo

View File

@@ -82,9 +82,7 @@ fi
TARGET="${1}"
shift
# Use mktemp to store exit codes
export TMP_BASTILLE_EXIT_CODE="$(mktemp)"
echo 0 > "${TMP_BASTILLE_EXIT_CODE}"
ERRORS=0
bastille_root_check
set_target "${TARGET}"
@@ -104,9 +102,14 @@ for _jail in ${JAILS}; do
jexec -l "${_jail}" /usr/sbin/service "$@"
bastille_check_exit_code "${_jail}" "$?"
if [ "$?" -ne 0 ]; then
ERRORS=$((ERRORS + 1))
fi
done
echo
bastille_return_exit_code
if [ "${ERRORS}" -ne 0 ]; then
error_exit "[ERROR]: Command failed on ${ERRORS} jails."
fi
echo

View File

@@ -104,8 +104,6 @@ set_target "${TARGET}"
for _jail in ${JAILS}; do
(
# Continue if '-b|--boot' is set and 'boot=off'
if [ "${BOOT}" -eq 1 ]; then
BOOT_ENABLED="$(sysrc -f ${bastille_jailsdir}/${_jail}/settings.conf -n boot)"
@@ -220,9 +218,4 @@ for _jail in ${JAILS}; do
# Delay between jail action
sleep "${DELAY_TIME}"
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait

View File

@@ -87,8 +87,6 @@ set_target "${TARGET}" "reverse"
for _jail in ${JAILS}; do
(
# Validate that all jails that 'depend' on this one are stopped
for _depend_jail in $(ls --color=never ${bastille_jailsdir} | sed -e 's/\n//g'); do
if ! grep -hoqsw "depend=" ${bastille_jailsdir}/${_depend_jail}/settings.conf; then
@@ -161,9 +159,4 @@ for _jail in ${JAILS}; do
update_jail_syntax_v1 "${_jail}"
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait

View File

@@ -82,17 +82,13 @@ fi
TARGET="${1}"
shift
# Use mktemp to store exit codes
export TMP_BASTILLE_EXIT_CODE="$(mktemp)"
echo 0 > "${TMP_BASTILLE_EXIT_CODE}"
ERRORS=0
bastille_root_check
set_target "${TARGET}"
for _jail in ${JAILS}; do
(
# Validate jail state
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
bastille start "${_jail}"
@@ -106,14 +102,14 @@ for _jail in ${JAILS}; do
jexec -l "${_jail}" /usr/sbin/sysrc "$@"
bastille_check_exit_code "${_jail}" "$?"
) &
bastille_running_jobs "${bastille_process_limit}"
if [ "$?" -ne 0 ]; then
ERRORS=$((ERRORS + 1))
fi
done
wait
echo
bastille_return_exit_code
if [ "${ERRORS}" -ne 0 ]; then
error_exit "[ERROR]: Command failed on ${ERRORS} jails."
fi
echo

View File

@@ -77,8 +77,6 @@ set_target "${TARGET}"
for _jail in ${JAILS}; do
(
bastille_jail_tags="${bastille_jailsdir}/${_jail}/tags"
case ${ACTION} in
add)
@@ -120,9 +118,4 @@ for _jail in ${JAILS}; do
;;
esac
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait

View File

@@ -272,8 +272,6 @@ fi
for _jail in ${JAILS}; do
(
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
bastille start "${_jail}"
else
@@ -476,9 +474,4 @@ for _jail in ${JAILS}; do
info "\nTemplate applied: ${TEMPLATE}"
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait

View File

@@ -88,8 +88,6 @@ set_target "${TARGET}"
for _jail in ${JAILS}; do
(
# Validate jail state
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
bastille start "${_jail}"
@@ -130,9 +128,6 @@ for _jail in ${JAILS}; do
echo "Unmounted: ${_jailpath}"
) &
bastille_running_jobs "${bastille_process_limit}"
done
wait
echo