|
8 | 8 | --timeout=30s \ |
9 | 9 | --start-period=1s \ |
10 | 10 | --retries=3 \ |
11 | | - CMD python3 docker/healthcheck.py http://localhost:8080/v0/ |
| 11 | + CMD python3 docker/healthcheck.py http://localhost:8000/ |
12 | 12 | ``` |
13 | 13 |
|
14 | 14 | Q&A: |
|
18 | 18 |
|
19 | 19 | import os |
20 | 20 | import sys |
| 21 | +from contextlib import suppress |
21 | 22 | from urllib.request import urlopen |
22 | 23 |
|
23 | | -SUCCESS, UNHEALTHY = 0, 1 |
| 24 | +# Disabled if boots with debugger (e.g. debug, pdb-debug, debug-ptvsd, etc) |
| 25 | +SC_BOOT_MODE = os.environ.get("SC_BOOT_MODE", "") |
24 | 26 |
|
25 | | -# Disabled if boots with debugger |
26 | | -ok = os.environ.get("SC_BOOT_MODE") == "debug" |
| 27 | +# Adds a base-path if defined in environ |
| 28 | +SIMCORE_NODE_BASEPATH = os.environ.get("SIMCORE_NODE_BASEPATH", "") |
27 | 29 |
|
28 | | -# Queries host |
29 | | -# pylint: disable=consider-using-with |
30 | | -ok = ( |
31 | | - ok |
32 | | - or urlopen( |
33 | | - "{host}{baseurl}".format( |
34 | | - host=sys.argv[1], baseurl=os.environ.get("SIMCORE_NODE_BASEPATH", "") |
35 | | - ) # adds a base-path if defined in environ |
36 | | - ).getcode() |
37 | | - == 200 |
38 | | -) |
39 | 30 |
|
40 | | -sys.exit(SUCCESS if ok else UNHEALTHY) |
| 31 | +def is_service_healthy() -> bool: |
| 32 | + if "debug" in SC_BOOT_MODE.lower(): |
| 33 | + return True |
| 34 | + |
| 35 | + with suppress(Exception): |
| 36 | + with urlopen(f"{sys.argv[1]}{SIMCORE_NODE_BASEPATH}") as f: |
| 37 | + return f.getcode() == 200 |
| 38 | + return False |
| 39 | + |
| 40 | + |
| 41 | +sys.exit(os.EX_OK if is_service_healthy() else os.EX_UNAVAILABLE) |
0 commit comments