From ba269dde2c66deb904becd9efbb114aeb4310e65 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Sat, 28 Nov 2026 16:17:56 +0100 Subject: [PATCH] Host tools: report the containers' real exit code and what failed (#19152) update-lxcs and clean-lxcs ended with 1 even when every failed container gave the same code (141 of 163 update-lxcs failures in a week were apt's 100); they now exit with that code. update-apps adds the failing step from the engine's .errinfo in the container, so "exit code: 1" says what broke. --- tools/pve/clean-lxcs.sh | 5 +++++ tools/pve/update-apps.sh | 13 ++++++++++--- tools/pve/update-lxcs.sh | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/pve/clean-lxcs.sh b/tools/pve/clean-lxcs.sh index eafaaf819..860738024 100644 --- a/tools/pve/clean-lxcs.sh +++ b/tools/pve/clean-lxcs.sh @@ -161,6 +161,11 @@ if [ "${#failed_containers[@]}" -gt 0 ]; then [ -s "$RUN_LOG" ] && echo -e "Their output: $RUN_LOG\n" printf -v CS_ERROR_MSG '%s; ' "${failed_containers[@]}" CS_ERROR_MSG="Cleaning failed in ${#failed_containers[@]} container(s): ${CS_ERROR_MSG%; }" + # One code shared by every failed container is the real one (100 is apt), not "1". + codes=$(printf '%s\n' "${failed_containers[@]}" | sed -n 's/^[^:]*: cleaning exited with \([0-9]*\).*/\1/p') + if [[ -n "$codes" && $(wc -l <<<"$codes") -eq ${#failed_containers[@]} && $(sort -u <<<"$codes" | wc -l) -eq 1 ]]; then + exit "$(head -n1 <<<"$codes")" + fi exit 1 fi echo -e "${GN} Finished, Selected Containers Cleaned. ${CL} \n" diff --git a/tools/pve/update-apps.sh b/tools/pve/update-apps.sh index 2aaaa10ba..db75e256c 100644 --- a/tools/pve/update-apps.sh +++ b/tools/pve/update-apps.sh @@ -620,6 +620,7 @@ for container in $CHOICE; do fi #4) Update service, using the update command + pct exec "$container" -- touch /tmp/.cs-update-start 2>/dev/null || true # Prepend a no-op 'clear' wrapper to PATH so update scripts calling clear # don't fail without a TTY — works for all shells incl. ash (no export -f) SETUP_CMD="mkdir -p /tmp/.nc; printf '#!/bin/sh\n:\n' > /tmp/.nc/clear; chmod +x /tmp/.nc/clear; export PATH=/tmp/.nc:\$PATH; export TERM=dumb; " @@ -631,6 +632,12 @@ for container in $CHOICE; do opensuse) pct exec "$container" -- bash -c "${SETUP_CMD}${UPDATE_CMD}" ;; esac exit_code=$? + # The engine in the container leaves what failed in an .errinfo file; without it + # the report says only "exit code: 1". + update_detail="" + if [ $exit_code -ne 0 ]; then + update_detail=$(pct exec "$container" -- sh -c 'f=$(find /root /tmp -maxdepth 1 -name "*.errinfo" -newer /tmp/.cs-update-start 2>/dev/null | head -n1); [ -n "$f" ] || exit 0; m=$(sed -n "s/^MESSAGE=//p" "$f" | head -n1); [ -n "$m" ] || m=$(sed -n "s/^COMMAND=//p" "$f" | head -n1); printf "%s" "$m" | head -c 200' 2>/dev/null || true) + fi #5) if build resources are different than run resources, then: if [ "$UPDATE_BUILD_RESOURCES" -eq "1" ]; then @@ -665,7 +672,7 @@ for container in $CHOICE; do log_result "$container" "$service" "SKIPPED" "Storage critically low on /boot (>80%)" log_write "Container $container ($service): SKIPPED — storage critically low on /boot" elif [ "$BACKUP_CHOICE" == "yes" ]; then - msg_error "Update failed for container $container ($service, exit code: $exit_code) — attempting restore" + msg_error "Update failed for container $container ($service, exit code: $exit_code)${update_detail:+: $update_detail} — attempting restore" log_write "Container $container ($service): FAILED (exit $exit_code) — attempting restore" msg_info "Restoring LXC $container from backup ($STORAGE_CHOICE)" wait @@ -703,8 +710,8 @@ for container in $CHOICE; do exit 235 fi else - msg_error "Update failed for container $container ($service, exit code: $exit_code)" - log_result "$container" "$service" "FAILED" "Exit code $exit_code" + msg_error "Update failed for container $container ($service, exit code: $exit_code)${update_detail:+: $update_detail}" + log_result "$container" "$service" "FAILED" "Exit code $exit_code${update_detail:+: $update_detail}" log_write "Container $container ($service): FAILED (exit $exit_code)" if [[ "$var_continue_on_error" == "yes" ]]; then echo -e "${YW}[WARN]${CL} Continuing to next container (var_continue_on_error=yes)" diff --git a/tools/pve/update-lxcs.sh b/tools/pve/update-lxcs.sh index 0caa4f581..085be6547 100644 --- a/tools/pve/update-lxcs.sh +++ b/tools/pve/update-lxcs.sh @@ -174,5 +174,10 @@ echo "" if [ "${#failed_containers[@]}" -gt 0 ]; then printf -v CS_ERROR_MSG '%s; ' "${failed_containers[@]}" CS_ERROR_MSG="Update failed in ${#failed_containers[@]} container(s): ${CS_ERROR_MSG%; }" + # One code shared by every failed container is the real one (100 is apt), not "1". + codes=$(printf '%s\n' "${failed_containers[@]}" | sed -n 's/^[^:]*: update exited with \([0-9]*\).*/\1/p') + if [[ -n "$codes" && $(wc -l <<<"$codes") -eq ${#failed_containers[@]} && $(sort -u <<<"$codes" | wc -l) -eq 1 ]]; then + exit "$(head -n1 <<<"$codes")" + fi exit 1 fi