Files

19 lines
752 B
Bash
Executable File

#!/bin/sh
set -eu
URL=${HEALTHCHECK_URL:-http://127.0.0.1:8000/api/v1/health/ready}
TIMEOUT=${HEALTHCHECK_TIMEOUT:-5}
python3 - "$URL" "$TIMEOUT" <<'PY'
import json, sys, urllib.request
url, timeout = sys.argv[1], float(sys.argv[2])
try:
with urllib.request.urlopen(url, timeout=timeout) as response:
payload=json.loads(response.read())
if response.status != 200 or payload.get('status') != 'ok' or payload.get('ready') is not True:
raise RuntimeError('service is not ready')
if payload.get('outreach_enabled') is not False: raise RuntimeError('outreach safety check failed')
except Exception as exc:
print(f'healthcheck failed: {type(exc).__name__}', file=sys.stderr)
raise SystemExit(1)
print('ok')
PY