diff --git a/misc/alpine-install.func b/misc/alpine-install.func index 28b6ce8d4..a870b8650 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -148,6 +148,7 @@ motd_ssh() { # Start the sshd service $STD /etc/init.d/sshd start fi + post_progress_to_api } # Validate Timezone for some LXC's @@ -184,5 +185,5 @@ EOF echo "bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/${app}.sh)\"" >/usr/bin/update chmod +x /usr/bin/update - + post_progress_to_api } diff --git a/misc/api.func b/misc/api.func index 0ae647ca2..aedbf93ae 100644 --- a/misc/api.func +++ b/misc/api.func @@ -688,6 +688,29 @@ EOF POST_TO_API_DONE=true } +# ------------------------------------------------------------------------------ +# post_progress_to_api() +# +# - Lightweight progress ping from host or container +# - Updates the existing telemetry record status to "configuring" +# - Signals that the installation is actively progressing (not stuck) +# - Fire-and-forget: never blocks or fails the script +# - Only executes if DIAGNOSTICS=yes and RANDOM_UUID is set +# - Can be called multiple times safely +# ------------------------------------------------------------------------------ +post_progress_to_api() { + command -v curl &>/dev/null || return 0 + [[ "${DIAGNOSTICS:-no}" == "no" ]] && return 0 + [[ -z "${RANDOM_UUID:-}" ]] && return 0 + + local app_name="${NSAPP:-${app:-unknown}}" + local telemetry_type="${TELEMETRY_TYPE:-lxc}" + + curl -fsS -m 5 -X POST "${TELEMETRY_URL:-https://telemetry.community-scripts.org/telemetry}" \ + -H "Content-Type: application/json" \ + -d "{\"random_id\":\"${RANDOM_UUID}\",\"execution_id\":\"${EXECUTION_ID:-${RANDOM_UUID}}\",\"type\":\"${telemetry_type}\",\"nsapp\":\"${app_name}\",\"status\":\"configuring\"}" &>/dev/null || true +} + # ------------------------------------------------------------------------------ # post_update_to_api() # diff --git a/misc/build.func b/misc/build.func index f39e37f61..8bfae32ef 100644 --- a/misc/build.func +++ b/misc/build.func @@ -3660,9 +3660,6 @@ $PCT_OPTIONS_STRING" exit 214 fi msg_ok "Storage space validated" - - # Report installation start to API (early - captures failed installs too) - post_to_api fi create_lxc_container || exit $? @@ -3908,6 +3905,7 @@ EOF for i in {1..10}; do if pct status "$CTID" | grep -q "status: running"; then msg_ok "Started LXC Container" + post_progress_to_api # Signal container is running break fi sleep 1 @@ -3962,6 +3960,7 @@ EOF echo -e "${YW}Container may have limited internet access. Installation will continue...${CL}" else msg_ok "Network in LXC is reachable (ping)" + post_progress_to_api # Signal network is ready fi fi # Function to get correct GID inside container @@ -4033,6 +4032,7 @@ EOF' fi msg_ok "Customized LXC Container" + post_progress_to_api # Signal ready for app installation # Optional DNS override for retry scenarios (inside LXC, never on host) if [[ "${DNS_RETRY_OVERRIDE:-false}" == "true" ]]; then @@ -4888,6 +4888,9 @@ create_lxc_container() { exit 206 fi + # Report installation start to API early - captures failures in storage/template/create + post_to_api + # Storage capability check check_storage_support "rootdir" || { msg_error "No valid storage found for 'rootdir' [Container]" @@ -5417,9 +5420,7 @@ create_lxc_container() { } msg_ok "LXC Container ${BL}$CTID${CL} ${GN}was successfully created." - - # Report container creation to API - post_to_api + post_progress_to_api # Signal container creation complete } # ============================================================================== diff --git a/misc/core.func b/misc/core.func index 838ebdd85..0b6b14846 100644 --- a/misc/core.func +++ b/misc/core.func @@ -1496,6 +1496,11 @@ cleanup_lxc() { fi msg_ok "Cleaned" + + # Send progress ping if available (defined in install.func) + if declare -f post_progress_to_api &>/dev/null; then + post_progress_to_api + fi } # ------------------------------------------------------------------------------ diff --git a/misc/error_handler.func b/misc/error_handler.func index a6e7b49c3..380b52c85 100644 --- a/misc/error_handler.func +++ b/misc/error_handler.func @@ -204,6 +204,12 @@ error_handler() { printf "\e[?25h" + # ALWAYS report failure to API immediately - don't wait for container checks + # This ensures we capture failures that occur before/after container exists + if declare -f post_update_to_api &>/dev/null; then + post_update_to_api "failed" "$exit_code" 2>/dev/null || true + fi + # Use msg_error if available, fallback to echo if declare -f msg_error >/dev/null 2>&1; then msg_error "in line ${line_number}: exit code ${exit_code} (${explanation}): while executing command ${command}" @@ -254,11 +260,6 @@ error_handler() { # Offer to remove container if it exists (build errors after container creation) if [[ -n "${CTID:-}" ]] && command -v pct &>/dev/null && pct status "$CTID" &>/dev/null; then - # Report failure to API before container cleanup - if declare -f post_update_to_api &>/dev/null; then - post_update_to_api "failed" "$exit_code" - fi - echo "" if declare -f msg_custom >/dev/null 2>&1; then echo -en "${TAB}❓${TAB}${YW}Remove broken container ${CTID}? (Y/n) [auto-remove in 60s]: ${CL}" diff --git a/misc/install.func b/misc/install.func index 8253c4272..69b1498ec 100644 --- a/misc/install.func +++ b/misc/install.func @@ -285,6 +285,7 @@ motd_ssh() { sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config systemctl restart sshd fi + post_progress_to_api } # ============================================================================== @@ -323,4 +324,5 @@ EOF chmod 700 /root/.ssh chmod 600 /root/.ssh/authorized_keys fi + post_progress_to_api }