From aad11581468b35ae4acfc18efdd7118f1771eefb Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sat, 15 Mar 2025 21:35:03 -0600 Subject: [PATCH] Add -b|--boot for start/stop/restart --- usr/local/share/bastille/create.sh | 8 +++++++- usr/local/share/bastille/restart.sh | 20 ++++++++++++++++++++ usr/local/share/bastille/start.sh | 19 +++++++++++++++++-- usr/local/share/bastille/stop.sh | 19 +++++++++++++++++-- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/usr/local/share/bastille/create.sh b/usr/local/share/bastille/create.sh index 2873e591..8fdb9ef2 100644 --- a/usr/local/share/bastille/create.sh +++ b/usr/local/share/bastille/create.sh @@ -46,6 +46,7 @@ usage() { -E | --empty Creates an empty container, intended for custom jail builds (thin/thick/linux or unsupported). -L | --linux This option is intended for testing with Linux jails, this is considered experimental. -M | --static-mac Generate a static MAC address for jail (VNET only). + --no-boot Create jail with boot=off. --no-validate Do not validate the release when creating the jail. -p | --priority VALUE Sets the priority value for jail startup and shutdown. -T | --thick Creates a thick container, they consume more space as they are self contained and independent. @@ -657,7 +658,7 @@ create_jail() { fi # Apply priority and boot settings - sysrc -f "${bastille_jailsdir}/${NAME}/boot.conf" boot=on + sysrc -f "${bastille_jailsdir}/${NAME}/boot.conf" boot=${BOOT} sysrc -f "${bastille_jailsdir}/${NAME}/boot.conf" priority="${PRIORITY}" } @@ -671,6 +672,7 @@ if echo "${3}" | grep '@'; then fi # Handle options. +BOOT="on" EMPTY_JAIL="" THICK_JAIL="" CLONE_JAIL="" @@ -719,6 +721,10 @@ while [ $# -gt 0 ]; do error_exit "Not a valid priority value: \"${2}\"" fi ;; + --no-boot) + BOOT="off" + shift + ;; --no-validate|no-validate) VALIDATE_RELEASE="" shift diff --git a/usr/local/share/bastille/restart.sh b/usr/local/share/bastille/restart.sh index ffdb1650..8a4ff32e 100644 --- a/usr/local/share/bastille/restart.sh +++ b/usr/local/share/bastille/restart.sh @@ -30,5 +30,25 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +usage() { + error_notify "Usage: bastille restart [option(s)] TARGET" + cat << EOF + Options: + + -b | --boot Respect jail boot setting. + -v | --verbose Print every action on jail start. + -x | --debug Enable debug mode. + +EOF + exit 1 +} + +# Handle options. +case "${1}" in + -h|--help|help) + usage + ;; +esac + bastille stop "$@" bastille start "$@" diff --git a/usr/local/share/bastille/start.sh b/usr/local/share/bastille/start.sh index 8a0960d1..4e4f3e44 100644 --- a/usr/local/share/bastille/start.sh +++ b/usr/local/share/bastille/start.sh @@ -38,20 +38,26 @@ usage() { cat << EOF Options: - -v | --verbose Print every action on jail start. - -x | --debug Enable debug mode. + -b | --boot Respect jail boot setting. + -v | --verbose Print every action on jail start. + -x | --debug Enable debug mode. EOF exit 1 } # Handle options. +BOOT=0 OPTION="" while [ "$#" -gt 0 ]; do case "${1}" in -h|--help|help) usage ;; + -b|--boot) + BOOT=1 + shift + ;; -v|--verbose) OPTION="-v" shift @@ -63,6 +69,7 @@ while [ "$#" -gt 0 ]; do -*) for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do case ${_opt} in + b) BOOT=1 ;; v) OPTION="-v" ;; x) enable_debug ;; *) error_exit "Unknown Option: \"${1}\"" ;; @@ -87,6 +94,14 @@ 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}/boot.conf -n boot)" + if [ "${BOOT_ENABLED}" = "off" ]; then + continue + fi + fi + info "[${_jail}]:" check_target_is_stopped "${_jail}" || error_continue "Jail is already running." diff --git a/usr/local/share/bastille/stop.sh b/usr/local/share/bastille/stop.sh index 124cef24..41441290 100644 --- a/usr/local/share/bastille/stop.sh +++ b/usr/local/share/bastille/stop.sh @@ -38,20 +38,26 @@ usage() { cat << EOF Options: - -v | --verbose Print every action on jail stop. - -x | --debug Enable debug mode. + -b | --boot Respect jail boot setting. + -v | --verbose Print every action on jail stop. + -x | --debug Enable debug mode. EOF exit 1 } # Handle options. +BOOT=0 OPTION="" while [ "$#" -gt 0 ]; do case "${1}" in -h|--help|help) usage ;; + -b|--boot) + BOOT=1 + shift + ;; -v|--verbose) OPTION="-v" shift @@ -63,6 +69,7 @@ while [ "$#" -gt 0 ]; do -*) for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do case ${_opt} in + b) BOOT="1" ;; v) OPTION="-v" ;; x) enable_debug ;; *) error_exit "Unknown Option: \"${1}\"" ;; @@ -87,6 +94,14 @@ 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}/boot.conf -n boot)" + if [ "${BOOT_ENABLED}" = "off" ]; then + continue + fi + fi + info "[${_jail}]:" check_target_is_running "${_jail}" || error_continue "Jail is already stopped."