Skip to content

Commit

Permalink
Mm/stop and start tweak (#169)
Browse files Browse the repository at this point in the history
* add checks for the stop process

* function, not variable

* docker not compose

* bumpversion and update more comments
  • Loading branch information
mmorgan-pt authored Dec 21, 2024
1 parent cf565aa commit 551a637
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.7.13
current_version = 0.7.14

commit = True
tag = True
Expand Down
23 changes: 23 additions & 0 deletions src/_stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/plextrac
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -Eeuo pipefail

VERSION=0.7.13
VERSION=0.7.14

## Podman Global Declaration Variable
declare -A svcValues
Expand Down Expand Up @@ -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:"
Expand Down

0 comments on commit 551a637

Please sign in to comment.