fix:备份恢复密钥

This commit is contained in:
waner
2026-05-09 18:09:16 +08:00
parent 9ccb5147ef
commit 79d38cc566
28 changed files with 1543 additions and 332 deletions
@@ -161,12 +161,37 @@ health_check() {
}
command -v curl >/dev/null 2>&1 || fail "curl command not found for health check" "HEALTH_CHECK"
local timeout="${HEALTH_CHECK_TIMEOUT_SECONDS:-5}"
local response
response="$(curl -fsS --max-time "${timeout}" "${url}")" || fail "health check request failed" "HEALTH_CHECK"
if [[ "${response}" != *"UP"* ]]; then
fail "health check did not return UP" "HEALTH_CHECK"
fi
log "health check passed"
local max_wait="${HEALTH_CHECK_MAX_WAIT_SECONDS:-180}"
local interval="${HEALTH_CHECK_RETRY_INTERVAL_SECONDS:-5}"
[[ "${max_wait}" =~ ^[0-9]+$ ]] || max_wait=180
[[ "${interval}" =~ ^[0-9]+$ ]] || interval=5
local start_time
start_time="$(date +%s)"
local attempt=1
local response=""
local curl_output
while true; do
curl_output="$(curl -fsS --max-time "${timeout}" "${url}" 2>&1)" && response="${curl_output}" || {
log "[WARN] health check attempt ${attempt} failed: ${curl_output}"
response=""
}
if [[ "${response}" == *"UP"* ]]; then
log "health check passed after ${attempt} attempt(s)"
return 0
fi
if [[ -n "${response}" ]]; then
log "[WARN] health check attempt ${attempt} did not return UP: ${response}"
fi
local now
now="$(date +%s)"
if (( now - start_time >= max_wait )); then
fail "health check request failed after ${max_wait}s" "HEALTH_CHECK"
fi
if (( interval > 0 )); then
sleep "${interval}"
fi
attempt=$((attempt + 1))
done
}
mkdir -p "${WORK_DIR}"