From 79aaf2a25e266b48b59752b4533b8f12a3454ca8 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Tue, 24 Mar 2026 08:57:11 +0100 Subject: [PATCH] Preserve telemetry type and report failures Respect a pre-set TELEMETRY_TYPE in misc/api.func and use it in the API payload instead of the hardcoded "lxc". In turnkey/turnkey.sh, set TELEMETRY_TYPE="turnkey" for turnkey installs and enhance turnkey_cleanup() to report failed installs to telemetry (calls post_update_to_api "failed" with the exit code when POST_TO_API_DONE is true and POST_UPDATE_DONE is not), then destroy the failed container. These changes ensure correct telemetry type propagation and that failed turnkey deployments are reported. --- misc/api.func | 6 +++--- turnkey/turnkey.sh | 14 +++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/misc/api.func b/misc/api.func index e29975e2c..f65702679 100644 --- a/misc/api.func +++ b/misc/api.func @@ -627,8 +627,8 @@ post_to_api() { [[ "${DEV_MODE:-}" == "true" ]] && echo "[DEBUG] post_to_api() DIAGNOSTICS=$DIAGNOSTICS RANDOM_UUID=$RANDOM_UUID NSAPP=$NSAPP" >&2 - # Set type for later status updates - TELEMETRY_TYPE="lxc" + # Set type for later status updates (respect pre-set value, e.g. "turnkey") + TELEMETRY_TYPE="${TELEMETRY_TYPE:-lxc}" local pve_version="" if command -v pveversion &>/dev/null; then @@ -664,7 +664,7 @@ post_to_api() { { "random_id": "${RANDOM_UUID}", "execution_id": "${EXECUTION_ID:-${RANDOM_UUID}}", - "type": "lxc", + "type": "${TELEMETRY_TYPE}", "nsapp": "${NSAPP:-unknown}", "status": "installing", "ct_type": ${CT_TYPE:-1}, diff --git a/turnkey/turnkey.sh b/turnkey/turnkey.sh index 80f8f9049..5129be756 100644 --- a/turnkey/turnkey.sh +++ b/turnkey/turnkey.sh @@ -132,11 +132,18 @@ select_storage() { # MAIN # ============================================================================== -# Cleanup on error: destroy container and restart monitor +# Cleanup on error: destroy container, report telemetry, and restart monitor turnkey_cleanup() { local exit_code=$? - if [[ $exit_code -ne 0 ]] && [[ -n "${CTID:-}" ]]; then - cleanup_ctid 2>/dev/null || true + if [[ $exit_code -ne 0 ]]; then + # Report failure to telemetry + if [[ "${POST_TO_API_DONE:-}" == "true" && "${POST_UPDATE_DONE:-}" != "true" ]]; then + post_update_to_api "failed" "$exit_code" 2>/dev/null || true + fi + # Destroy failed container + if [[ -n "${CTID:-}" ]]; then + cleanup_ctid 2>/dev/null || true + fi fi if [[ -f /etc/systemd/system/ping-instances.service ]]; then systemctl start ping-instances.service 2>/dev/null || true @@ -285,6 +292,7 @@ fi [[ " ${PCT_OPTIONS[*]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs "${CONTAINER_STORAGE}:${PCT_DISK_SIZE:-8}") # Set telemetry variables for the selected turnkey +TELEMETRY_TYPE="turnkey" NSAPP="turnkey-${turnkey}" CT_TYPE=1 DISK_SIZE="${PCT_DISK_SIZE:-8}"