okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge commit 'ae31e3cd3' into f-split-int2aeb246cf

main
883 B18 linesraw
1#!/bin/sh
2# Container health: GET /v1/models with the API key. Healthy only when the server answers and has a model loaded.
3# While the model downloads or loads (can take hours the first time) the container is "starting", not "unhealthy".
4KEY_FILE="${STRATA_KEY_FILE:-/data/state/api-key}"
5KEY="${API_KEY:-}"
6[ -z "$KEY" ] && [ -r "$KEY_FILE" ] && KEY=$(cat "$KEY_FILE")
7exec /opt/strata/terminal/python/bin/python3 - "http://127.0.0.1:${PORT:-8080}/v1/models" "$KEY" <<'PY'
8import sys, urllib.request, json
9url, key = sys.argv[1], sys.argv[2]
10req = urllib.request.Request(url, headers={"Authorization": "Bearer " + key} if key else {})
11try:
12    with urllib.request.urlopen(req, timeout=4) as r:
13        data = json.load(r)
14        sys.exit(0 if r.status == 200 and data.get("data") else 1)
15except Exception as e:
16    print("not healthy: %s" % e, file=sys.stderr)
17    sys.exit(1)
18PY