Skip to content

Commit 740406a

Browse files
committed
healthcheck
1 parent 3b10e76 commit 740406a

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

services/director/docker/healthcheck.py

100644100755
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
--timeout=30s \
99
--start-period=1s \
1010
--retries=3 \
11-
CMD python3 docker/healthcheck.py http://localhost:8080/v0/
11+
CMD python3 docker/healthcheck.py http://localhost:8000/
1212
```
1313
1414
Q&A:
@@ -18,23 +18,24 @@
1818

1919
import os
2020
import sys
21+
from contextlib import suppress
2122
from urllib.request import urlopen
2223

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", "")
2426

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", "")
2729

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-
)
3930

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

Comments
 (0)