fixup! fixup! WIP WORLD
This commit is contained in:
parent
848cfff268
commit
9ee73d75ea
50
abra
50
abra
@ -794,52 +794,44 @@ output_version_summary() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ensure_stack_deployed() {
|
ensure_stack_deployed() {
|
||||||
local stack=$1
|
|
||||||
local deployed=false
|
|
||||||
|
|
||||||
SERVICES=$($YQ e '.services | keys | .[]' "${APP_DIR}/${COMPOSE}" | tr '\n' ' ')
|
|
||||||
debug "Detected the following services: $(echo ${SERVICES})"
|
|
||||||
|
|
||||||
local -a UNHEALTHY # mapping
|
local -a UNHEALTHY # mapping
|
||||||
local -a HEALTHY # mapping
|
local -a HEALTHY # mapping
|
||||||
local -a UNKNOWN # mapping
|
local -a MISSING # mapping
|
||||||
|
|
||||||
services=$(docker stack services "${STACK_NAME}" --format "{{.ID}}" | tr '\n' ' ')
|
IFS=' ' read -r -a SERVICES <<< $(docker stack services "${STACK_NAME}" --format "{{.ID}}" | tr '\n' ' ')
|
||||||
debug "Detected the following service IDs: $(echo $services)"
|
debug "Detected the following services: ${SERVICES}"
|
||||||
|
|
||||||
without_health_checks = $(docker inspect --format)
|
|
||||||
|
|
||||||
# TODO: this tells you if shit is missing
|
|
||||||
docker inspect --format "{{ json .State }}" traefik_app.1.rnpar574ozsn6oi2ouo5s84jn | jq "try(.Health.Status // \"missing\")"
|
|
||||||
|
|
||||||
while [ ! "${#HEALTHY[@]}" -eq "$(( ${#SERVICES[@]} + 1 ))" ]; do
|
|
||||||
debug "Number of services expected to be healthy: $(( ${#SERVICES[@]} + 1 ))"
|
|
||||||
debug "Number of services actually healthy: ${#HEALTHY[@]}"
|
|
||||||
|
|
||||||
|
while [ ! $(( ${#HEALTHY[@]} + ${#MISSING[@]} )) -eq ${#SERVICES[@]} ]; do
|
||||||
for service in $(docker ps -f "name=$STACK_NAME" -q); do
|
for service in $(docker ps -f "name=$STACK_NAME" -q); do
|
||||||
local status=$(docker inspect --format "{{ .State.Health.Status }}" "$service")
|
healthcheck=$(docker inspect --format "{{ json .State }}" "$service" | jq "try(.Health.Status // \"missing\")")
|
||||||
local name=$(docker inspect --format '{{ index .Config.Labels "com.docker.swarm.service.name" }}' $service)
|
name=$(docker inspect --format '{{ index .Config.Labels "com.docker.swarm.service.name" }}' "$service")
|
||||||
|
|
||||||
debug "Processing $name (status: $status)..."
|
if [[ ${UNHEALTHY[*]} =~ ${name} ]] || [[ ${MISSING[*]} =~ ${name} ]]; then
|
||||||
|
debug "Already reported $name as failing/missing healthcheck, skipping..."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$status" == "unhealthy" ]]; then
|
if [[ "$healthcheck" == *"missing"* ]] && [[ ! "${MISSING[*]}" =~ $name ]]; then
|
||||||
local logs=$(docker inspect --format "{{ json .State.Health.Log }}" "$service")
|
debug "$name has no healthcheck, skipping..."
|
||||||
local exitcode="$(echo $logs | $JQ '.[-1] | .ExitCode')"
|
MISSING+=("$name")
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$healthcheck" == *"unhealthy"* ]]; then
|
||||||
|
logs=$(docker inspect --format "{{ json .State.Health.Log }}" "$service")
|
||||||
|
exitcode="$(echo $logs | $JQ '.[-1] | .ExitCode')"
|
||||||
warning "Healthcheck for new instance of $name is failing (exit code: $exitcode)"
|
warning "Healthcheck for new instance of $name is failing (exit code: $exitcode)"
|
||||||
warning "$(echo $logs | $JQ -r '.[-1] | .Output')"
|
warning "$(echo $logs | $JQ -r '.[-1] | .Output')"
|
||||||
debug "Placing $name in UNHEALTHY mapping..."
|
debug "Placing $name in UNHEALTHY mapping..."
|
||||||
UNHEALTHY+=("$name")
|
UNHEALTHY+=("$name")
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ${UNHEALTHY[*]} =~ ${name} ]]; then
|
if [[ "$healthcheck" == *"healthy"* ]] && [[ ! "${HEALTHY[*]}" =~ $name ]]; then
|
||||||
debug "Already reported $name as failing, skipping..."
|
|
||||||
continue
|
|
||||||
elif [[ "$status" == "healthy" ]] && [[ ! "${HEALTHY[*]}" =~ $name ]]; then
|
|
||||||
debug "$name is healthy, skipping..."
|
debug "$name is healthy, skipping..."
|
||||||
HEALTHY+=("$name")
|
HEALTHY+=("$name")
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
Reference in New Issue
Block a user