diff --git a/docs/chapters/subcommands/restart.rst b/docs/chapters/subcommands/restart.rst index 86e3749b..77462c7b 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, 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. \ 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 3db70675..771a092a 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 @@ -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 \ No newline at end of file +done \ No newline at end of file