From 16d5d05d73645dbd89d0a6361856eb350088adc6 Mon Sep 17 00:00:00 2001 From: tschettervictor Date: Sat, 27 Sep 2025 12:34:47 -0600 Subject: [PATCH 1/4] restart: error if jail is not restarted --- usr/local/share/bastille/restart.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/usr/local/share/bastille/restart.sh b/usr/local/share/bastille/restart.sh index 3db70675..e9e34c73 100644 --- a/usr/local/share/bastille/restart.sh +++ b/usr/local/share/bastille/restart.sh @@ -106,6 +106,7 @@ if [ "$#" -ne 1 ]; then fi TARGET="${1}" +ERRORS=0 bastille_root_check set_target "${TARGET}" @@ -116,8 +117,12 @@ for _jail in ${JAILS}; do if check_target_is_running "${_jail}"; then bastille stop ${_stop_options} ${_jail} bastille start ${_start_options} ${_jail} + else + ERRORS=$((ERRORS + 1)) fi done -echo \ No newline at end of file +if [ "${ERRORS}" -ne 0 ]; then + error_exit "[ERROR]: Failed to restart ${ERRORS} jails." +fi \ No newline at end of file From 8a6627841bf39322764bf6bb684115bde7ff04cc Mon Sep 17 00:00:00 2001 From: tschettervictor Date: Sun, 28 Sep 2025 11:19:45 -0600 Subject: [PATCH 2/4] restart: be consistent with service command --- docs/chapters/subcommands/restart.rst | 14 ++++---- usr/local/share/bastille/restart.sh | 50 ++++++++++++--------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/docs/chapters/subcommands/restart.rst b/docs/chapters/subcommands/restart.rst index 86e3749b..7268d31f 100644 --- a/docs/chapters/subcommands/restart.rst +++ b/docs/chapters/subcommands/restart.rst @@ -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, the start the targetted jail(s). If a jail is not running, Bastille +will still start it. To avoide this, run the restart command with ``-i|--ignore`` to skip any jail(s) +that are not running. .. 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. \ No newline at end of file + -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. \ No newline at end of file diff --git a/usr/local/share/bastille/restart.sh b/usr/local/share/bastille/restart.sh index e9e34c73..fd94b898 100644 --- a/usr/local/share/bastille/restart.sh +++ b/usr/local/share/bastille/restart.sh @@ -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 @@ -113,16 +110,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} - else - ERRORS=$((ERRORS + 1)) + elif [ "${IGNORE}" -eq 1 ]; then + if check_target_is_stopped "${_jail}"; then + info "\n[${_jail}]:" + error_continue "Jail is stopped." + fi fi -done - -if [ "${ERRORS}" -ne 0 ]; then - error_exit "[ERROR]: Failed to restart ${ERRORS} jails." -fi \ No newline at end of file +done \ No newline at end of file From 3d8952d8f2906b86a9ee82894f5e55ed2713ce48 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 28 Sep 2025 11:24:59 -0600 Subject: [PATCH 3/4] Typo --- docs/chapters/subcommands/restart.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/chapters/subcommands/restart.rst b/docs/chapters/subcommands/restart.rst index 7268d31f..77462c7b 100644 --- a/docs/chapters/subcommands/restart.rst +++ b/docs/chapters/subcommands/restart.rst @@ -3,9 +3,9 @@ restart Restart jail(s). -Bastille will attempt to stop, the start the targetted jail(s). If a jail is not running, Bastille -will still start it. To avoide this, run the restart command with ``-i|--ignore`` to skip any jail(s) -that are not running. +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 From a85e7cc7a547ff89cc38f391aea8f52c956ef9c9 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 28 Sep 2025 11:25:35 -0600 Subject: [PATCH 4/4] Fix unused error var --- usr/local/share/bastille/restart.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/usr/local/share/bastille/restart.sh b/usr/local/share/bastille/restart.sh index fd94b898..771a092a 100644 --- a/usr/local/share/bastille/restart.sh +++ b/usr/local/share/bastille/restart.sh @@ -103,7 +103,6 @@ if [ "$#" -ne 1 ]; then fi TARGET="${1}" -ERRORS=0 bastille_root_check set_target "${TARGET}"