mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-04-28 05:10:40 +00:00
Add post_progress_to_api lightweight telemetry ping
Introduce post_progress_to_api() in misc/api.func — a non-blocking, fire-and-forget curl ping (gated by DIAGNOSTICS and RANDOM_UUID) that updates telemetry status to "configuring". Wire this progress ping into multiple scripts (alpine-install.func, install.func, build.func, core.func) at key milestones (container start, network ready, customization, creation, cleanup) and replace/deduplicate some earlier post_to_api calls. Also update error_handler.func to always report failures immediately via post_update_to_api to ensure failures are captured even before/after container lifecycle.
This commit is contained in:
@@ -148,6 +148,7 @@ motd_ssh() {
|
|||||||
# Start the sshd service
|
# Start the sshd service
|
||||||
$STD /etc/init.d/sshd start
|
$STD /etc/init.d/sshd start
|
||||||
fi
|
fi
|
||||||
|
post_progress_to_api
|
||||||
}
|
}
|
||||||
|
|
||||||
# Validate Timezone for some LXC's
|
# 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
|
echo "bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/ct/${app}.sh)\"" >/usr/bin/update
|
||||||
chmod +x /usr/bin/update
|
chmod +x /usr/bin/update
|
||||||
|
post_progress_to_api
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -688,6 +688,29 @@ EOF
|
|||||||
POST_TO_API_DONE=true
|
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()
|
# post_update_to_api()
|
||||||
#
|
#
|
||||||
|
|||||||
+7
-6
@@ -3660,9 +3660,6 @@ $PCT_OPTIONS_STRING"
|
|||||||
exit 214
|
exit 214
|
||||||
fi
|
fi
|
||||||
msg_ok "Storage space validated"
|
msg_ok "Storage space validated"
|
||||||
|
|
||||||
# Report installation start to API (early - captures failed installs too)
|
|
||||||
post_to_api
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
create_lxc_container || exit $?
|
create_lxc_container || exit $?
|
||||||
@@ -3908,6 +3905,7 @@ EOF
|
|||||||
for i in {1..10}; do
|
for i in {1..10}; do
|
||||||
if pct status "$CTID" | grep -q "status: running"; then
|
if pct status "$CTID" | grep -q "status: running"; then
|
||||||
msg_ok "Started LXC Container"
|
msg_ok "Started LXC Container"
|
||||||
|
post_progress_to_api # Signal container is running
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
@@ -3962,6 +3960,7 @@ EOF
|
|||||||
echo -e "${YW}Container may have limited internet access. Installation will continue...${CL}"
|
echo -e "${YW}Container may have limited internet access. Installation will continue...${CL}"
|
||||||
else
|
else
|
||||||
msg_ok "Network in LXC is reachable (ping)"
|
msg_ok "Network in LXC is reachable (ping)"
|
||||||
|
post_progress_to_api # Signal network is ready
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# Function to get correct GID inside container
|
# Function to get correct GID inside container
|
||||||
@@ -4033,6 +4032,7 @@ EOF'
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
msg_ok "Customized LXC Container"
|
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)
|
# Optional DNS override for retry scenarios (inside LXC, never on host)
|
||||||
if [[ "${DNS_RETRY_OVERRIDE:-false}" == "true" ]]; then
|
if [[ "${DNS_RETRY_OVERRIDE:-false}" == "true" ]]; then
|
||||||
@@ -4888,6 +4888,9 @@ create_lxc_container() {
|
|||||||
exit 206
|
exit 206
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Report installation start to API early - captures failures in storage/template/create
|
||||||
|
post_to_api
|
||||||
|
|
||||||
# Storage capability check
|
# Storage capability check
|
||||||
check_storage_support "rootdir" || {
|
check_storage_support "rootdir" || {
|
||||||
msg_error "No valid storage found for 'rootdir' [Container]"
|
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."
|
msg_ok "LXC Container ${BL}$CTID${CL} ${GN}was successfully created."
|
||||||
|
post_progress_to_api # Signal container creation complete
|
||||||
# Report container creation to API
|
|
||||||
post_to_api
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|||||||
@@ -1496,6 +1496,11 @@ cleanup_lxc() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
msg_ok "Cleaned"
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -204,6 +204,12 @@ error_handler() {
|
|||||||
|
|
||||||
printf "\e[?25h"
|
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
|
# Use msg_error if available, fallback to echo
|
||||||
if declare -f msg_error >/dev/null 2>&1; then
|
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}"
|
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)
|
# 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
|
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 ""
|
echo ""
|
||||||
if declare -f msg_custom >/dev/null 2>&1; then
|
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}"
|
echo -en "${TAB}❓${TAB}${YW}Remove broken container ${CTID}? (Y/n) [auto-remove in 60s]: ${CL}"
|
||||||
|
|||||||
@@ -285,6 +285,7 @@ motd_ssh() {
|
|||||||
sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config
|
sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config
|
||||||
systemctl restart sshd
|
systemctl restart sshd
|
||||||
fi
|
fi
|
||||||
|
post_progress_to_api
|
||||||
}
|
}
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
@@ -323,4 +324,5 @@ EOF
|
|||||||
chmod 700 /root/.ssh
|
chmod 700 /root/.ssh
|
||||||
chmod 600 /root/.ssh/authorized_keys
|
chmod 600 /root/.ssh/authorized_keys
|
||||||
fi
|
fi
|
||||||
|
post_progress_to_api
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user