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" 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() { run_cmd() {
if [ "$DRY_RUN" = true ]; then if [ "$DRY_RUN" = true ]; then
log DEBUG "[DRY RUN] $*" log DEBUG "[DRY RUN] $*"
@@ -132,10 +142,6 @@ error_flag=false
cd "$COMPOSE_DIR" cd "$COMPOSE_DIR"
# =============================
# Sortierung
# =============================
while IFS= read -r -d '' file; do while IFS= read -r -d '' file; do
dir=$(dirname "$file") dir=$(dirname "$file")
@@ -156,6 +162,16 @@ while IFS= read -r -d '' file; do
total_services=${#services[@]} total_services=${#services[@]}
current_index=0 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 stack_updated=false
changed_services=() changed_services=()
version_report=() version_report=()
@@ -224,14 +240,15 @@ while IFS= read -r -d '' file; do
log WARN " 🔄 Einzelcontainer-Update: $svc" log WARN " 🔄 Einzelcontainer-Update: $svc"
if ! run_cmd docker compose up -d "$svc" >/dev/null 2>&1; then if [ "${was_running[$svc]}" = 1 ]; then
log ERROR " ❌ Update fehlgeschlagen" run_cmd docker compose up -d "$svc"
error_flag=true
else else
log INFO " ✔️ Container erfolgreich aktualisiert" run_cmd docker compose create "$svc"
notify_stacks_updated+=("$stack ($svc)")
fi fi
log INFO " ✔️ Container aktualisiert"
notify_stacks_updated+=("$stack ($svc)")
else else
log WARN " 🔄 Stack wird neu deployt (Trigger: ${changed_services[*]})" log WARN " 🔄 Stack wird neu deployt (Trigger: ${changed_services[*]})"
@@ -240,6 +257,15 @@ while IFS= read -r -d '' file; do
error_flag=true error_flag=true
else else
log INFO " ✔️ Stack erfolgreich aktualisiert" 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[*]})") notify_stacks_updated+=("$stack (${changed_services[*]})")
fi fi
fi fi
@@ -274,7 +300,6 @@ if [ "$NTFY_ENABLED" = true ]; then
done done
fi fi
# Priority fix
if [ "$error_flag" = true ]; then if [ "$error_flag" = true ]; then
msg+=$'\n\n❗ Fehler sind aufgetreten Logs prüfen' msg+=$'\n\n❗ Fehler sind aufgetreten Logs prüfen'
PRIORITY=5 PRIORITY=5