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}"