From a3186506b4cd4c6ec617fd7dbe52d19ba7bfcd43 Mon Sep 17 00:00:00 2001 From: Michael Burke <72173919+Michael-Burke@users.noreply.github.com> Date: Mon, 20 May 2024 20:59:51 -0600 Subject: [PATCH] Added override flag to manager util (#135) * Added override flag to manager util * Bumped version to 0.6.7 --- .bumpversion.cfg | 2 +- src/_manage_postgres.sh | 96 +++++++++++++++++++++-------------------- src/plextrac | 2 +- 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index f82b96e..f0fd453 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.6.6 +current_version = 0.6.7 commit = True tag = True diff --git a/src/_manage_postgres.sh b/src/_manage_postgres.sh index 990f2ee..05284e5 100644 --- a/src/_manage_postgres.sh +++ b/src/_manage_postgres.sh @@ -145,64 +145,68 @@ function mod_autofix() { } function mod_check_etl_status() { - local migration_exited="running" - title "Checking Data Migration Status" - info "Checking Migration Status" - if [ "$CONTAINER_RUNTIME" == "podman" ]; then - local migration_exited=$(podman container inspect --format '{{.State.Status}}' "migrations") - else - local migration_exited=$(docker inspect --format '{{.State.Status}}' "plextrac-couchbase-migrations-1") - fi - while [ "$migration_exited" == "running" ]; do - # Check if the migration container has exited, e.g., migrations have completed or failed + if [ "${IGNORE_ETL_STATUS:-false}" == "false" ]; then + local migration_exited="running" + title "Checking Data Migration Status" + info "Checking Migration Status" if [ "$CONTAINER_RUNTIME" == "podman" ]; then local migration_exited=$(podman container inspect --format '{{.State.Status}}' "migrations") else local migration_exited=$(docker inspect --format '{{.State.Status}}' "plextrac-couchbase-migrations-1") fi - for s in / - \\ \|; do printf "\r$s"; sleep .1; done - done - printf "\r" - info "Migrations complete" + while [ "$migration_exited" == "running" ]; do + # Check if the migration container has exited, e.g., migrations have completed or failed + if [ "$CONTAINER_RUNTIME" == "podman" ]; then + local migration_exited=$(podman container inspect --format '{{.State.Status}}' "migrations") + else + local migration_exited=$(docker inspect --format '{{.State.Status}}' "plextrac-couchbase-migrations-1") + fi + for s in / - \\ \|; do printf "\r$s"; sleep .1; done + done + printf "\r" + info "Migrations complete" - title "Checking Data ETL Status" - debug "Checking ETL health and status..." - ETL_OUTPUT=${ETL_OUTPUT:-true} - if [ "$CONTAINER_RUNTIME" == "podman" ]; then - local api_running=$(podman container inspect --format '{{.State.Status}}' "plextracapi" | wc -l) - else - local api_running=$(compose_client ps -q plextracapi | wc -l) - fi - if [ $api_running -gt 0 ]; then + title "Checking Data ETL Status" + debug "Checking ETL health and status..." + ETL_OUTPUT=${ETL_OUTPUT:-true} if [ "$CONTAINER_RUNTIME" == "podman" ]; then - RAW_OUTPUT=$(podman exec plextracapi npm run pg:etl:status --no-update-notifier --if-present) + local api_running=$(podman container inspect --format '{{.State.Status}}' "plextracapi" | wc -l) else - RAW_OUTPUT=$(compose_client exec plextracapi npm run pg:etl:status --no-update-notifier --if-present) - fi - if [ "$RAW_OUTPUT" == "" ]; then - debug "No ETL status output found or it failed to run." - return + local api_running=$(compose_client ps -q plextracapi | wc -l) fi - # Find the json content by looking for the first line that starts - # with an opening brace and the first line that starts with a closing brace. - JSON_OUTPUT=$(echo "$RAW_OUTPUT" | sed '/^{/,/^}/!d') - - # Find the summary content by finding the first line that starts - # with a closing brace and selecting all remaining lines after that one. - SUMMARY_OUTPUT=$(echo "$RAW_OUTPUT" | sed '1,/^}/d') - ETLS_COMBINED_STATUS=$(echo $JSON_OUTPUT | jq -r .etlsCombinedStatus) - if [ "${ETL_OUTPUT:-true}" == "true" ]; then - msg "$SUMMARY_OUTPUT\n" - debug "$JSON_OUTPUT\n" - fi - - if [[ "$ETLS_COMBINED_STATUS" == "HEALTHY" ]]; then - info "All ETLs are in a healthy status." + if [ $api_running -gt 0 ]; then + if [ "$CONTAINER_RUNTIME" == "podman" ]; then + RAW_OUTPUT=$(podman exec plextracapi npm run pg:etl:status --no-update-notifier --if-present) else - etl_failure + RAW_OUTPUT=$(compose_client exec plextracapi npm run pg:etl:status --no-update-notifier --if-present) + fi + if [ "$RAW_OUTPUT" == "" ]; then + debug "No ETL status output found or it failed to run." + return + fi + # Find the json content by looking for the first line that starts + # with an opening brace and the first line that starts with a closing brace. + JSON_OUTPUT=$(echo "$RAW_OUTPUT" | sed '/^{/,/^}/!d') + + # Find the summary content by finding the first line that starts + # with a closing brace and selecting all remaining lines after that one. + SUMMARY_OUTPUT=$(echo "$RAW_OUTPUT" | sed '1,/^}/d') + ETLS_COMBINED_STATUS=$(echo $JSON_OUTPUT | jq -r .etlsCombinedStatus) + if [ "${ETL_OUTPUT:-true}" == "true" ]; then + msg "$SUMMARY_OUTPUT\n" + debug "$JSON_OUTPUT\n" + fi + + if [[ "$ETLS_COMBINED_STATUS" == "HEALTHY" ]]; then + info "All ETLs are in a healthy status." + else + etl_failure + fi + else + info "PlexTrac API container not running, skipping ETL status check" fi else - info "PlexTrac API container not running, skipping ETL status check" + error "Skipping ETL status check" fi } diff --git a/src/plextrac b/src/plextrac index a389908..3c2acc5 100755 --- a/src/plextrac +++ b/src/plextrac @@ -1,7 +1,7 @@ #!/bin/bash set -Eeuo pipefail -VERSION=0.6.6 +VERSION=0.6.7 ## Podman Global Declaration Variable declare -A svcValues