Show correct status for missing contexts

Closes #99.
This commit is contained in:
decentral1se 2021-03-18 19:45:30 +01:00
parent f5951add54
commit f382765f29
Signed by: decentral1se
GPG Key ID: 92DAD76BD9567B8A
1 changed files with 8 additions and 1 deletions

9
abra
View File

@ -755,12 +755,13 @@ sub_app_list (){
fi
local -a DEPLOYED_APPS # array
local -a CHECKED_SERVERS # array
warning "Loading status from ${#SERVERS[@]} server(s), patience advised.."
for SERVER in "${SERVERS[@]}"; do
SERVER="${SERVER##*/}" # basename
mapfile -t SERVER_APPS < <(DOCKER_CONTEXT="$SERVER" docker stack ls --format '{{ .Name }}')
mapfile -t SERVER_APPS < <(DOCKER_CONTEXT="$SERVER" docker stack ls --format '{{ .Name }}' 2>/dev/null)
# add $SERVER~ to the start of each DEPLOYED_APPS
DEPLOYED_APPS+=("${SERVER_APPS[@]/#/$SERVER~}")
done
@ -800,6 +801,12 @@ sub_app_list (){
fi
if [ -n "$STATUS" ]; then
APP_STATUS=$( printf '%s\n' "${DEPLOYED_APPS[@]}" | grep -qP "^${SERVER}~${APP_STACK_NAME}$" && echo "deployed" || echo "inactive")
if [[ "$APP_STATUS" == "inactive" ]] && [[ ! ${CHECKED_SERVERS[*]} =~ ${SERVER} ]]; then
CHECKED_SERVERS+=("$SERVER")
if ! docker context inspect "$SERVER" > /dev/null 2>&1; then
APP_STATUS="unknown"
fi
fi
fi
printf " %s\t%s\t%s%s\n" "$DOMAIN" "$TYPE" "$SERVER" "${STATUS:+ }${APP_STATUS}"
done | column -s' ' -t