Files
vps/ansible/roles/healthcheck/templates/healthcheck-runner.sh.j2
T

25 lines
1.1 KiB
Django/Jinja
Raw Normal View History

2026-08-03 12:26:42 +08:00
#!/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 %}
# Collect profile check names line-by-line (robust against Jinja trim_blocks
# whitespace control, which would otherwise merge this into one line).
aggregate_args=""
{% for profile in healthcheck_profiles %}
aggregate_args="$aggregate_args {{ healthcheck_profile_scripts[profile] | replace('.sh', '') }}"
{% endfor %}
aggregate_result $aggregate_args
exit "$rc"