This commit is contained in:
2026-03-29 16:20:52 +02:00
parent 28c3ca5a9c
commit b4c99d6ca7

View File

@@ -99,6 +99,16 @@ get_local_image_digest() {
docker inspect --format='{{index .RepoDigests 0}}' "$image" 2>/dev/null || echo "unknown"
}
is_running() {
local svc="$1"
local cid
cid=$(docker compose ps -q "$svc" 2>/dev/null || true)
[ -z "$cid" ] && return 1
docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null | grep -q true
}
run_cmd() {
if [ "$DRY_RUN" = true ]; then
log DEBUG "[DRY RUN] $*"
@@ -132,10 +142,6 @@ error_flag=false
cd "$COMPOSE_DIR"
# =============================
# Sortierung
# =============================
while IFS= read -r -d '' file; do
dir=$(dirname "$file")
@@ -156,6 +162,16 @@ while IFS= read -r -d '' file; do
total_services=${#services[@]}
current_index=0
# Running State merken
declare -A was_running
for svc in "${services[@]}"; do
if is_running "$svc"; then
was_running["$svc"]=1
else
was_running["$svc"]=0
fi
done
stack_updated=false
changed_services=()
version_report=()
@@ -224,14 +240,15 @@ while IFS= read -r -d '' file; do
log WARN " 🔄 Einzelcontainer-Update: $svc"
if ! run_cmd docker compose up -d "$svc" >/dev/null 2>&1; then
log ERROR " ❌ Update fehlgeschlagen"
error_flag=true
if [ "${was_running[$svc]}" = 1 ]; then
run_cmd docker compose up -d "$svc"
else
log INFO " ✔️ Container erfolgreich aktualisiert"
notify_stacks_updated+=("$stack ($svc)")
run_cmd docker compose create "$svc"
fi
log INFO " ✔️ Container aktualisiert"
notify_stacks_updated+=("$stack ($svc)")
else
log WARN " 🔄 Stack wird neu deployt (Trigger: ${changed_services[*]})"
@@ -240,6 +257,15 @@ while IFS= read -r -d '' file; do
error_flag=true
else
log INFO " ✔️ Stack erfolgreich aktualisiert"
# vorher gestoppte wieder stoppen
for svc in "${services[@]}"; do
if [ "${was_running[$svc]}" = 0 ]; then
log INFO " ⏹️ Stoppe $svc (war vorher gestoppt)"
run_cmd docker compose stop "$svc" >/dev/null 2>&1 || true
fi
done
notify_stacks_updated+=("$stack (${changed_services[*]})")
fi
fi
@@ -274,7 +300,6 @@ if [ "$NTFY_ENABLED" = true ]; then
done
fi
# Priority fix
if [ "$error_flag" = true ]; then
msg+=$'\n\n❗ Fehler sind aufgetreten Logs prüfen'
PRIORITY=5
@@ -301,4 +326,4 @@ if [ "$NTFY_ENABLED" = true ]; then
fi
fi
log INFO "==== Update beendet ===="
log INFO "==== Update beendet ===="