Files
vps/ansible/roles/healthcheck/templates/healthcheck-runner.sh.j2
T
windyboy d0d5e5a704 refactor(healthcheck): support multiple profiles per host with aggregate result
Replace the single healthcheck_profile with a healthcheck_profiles list so a
host can run several checks (e.g. hk2: pdns, rustdesk, hk2aux). Profiles emit
per-check JSON to latest-<check>.json; the dispatcher clears stale per-check
files, runs every profile, and merges them into latest.json.

Contract: a single complete check keeps the historical verbatim latest.json
shape; several checks produce a worst-status aggregate retaining every check's
detail. A profile that crashes before reporting is aggregated as unknown so
latest.json can never go stale while the dispatcher fails. The dispatcher exits
with the worst (max) profile exit code.
2026-08-12 21:16:30 +08:00

19 lines
958 B
Django/Jinja

#!/usr/bin/env bash
set -o pipefail
source '{{ healthcheck_install_root }}/health-common.sh'
# Run every enabled health-check profile, exit with the worst (max) code, and
# merge the per-check results into /var/lib/vps-health/latest.json.
rc=0
# Drop per-check results from any prior run so a profile that crashes before
# reporting cannot leak a stale healthy result into the aggregate.
{% for profile in healthcheck_profiles %}
rm -f '{{ healthcheck_state_dir }}/latest-{{ healthcheck_profile_scripts[profile] | replace('.sh', '') }}.json'
{% endfor %}
{% for profile in healthcheck_profiles %}
'{{ healthcheck_install_root }}/{{ healthcheck_profile_scripts[profile] }}' 2>&1 | tee -a '{{ healthcheck_log_dir }}/healthcheck.log'
this_rc="${PIPESTATUS[0]}"
[ "$this_rc" -gt "$rc" ] && rc="$this_rc"
{% endfor %}
aggregate_result{% for profile in healthcheck_profiles %} {{ healthcheck_profile_scripts[profile] | replace('.sh', '') }}{% endfor %}
exit "$rc"