Merge pull request #1249 from BastilleBSD/restart-fix

This commit is contained in:
tschettervictor
2025-09-28 11:41:46 -06:00
committed by GitHub
2 changed files with 31 additions and 29 deletions

View File

@@ -3,8 +3,9 @@ restart
Restart jail(s).
Bastille will only restart targeted jail(s) if they are running. Jails that
are stopped will not be started.
Bastille will attempt to stop, then start the targetted jail(s). If a jail is not running, Bastille
will still start it. To avoid this, run the restart command with ``-i|--ignore`` to skip any
stopped jail(s).
.. code-block:: shell
@@ -21,7 +22,8 @@ are stopped will not be started.
Options:
-b | --boot Respect jail boot setting.
-d | --delay VALUE Time (seconds) to wait after starting each jail.
-v | --verbose Print every action on jail restart.
-x | --debug Enable debug mode.
-b | --boot Respect jail boot setting.
-d | --delay VALUE Time (seconds) to wait after starting each jail.
-i | --ignore Ignore stopped jails (do not start if stopped).
-v | --verbose Print every action on jail restart.
-x | --debug Enable debug mode.

View File

@@ -38,10 +38,11 @@ usage() {
Options:
-b | --boot Respect jail boot setting.
-d | --delay VALUE Time (seconds) to wait after starting each jail.
-v | --verbose Print every action on jail start.
-x | --debug Enable debug mode.
-b | --boot Respect jail boot setting.
-d | --delay VALUE Time (seconds) to wait after starting each jail.
-i | --ignore Ignore stopped jails (do not start if stopped).
-v | --verbose Print every action on jail start.
-x | --debug Enable debug mode.
EOF
exit 1
@@ -51,6 +52,7 @@ EOF
# We pass these to start and stop.
_start_options=""
_stop_options=""
IGNORE=0
while [ "$#" -gt 0 ]; do
case "${1}" in
-h|--help|help)
@@ -64,6 +66,10 @@ while [ "$#" -gt 0 ]; do
_start_options="${_start_options} -d ${2}"
shift 2
;;
-i|--ignore)
IGNORE=1
shift
;;
-v|--verbose)
_start_options="${_start_options} -v"
_stop_options="${_stop_options} -v"
@@ -77,20 +83,11 @@ while [ "$#" -gt 0 ]; do
-*)
for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do
case ${_opt} in
b)
_start_options="${_start_options} -b"
;;
v)
_start_options="${_start_options} -v"
_stop_options="${_stop_options} -v"
;;
x)
_start_options="${_start_options} -x"
_stop_options="${_stop_options} -x"
;;
*)
error_exit "[ERROR]: Unknown Option: \"${1}\""
;;
b) _start_options="${_start_options} -b" ;;
i) IGNORE=1 ;;
v) _start_options="${_start_options} -v" _stop_options="${_stop_options} -v" ;;
x) _start_options="${_start_options} -x" _stop_options="${_stop_options} -x" ;;
*) error_exit "[ERROR]: Unknown Option: \"${1}\"" ;;
esac
done
shift
@@ -112,12 +109,15 @@ set_target "${TARGET}"
for _jail in ${JAILS}; do
# Only restart running jails
if check_target_is_running "${_jail}"; then
# Restart all jails except if --ignore
if [ "${IGNORE}" -eq 0 ]; then
bastille stop ${_stop_options} ${_jail}
bastille start ${_start_options} ${_jail}
elif [ "${IGNORE}" -eq 1 ]; then
if check_target_is_stopped "${_jail}"; then
info "\n[${_jail}]:"
error_continue "Jail is stopped."
fi
fi
done
echo
done