From 551a637831ea349f0ddcf0723d00059a607a7742 Mon Sep 17 00:00:00 2001 From: mmorgan-pt <99763568+mmorgan-pt@users.noreply.github.com> Date: Fri, 20 Dec 2024 21:30:35 -0700 Subject: [PATCH] Mm/stop and start tweak (#169) * add checks for the stop process * function, not variable * docker not compose * bumpversion and update more comments --- .bumpversion.cfg | 2 +- src/_stop.sh | 23 +++++++++++++++++++++++ src/plextrac | 6 +++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 25fdf23..f824b5c 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.7.13 +current_version = 0.7.14 commit = True tag = True diff --git a/src/_stop.sh b/src/_stop.sh index f2850fe..63ba004 100644 --- a/src/_stop.sh +++ b/src/_stop.sh @@ -6,6 +6,29 @@ function mod_stop() { title "Attempting to gracefully stop PlexTrac..." debug "Stopping API Services..." + + # Before stopping, check if stable is being used and the current image tag for stable is correct + if [[ "$UPGRADE_STRATEGY" == "stable" ]]; then + debug "Running stable, validating the expected version against current running version" + running_backend_version="$(for i in $(compose_client ps plextracapi -q); do docker container inspect "$i" --format json | jq -r '(.[].Config.Labels | ."org.opencontainers.image.version")'; done | sort -u)" + running_frontend_version="$(for i in $(compose_client ps plextracnginx -q); do docker container inspect "$i" --format json | jq -r '(.[].Config.Labels | ."org.opencontainers.image.version")'; done | sort -u)" + expected_backend_tag="$(compose_client config | grep image | grep plextracapi | head -n 1 | awk '{print $2}')" + expected_frontend_tag="$(compose_client config | grep image | grep plextracnginx | head -n 1 | awk '{print $2}')" + expected_backend_version="$(docker image inspect $expected_backend_tag --format json | jq -r '(.[].Config.Labels | ."org.opencontainers.image.version")')" + expected_frontend_version="$(docker image inspect $expected_frontend_tag --format json | jq -r '(.[].Config.Labels | ."org.opencontainers.image.version")')" + + if [[ "$running_backend_version" != "$expected_backend_version" ]]; then + error "The running backend version ${running_backend_version} does not match the expected version (${expected_backend_version})" + error "During a system reboot or shutdown, the docker engine normally handles this gracefully and automatically, so using 'plextrac stop' may be unnecessary" + die "Since 'plextrac stop' runs a docker compose down, we cannot guarantee a 'plextrac start' will bring up the correct version. Please change UPGRADE_STRATEGY to the current running version ${running_backend_version} or run an update first" + fi + if [[ "$running_frontend_version" != "$expected_frontend_version" ]]; then + error "The running frontend version (${running_frontend_version}) does not match the expected version (${expected_frontend_version})" + error "During a system reboot or shutdown, the docker engine normally handles this gracefully and automatically, so using 'plextrac stop' may be unnecessary" + die "Since 'plextrac stop' runs a docker compose down, we cannot guarantee a 'plextrac start' will bring up the correct version. Please change UPGRADE_STRATEGY to the current running version ${running_frontend_version} or run an update first" + fi + fi + for service in $(container_client ps --format '{{.Names}}' | grep -Eo 'plextracapi|plextracnginx|notification-engine|notification-sender|contextual-scoring-service'); do if [ "$CONTAINER_RUNTIME" == "podman" ]; then container_client stop $service diff --git a/src/plextrac b/src/plextrac index 773ea7f..7431a29 100755 --- a/src/plextrac +++ b/src/plextrac @@ -1,7 +1,7 @@ #!/bin/bash set -Eeuo pipefail -VERSION=0.7.13 +VERSION=0.7.14 ## Podman Global Declaration Variable declare -A svcValues @@ -126,8 +126,8 @@ function mod_help() { log "migrate ${DIM}migrate current instance from legacy management scripts${RESET}" log "reload-cert ${DIM}reload PlexTrac SSL certificates${RESET}" log "restore ${DIM}restore instance from backups${RESET}" - log "start ${DIM}start a PlexTrac instance${RESET}" - log "stop ${DIM}stop PlexTrac${RESET}" + log "start ${DIM}manually start a PlexTrac instance if normal processes did not succeed${RESET}" + log "stop ${DIM}manually stops the PlexTrac instance. Not a part of normal maintenance${RESET}" log "update ${DIM}updates the management utility & applies any configuration or application updates${RESET}" log "" info "Available flags to modify command behavior:"