mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-14 21:42:57 +00:00
Improve docker_healthcheck.py file
This commit is contained in:
@@ -70,7 +70,7 @@ RUN sed -re "s/c.ServerApp/c.NotebookApp/g" \
|
|||||||
# This healtcheck works well for `lab`, `notebook`, `nbclassic`, `server` and `retro` jupyter commands
|
# This healtcheck works well for `lab`, `notebook`, `nbclassic`, `server` and `retro` jupyter commands
|
||||||
# https://github.com/jupyter/docker-stacks/issues/915#issuecomment-1068528799
|
# https://github.com/jupyter/docker-stacks/issues/915#issuecomment-1068528799
|
||||||
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \
|
||||||
CMD python /etc/jupyter/docker_healthcheck.py || exit 1
|
CMD /etc/jupyter/docker_healthcheck.py || exit 1
|
||||||
|
|
||||||
# Switch back to jovyan to avoid accidental container runs as root
|
# Switch back to jovyan to avoid accidental container runs as root
|
||||||
USER ${NB_UID}
|
USER ${NB_UID}
|
||||||
|
11
base-notebook/docker_healthcheck.py
Normal file → Executable file
11
base-notebook/docker_healthcheck.py
Normal file → Executable file
@@ -1,16 +1,19 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# Copyright (c) Jupyter Development Team.
|
||||||
|
# Distributed under the terms of the Modified BSD License.
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
# A number of operations below delibrately don't check for possible errors
|
# A number of operations below delibrately don't check for possible errors
|
||||||
# As this is a healthcheck, it should succeed or raise an exception on error
|
# As this is a healthcheck, it should succeed or raise an exception on error
|
||||||
|
|
||||||
runtime_dir = "/home/" + os.environ["NB_USER"] + "/.local/share/jupyter/runtime/"
|
runtime_dir = Path("/home/") / os.environ["NB_USER"] / ".local/share/jupyter/runtime/"
|
||||||
file_list = os.listdir(runtime_dir)
|
json_file = next(runtime_dir.glob("*.json"))
|
||||||
json_file = [s for s in file_list if s.endswith(".json")]
|
|
||||||
|
|
||||||
url = json.load(open(runtime_dir + json_file[0]))["url"]
|
url = json.loads(json_file.read_bytes())["url"]
|
||||||
url = url + "api"
|
url = url + "api"
|
||||||
|
|
||||||
r = requests.get(url, verify=False) # request without SSL verification
|
r = requests.get(url, verify=False) # request without SSL verification
|
||||||
|
Reference in New Issue
Block a user