Skip to content

Commit

Permalink
healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Nov 4, 2024
1 parent 3b10e76 commit 740406a
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions services/director/docker/healthcheck.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
--timeout=30s \
--start-period=1s \
--retries=3 \
CMD python3 docker/healthcheck.py http://localhost:8080/v0/
CMD python3 docker/healthcheck.py http://localhost:8000/
```
Q&A:
Expand All @@ -18,23 +18,24 @@

import os
import sys
from contextlib import suppress
from urllib.request import urlopen

SUCCESS, UNHEALTHY = 0, 1
# Disabled if boots with debugger (e.g. debug, pdb-debug, debug-ptvsd, etc)
SC_BOOT_MODE = os.environ.get("SC_BOOT_MODE", "")

# Disabled if boots with debugger
ok = os.environ.get("SC_BOOT_MODE") == "debug"
# Adds a base-path if defined in environ
SIMCORE_NODE_BASEPATH = os.environ.get("SIMCORE_NODE_BASEPATH", "")

# Queries host
# pylint: disable=consider-using-with
ok = (
ok
or urlopen(
"{host}{baseurl}".format(
host=sys.argv[1], baseurl=os.environ.get("SIMCORE_NODE_BASEPATH", "")
) # adds a base-path if defined in environ
).getcode()
== 200
)

sys.exit(SUCCESS if ok else UNHEALTHY)
def is_service_healthy() -> bool:
if "debug" in SC_BOOT_MODE.lower():
return True

with suppress(Exception):
with urlopen(f"{sys.argv[1]}{SIMCORE_NODE_BASEPATH}") as f:
return f.getcode() == 200
return False


sys.exit(os.EX_OK if is_service_healthy() else os.EX_UNAVAILABLE)

0 comments on commit 740406a

Please sign in to comment.