Spaces:
Sleeping
Sleeping
Create healthcheck.py
Browse files- healthcheck.py +9 -0
healthcheck.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os, sys, urllib.request
|
2 |
+
port = int(os.environ.get("PORT", "7860"))
|
3 |
+
url = f"http://127.0.0.1:{port}/_stcore/health"
|
4 |
+
try:
|
5 |
+
with urllib.request.urlopen(url, timeout=3) as resp:
|
6 |
+
ok = resp.status == 200 and b"ok" in resp.read().lower()
|
7 |
+
sys.exit(0 if ok else 1)
|
8 |
+
except Exception:
|
9 |
+
sys.exit(1)
|