set -euo pipefail
label="$1"; envfile="$2"; service="$3"; port="$4"
echo "## $label"
echo "envfile=$envfile exists=$([ -f "$envfile" ] && echo yes || echo no)"
if [ -f "$envfile" ]; then
  awk -F= '/(^|_)ALIPAY/{k=$1; v=$0; sub(/^[^=]*=/,"",v); if (k ~ /(KEY|SECRET|PRIVATE|PUBLIC|APP_ID|SELLER_ID|TOKEN|JWT)/) print k"=<set len="length(v)">"; else print k"="v}' "$envfile" || true
fi
if command -v systemctl >/dev/null 2>&1; then
  if [ "$service" = "user:sub2api.service" ]; then systemctl --user is-active sub2api.service || true; else systemctl is-active "$service" || true; fi
fi
curl -sS -m 5 -o /tmp/alipay_probe_health.out -w "health=%{http_code}\n" "http://127.0.0.1:${port}/health" || true
