This commit is contained in:
David Schroeder
2026-07-28 22:09:13 -05:00
parent 247c4ddace
commit 3bea3baa88
12 changed files with 236 additions and 49 deletions
+37 -7
View File
@@ -60,6 +60,28 @@ TAPM_PULSE_VALID_NONNEGATIVE_INTEGER() {
[[ "${1:-}" =~ ^[0-9]+$ ]]
}
TAPM_PULSE_BACKOFF_NEXT() {
local current="${1:-1}"
local maximum="${2:-8}"
local next
[[ "$current" =~ ^[1-9][0-9]*$ &&
"$maximum" =~ ^[1-9][0-9]*$ ]] || return 1
next=$((current * 2))
(( next > maximum )) && next="$maximum"
printf '%s\n' "$next"
}
TAPM_PULSE_BACKOFF_SLEEP() {
local deadline="$1"
local delay="$2"
local remaining=$((deadline - SECONDS))
(( remaining > 0 )) || return 0
(( delay > remaining )) && delay="$remaining"
sleep "$delay"
}
TAPM_PULSE_VALID_PORT() {
[[ "${1:-}" =~ ^[0-9]+$ ]] && (( 10#$1 >= 1 && 10#$1 <= 65535 ))
}
@@ -498,7 +520,8 @@ TAPM_PULSE_CONFIGURE_SECURITY() {
local token_variable="$6"
local requested_password="${7:-}"
local bootstrap_output bootstrap_token generated_username generated_password generated_api_token
local request_file curl_config response security_ready='no' attempt
local request_file curl_config response security_ready='no'
local deadline delay
generated_username='admin'
if [[ -n "$requested_password" ]]; then
@@ -577,7 +600,9 @@ raise SystemExit(0 if success is True else 1)
{
printf 'header = "X-API-Token: %s"\n' "$generated_api_token"
} >"$curl_config" || return 1
for (( attempt = 1; attempt <= 15; attempt++ )); do
deadline=$((SECONDS + 30))
delay=1
while (( SECONDS < deadline )); do
if curl --fail --silent --show-error \
--connect-timeout 3 --max-time 5 \
--config "$curl_config" \
@@ -585,7 +610,8 @@ raise SystemExit(0 if success is True else 1)
security_ready='yes'
break
fi
sleep 2
TAPM_PULSE_BACKOFF_SLEEP "$deadline" "$delay"
delay="$(TAPM_PULSE_BACKOFF_NEXT "$delay" 4)"
done
if [[ "$security_ready" != 'yes' ]]; then
unset generated_password generated_api_token
@@ -796,7 +822,8 @@ TAPM_PULSE_WAIT_AGENT_REGISTERED() {
local node="$3"
local temp_dir="$4"
local curl_config="${temp_dir}/agent-${node}-verify.curl"
local encoded_node response attempt
local encoded_node response
local deadline delay
printf 'header = "X-API-Token: %s"\n' "$token" >"$curl_config" || return 1
chmod 0600 "$curl_config" || return 1
@@ -809,8 +836,10 @@ print(urllib.parse.quote(os.environ["TAPM_PULSE_NODE_NAME"], safe=""))
# Pulse v6.1.1 completes its Proxmox setup before sending the first host
# report. Its built-in registration retries can span at least 135 seconds,
# so allow up to four minutes before treating the active agent as unconfirmed.
for (( attempt = 1; attempt <= 80; attempt++ )); do
# so allow up to four minutes while backing off repeated local lookups.
deadline=$((SECONDS + 240))
delay=1
while (( SECONDS < deadline )); do
response="$(
curl --fail --silent --show-error \
--connect-timeout 3 --max-time 5 \
@@ -821,7 +850,8 @@ print(urllib.parse.quote(os.environ["TAPM_PULSE_NODE_NAME"], safe=""))
if TAPM_PULSE_AGENT_REGISTERED_FROM_RESPONSE "$response"; then
return 0
fi
sleep 3
TAPM_PULSE_BACKOFF_SLEEP "$deadline" "$delay"
delay="$(TAPM_PULSE_BACKOFF_NEXT "$delay" 8)"
done
return 1
}