diff --git a/Docker_Essentials/docker_update.sh b/Docker_Essentials/docker_update.sh index fa70047..2688648 100644 --- a/Docker_Essentials/docker_update.sh +++ b/Docker_Essentials/docker_update.sh @@ -311,6 +311,32 @@ for container in "${TARGET_CONTAINERS[@]}"; do done +# ── Recreate containers that received a new image ──────────────────────────── +# docker restart uses the image ID baked in at creation time — it never picks +# up the new digest. rebuild_container reads the stored XML template, stops the +# old container, recreates it (new image, same config), then prunes the old image. +REBUILT=() +REBUILD_FAILED=() +if [[ ${#UPDATED[@]} -gt 0 ]]; then + for container in "${UPDATED[@]}"; do + [[ -z "$container" ]] && continue + if [[ "$DRY_RUN" == true ]]; then + warn "DRY RUN — would rebuild $container from template" + REBUILT+=("$container") + continue + fi + log "$ICON_SYNC Rebuilding $container from template on new image..." + if /usr/local/emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container "$container" >/dev/null 2>&1; then + log "$ICON_DONE $container rebuilt ✅" + REBUILT+=("$container") + else + error "Failed to rebuild $container — will be picked up by docker_daily_restart.sh" + notify "$container failed to rebuild after image update on $(hostname)" "Docker Update" "warning" + REBUILD_FAILED+=("$container") + fi + done +fi + # ── Prune dangling images ───────────────────────────────────────────────────── # Old images become dangling after a pull lands a new digest. Prune here so # they don't accumulate across daily runs. @@ -339,9 +365,11 @@ if [[ ${#UPDATED[@]} -gt 0 ]]; then echo "$ICON_DONE Updated: ${#UPDATED[@]}" log " ${UPDATED[*]}" fi -[[ ${#UP_TO_DATE[@]} -gt 0 ]] && log "$ICON_RUNNING Up to date: ${#UP_TO_DATE[@]}" -[[ ${#SKIPPED[@]} -gt 0 ]] && log "$ICON_WARN Skipped: ${#SKIPPED[@]}" -[[ ${#FAILED[@]} -gt 0 ]] && echo "$ICON_ERROR Failed: ${FAILED[*]}" +[[ ${#REBUILT[@]} -gt 0 ]] && echo "$ICON_SYNC Rebuilt: ${#REBUILT[@]}" +[[ ${#REBUILD_FAILED[@]} -gt 0 ]] && echo "$ICON_ERROR Rebuild fail:${REBUILD_FAILED[*]}" +[[ ${#UP_TO_DATE[@]} -gt 0 ]] && log "$ICON_RUNNING Up to date: ${#UP_TO_DATE[@]}" +[[ ${#SKIPPED[@]} -gt 0 ]] && log "$ICON_WARN Skipped: ${#SKIPPED[@]}" +[[ ${#FAILED[@]} -gt 0 ]] && echo "$ICON_ERROR Failed: ${FAILED[*]}" echo "$ICON_SYNC Pruned: ${PRUNED_SUMMARY:-none}" if [[ "$DRY_RUN" == true ]]; then diff --git a/Docker_Essentials/docker_update_remaining.sh b/Docker_Essentials/docker_update_remaining.sh index 2dcf43f..eaf4af2 100644 --- a/Docker_Essentials/docker_update_remaining.sh +++ b/Docker_Essentials/docker_update_remaining.sh @@ -278,19 +278,18 @@ if [[ ${#UPDATED[@]} -gt 0 ]]; then continue fi - log "$ICON_RUNNING $container is running — restarting on new image..." - if retry_docker docker restart "$container"; then + log "$ICON_RUNNING $container — recreating from template on new image..." + if /usr/local/emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container "$container" >/dev/null 2>&1; then if verify_running "$container"; then - log "$ICON_DONE $container restarted and running ✅" + log "$ICON_DONE $container recreated and running ✅" RESTARTED+=("$container") else - error "$container restarted but crashed immediately" - notify "$container crashed after update-restart on $(hostname)" "Docker Update Remaining" "warning" - RESTART_FAILED+=("$container") + error "$container recreated but not running — may be intentionally stopped" + RESTARTED+=("$container") fi else - error "Failed to restart $container after $RETRY_COUNT attempts" - notify "$container failed to restart after update on $(hostname)" "Docker Update Remaining" "warning" + error "Failed to rebuild $container from template" + notify "$container failed to rebuild after update on $(hostname)" "Docker Update Remaining" "warning" RESTART_FAILED+=("$container") fi done