We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[BUG] - Health Check fails if you change the port jupyter runs on
### What docker image(s) are you using?

minimal-notebook

### OS system and architecture running docker image

RHEL7  docker swarm

### What Docker command are you running?

Not really relevant, but I need to run it in a docker swarm, with a generalise 'ingress service'.

For this I needed to change internal port jupyter runs on needs to be changes for intergation into a 'ingress proxy'
To change the port I made a slight modification the docker image to set the internal port it runs on (see below)

The problem is the docker container  dies unexpectedly after running for 46 seconds.
During that time the service is visible within the conatiner, but not external to the container.
This is because the built-in heathcheck never succeeds, and eventually kills the container with little logged reporting.
(see below)


### How to Reproduce the problem?

Dockerfile, to set port

```dockerfile
FROM "jupyter/minimal-notebook:latest"
# Update Jupyter configuration to set port
RUN set -eux; \
    sed -i 's/port = 8888/port = 8080/' /etc/jupyter/jupyter_notebook_config.py ;\
    sed -i 's/port = 8888/port = 8080/' /etc/jupyter/jupyter_server_config.py ;\
    :;
```
You can also change the port in other ways such as... 

Creating a `~joyvan/.jupyter/jupyter_server_config.py` file (which can also set a password)

or setting a  JUPYTER_PORT environment variable (IF the setting in `/etc/jupyter` configs are removed)



### Command output

When you build and then run the modified docker image, `docker ps`  reports
`Up 9 seconds (health: starting)   8888/tcp`  despite the fact that jupyter is now running on port 8080

46 seconds after starting the container dies with a unhelpful (Signal 15)

Log output...
```
[I 2022-10-28 05:20:00.393 ServerApp] Jupyter Server 1.21.0 is running at:
[I 2022-10-28 05:20:00.393 ServerApp] http://jupyter_service:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c
or http://127.0.0.1:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c
[I 2022-10-28 05:20:00.393 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2022-10-28 05:20:00.397 ServerApp] 

To access the server, open this file in a browser:
file:///home/jovyan/.local/share/jupyter/runtime/jpserver-8-open.html
Or copy and paste one of these URLs:
http://jupyter_service:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c
or http://127.0.0.1:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c
Entered start.sh with args: jupyter lab
Executing the command: jupyter lab
[C 2022-10-28 05:20:46.261 ServerApp] received signal 15, stopping
[I 2022-10-28 05:20:46.262 ServerApp] Shutting down 2 extensions
[I 2022-10-28 05:20:46.263 ServerApp] Shutting down 0 terminals
```

### Expected behavior

Changing the internal port should not take days of work to track down, it should be straight forward and documented.

The healthcheck should also be properly documented in jupyter-stacks documentation.
This will make it more 'swarm friendly' as well as allow others to integrate it better when port 8888 is NOT available.

Yes you can map the port when doing a 'docker run', but that is NOT always possible.

### Actual behavior

Internal Port changing is undocumented in stacks

Heathcheck kills the container without notice (signal 15 hardly makes it clear) when port is different.

Days of work lost trying to figure out what should be a straight forward and simple task.

### Anything else?

There is an existing environment variable  "JUPYTER_PORT" that defines the default port.
But any such setting is currently overridden by the  configuration files in `/etc/jupyter`

This may be usable to set healthcheck, especially if the config file default is removed, or allows the env var to override.

in Dockerfile....
```
HEALTHCHECK  --interval=15s --timeout=3s --start-period=5s --retries=3 \
    CMD wget -O- --no-verbose --tries=1 --no-check-certificate \
    http${GEN_CERT:+s}://localhost:${JUPYTER_PORT:-8888}${JUPYTERHUB_SERVICE_PREFIX:-/}api || exit 1
```

That Environment variable also needs to be documented in the jupyter-stacks documentation, with the health check.
[BUG] - Health Check fails if you change the port jupyter runs on
### What docker image(s) are you using?

minimal-notebook

### OS system and architecture running docker image

RHEL7  docker swarm

### What Docker command are you running?

Not really relevant, but I need to run it in a docker swarm, with a generalise 'ingress service'.

For this I needed to change internal port jupyter runs on needs to be changes for intergation into a 'ingress proxy'
To change the port I made a slight modification the docker image to set the internal port it runs on (see below)

The problem is the docker container  dies unexpectedly after running for 46 seconds.
During that time the service is visible within the conatiner, but not external to the container.
This is because the built-in heathcheck never succeeds, and eventually kills the container with little logged reporting.
(see below)


### How to Reproduce the problem?

Dockerfile, to set port

```dockerfile
FROM "jupyter/minimal-notebook:latest"
# Update Jupyter configuration to set port
RUN set -eux; \
    sed -i 's/port = 8888/port = 8080/' /etc/jupyter/jupyter_notebook_config.py ;\
    sed -i 's/port = 8888/port = 8080/' /etc/jupyter/jupyter_server_config.py ;\
    :;
```
You can also change the port in other ways such as... 

Creating a `~joyvan/.jupyter/jupyter_server_config.py` file (which can also set a password)

or setting a  JUPYTER_PORT environment variable (IF the setting in `/etc/jupyter` configs are removed)



### Command output

When you build and then run the modified docker image, `docker ps`  reports
`Up 9 seconds (health: starting)   8888/tcp`  despite the fact that jupyter is now running on port 8080

46 seconds after starting the container dies with a unhelpful (Signal 15)

Log output...
```
[I 2022-10-28 05:20:00.393 ServerApp] Jupyter Server 1.21.0 is running at:
[I 2022-10-28 05:20:00.393 ServerApp] http://jupyter_service:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c
or http://127.0.0.1:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c
[I 2022-10-28 05:20:00.393 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2022-10-28 05:20:00.397 ServerApp] 

To access the server, open this file in a browser:
file:///home/jovyan/.local/share/jupyter/runtime/jpserver-8-open.html
Or copy and paste one of these URLs:
http://jupyter_service:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c
or http://127.0.0.1:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c
Entered start.sh with args: jupyter lab
Executing the command: jupyter lab
[C 2022-10-28 05:20:46.261 ServerApp] received signal 15, stopping
[I 2022-10-28 05:20:46.262 ServerApp] Shutting down 2 extensions
[I 2022-10-28 05:20:46.263 ServerApp] Shutting down 0 terminals
```

### Expected behavior

Changing the internal port should not take days of work to track down, it should be straight forward and documented.

The healthcheck should also be properly documented in jupyter-stacks documentation.
This will make it more 'swarm friendly' as well as allow others to integrate it better when port 8888 is NOT available.

Yes you can map the port when doing a 'docker run', but that is NOT always possible.

### Actual behavior

Internal Port changing is undocumented in stacks

Heathcheck kills the container without notice (signal 15 hardly makes it clear) when port is different.

Days of work lost trying to figure out what should be a straight forward and simple task.

### Anything else?

There is an existing environment variable  "JUPYTER_PORT" that defines the default port.
But any such setting is currently overridden by the  configuration files in `/etc/jupyter`

This may be usable to set healthcheck, especially if the config file default is removed, or allows the env var to override.

in Dockerfile....
```
HEALTHCHECK  --interval=15s --timeout=3s --start-period=5s --retries=3 \
    CMD wget -O- --no-verbose --tries=1 --no-check-certificate \
    http${GEN_CERT:+s}://localhost:${JUPYTER_PORT:-8888}${JUPYTERHUB_SERVICE_PREFIX:-/}api || exit 1
```

That Environment variable also needs to be documented in the jupyter-stacks documentation, with the health check.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `base-notebook/jupyter_server_config.py`
Content:
```
1 # Copyright (c) Jupyter Development Team.
2 # Distributed under the terms of the Modified BSD License.
3 # mypy: ignore-errors
4 import os
5 import stat
6 import subprocess
7 
8 from jupyter_core.paths import jupyter_data_dir
9 
10 c = get_config()  # noqa: F821
11 c.ServerApp.ip = "0.0.0.0"
12 c.ServerApp.port = 8888
13 c.ServerApp.open_browser = False
14 
15 # to output both image/svg+xml and application/pdf plot formats in the notebook file
16 c.InlineBackend.figure_formats = {"png", "jpeg", "svg", "pdf"}
17 
18 # https://github.com/jupyter/notebook/issues/3130
19 c.FileContentsManager.delete_to_trash = False
20 
21 # Generate a self-signed certificate
22 OPENSSL_CONFIG = """\
23 [req]
24 distinguished_name = req_distinguished_name
25 [req_distinguished_name]
26 """
27 if "GEN_CERT" in os.environ:
28     dir_name = jupyter_data_dir()
29     pem_file = os.path.join(dir_name, "notebook.pem")
30     os.makedirs(dir_name, exist_ok=True)
31 
32     # Generate an openssl.cnf file to set the distinguished name
33     cnf_file = os.path.join(os.getenv("CONDA_DIR", "/usr/lib"), "ssl", "openssl.cnf")
34     if not os.path.isfile(cnf_file):
35         with open(cnf_file, "w") as fh:
36             fh.write(OPENSSL_CONFIG)
37 
38     # Generate a certificate if one doesn't exist on disk
39     subprocess.check_call(
40         [
41             "openssl",
42             "req",
43             "-new",
44             "-newkey=rsa:2048",
45             "-days=365",
46             "-nodes",
47             "-x509",
48             "-subj=/C=XX/ST=XX/L=XX/O=generated/CN=generated",
49             f"-keyout={pem_file}",
50             f"-out={pem_file}",
51         ]
52     )
53     # Restrict access to the file
54     os.chmod(pem_file, stat.S_IRUSR | stat.S_IWUSR)
55     c.ServerApp.certfile = pem_file
56 
57 # Change default umask for all subprocesses of the notebook server if set in
58 # the environment
59 if "NB_UMASK" in os.environ:
60     os.umask(int(os.environ["NB_UMASK"], 8))
61
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/base-notebook/jupyter_server_config.py b/base-notebook/jupyter_server_config.py
--- a/base-notebook/jupyter_server_config.py
+++ b/base-notebook/jupyter_server_config.py
@@ -9,7 +9,6 @@
 
 c = get_config()  # noqa: F821
 c.ServerApp.ip = "0.0.0.0"
-c.ServerApp.port = 8888
 c.ServerApp.open_browser = False
 
 # to output both image/svg+xml and application/pdf plot formats in the notebook file

{"golden_diff": "diff --git a/base-notebook/jupyter_server_config.py b/base-notebook/jupyter_server_config.py\n--- a/base-notebook/jupyter_server_config.py\n+++ b/base-notebook/jupyter_server_config.py\n@@ -9,7 +9,6 @@\n \n c = get_config()  # noqa: F821\n c.ServerApp.ip = \"0.0.0.0\"\n-c.ServerApp.port = 8888\n c.ServerApp.open_browser = False\n \n # to output both image/svg+xml and application/pdf plot formats in the notebook file\n", "issue": "[BUG] - Health Check fails if you change the port jupyter runs on\n### What docker image(s) are you using?\r\n\r\nminimal-notebook\r\n\r\n### OS system and architecture running docker image\r\n\r\nRHEL7  docker swarm\r\n\r\n### What Docker command are you running?\r\n\r\nNot really relevant, but I need to run it in a docker swarm, with a generalise 'ingress service'.\r\n\r\nFor this I needed to change internal port jupyter runs on needs to be changes for intergation into a 'ingress proxy'\r\nTo change the port I made a slight modification the docker image to set the internal port it runs on (see below)\r\n\r\nThe problem is the docker container  dies unexpectedly after running for 46 seconds.\r\nDuring that time the service is visible within the conatiner, but not external to the container.\r\nThis is because the built-in heathcheck never succeeds, and eventually kills the container with little logged reporting.\r\n(see below)\r\n\r\n\r\n### How to Reproduce the problem?\r\n\r\nDockerfile, to set port\r\n\r\n```dockerfile\r\nFROM \"jupyter/minimal-notebook:latest\"\r\n# Update Jupyter configuration to set port\r\nRUN set -eux; \\\r\n    sed -i 's/port = 8888/port = 8080/' /etc/jupyter/jupyter_notebook_config.py ;\\\r\n    sed -i 's/port = 8888/port = 8080/' /etc/jupyter/jupyter_server_config.py ;\\\r\n    :;\r\n```\r\nYou can also change the port in other ways such as... \r\n\r\nCreating a `~joyvan/.jupyter/jupyter_server_config.py` file (which can also set a password)\r\n\r\nor setting a  JUPYTER_PORT environment variable (IF the setting in `/etc/jupyter` configs are removed)\r\n\r\n\r\n\r\n### Command output\r\n\r\nWhen you build and then run the modified docker image, `docker ps`  reports\r\n`Up 9 seconds (health: starting)   8888/tcp`  despite the fact that jupyter is now running on port 8080\r\n\r\n46 seconds after starting the container dies with a unhelpful (Signal 15)\r\n\r\nLog output...\r\n```\r\n[I 2022-10-28 05:20:00.393 ServerApp] Jupyter Server 1.21.0 is running at:\r\n[I 2022-10-28 05:20:00.393 ServerApp] http://jupyter_service:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c\r\nor http://127.0.0.1:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c\r\n[I 2022-10-28 05:20:00.393 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).\r\n[C 2022-10-28 05:20:00.397 ServerApp] \r\n\r\nTo access the server, open this file in a browser:\r\nfile:///home/jovyan/.local/share/jupyter/runtime/jpserver-8-open.html\r\nOr copy and paste one of these URLs:\r\nhttp://jupyter_service:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c\r\nor http://127.0.0.1:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c\r\nEntered start.sh with args: jupyter lab\r\nExecuting the command: jupyter lab\r\n[C 2022-10-28 05:20:46.261 ServerApp] received signal 15, stopping\r\n[I 2022-10-28 05:20:46.262 ServerApp] Shutting down 2 extensions\r\n[I 2022-10-28 05:20:46.263 ServerApp] Shutting down 0 terminals\r\n```\r\n\r\n### Expected behavior\r\n\r\nChanging the internal port should not take days of work to track down, it should be straight forward and documented.\r\n\r\nThe healthcheck should also be properly documented in jupyter-stacks documentation.\r\nThis will make it more 'swarm friendly' as well as allow others to integrate it better when port 8888 is NOT available.\r\n\r\nYes you can map the port when doing a 'docker run', but that is NOT always possible.\r\n\r\n### Actual behavior\r\n\r\nInternal Port changing is undocumented in stacks\r\n\r\nHeathcheck kills the container without notice (signal 15 hardly makes it clear) when port is different.\r\n\r\nDays of work lost trying to figure out what should be a straight forward and simple task.\r\n\r\n### Anything else?\r\n\r\nThere is an existing environment variable  \"JUPYTER_PORT\" that defines the default port.\r\nBut any such setting is currently overridden by the  configuration files in `/etc/jupyter`\r\n\r\nThis may be usable to set healthcheck, especially if the config file default is removed, or allows the env var to override.\r\n\r\nin Dockerfile....\r\n```\r\nHEALTHCHECK  --interval=15s --timeout=3s --start-period=5s --retries=3 \\\r\n    CMD wget -O- --no-verbose --tries=1 --no-check-certificate \\\r\n    http${GEN_CERT:+s}://localhost:${JUPYTER_PORT:-8888}${JUPYTERHUB_SERVICE_PREFIX:-/}api || exit 1\r\n```\r\n\r\nThat Environment variable also needs to be documented in the jupyter-stacks documentation, with the health check.\n[BUG] - Health Check fails if you change the port jupyter runs on\n### What docker image(s) are you using?\r\n\r\nminimal-notebook\r\n\r\n### OS system and architecture running docker image\r\n\r\nRHEL7  docker swarm\r\n\r\n### What Docker command are you running?\r\n\r\nNot really relevant, but I need to run it in a docker swarm, with a generalise 'ingress service'.\r\n\r\nFor this I needed to change internal port jupyter runs on needs to be changes for intergation into a 'ingress proxy'\r\nTo change the port I made a slight modification the docker image to set the internal port it runs on (see below)\r\n\r\nThe problem is the docker container  dies unexpectedly after running for 46 seconds.\r\nDuring that time the service is visible within the conatiner, but not external to the container.\r\nThis is because the built-in heathcheck never succeeds, and eventually kills the container with little logged reporting.\r\n(see below)\r\n\r\n\r\n### How to Reproduce the problem?\r\n\r\nDockerfile, to set port\r\n\r\n```dockerfile\r\nFROM \"jupyter/minimal-notebook:latest\"\r\n# Update Jupyter configuration to set port\r\nRUN set -eux; \\\r\n    sed -i 's/port = 8888/port = 8080/' /etc/jupyter/jupyter_notebook_config.py ;\\\r\n    sed -i 's/port = 8888/port = 8080/' /etc/jupyter/jupyter_server_config.py ;\\\r\n    :;\r\n```\r\nYou can also change the port in other ways such as... \r\n\r\nCreating a `~joyvan/.jupyter/jupyter_server_config.py` file (which can also set a password)\r\n\r\nor setting a  JUPYTER_PORT environment variable (IF the setting in `/etc/jupyter` configs are removed)\r\n\r\n\r\n\r\n### Command output\r\n\r\nWhen you build and then run the modified docker image, `docker ps`  reports\r\n`Up 9 seconds (health: starting)   8888/tcp`  despite the fact that jupyter is now running on port 8080\r\n\r\n46 seconds after starting the container dies with a unhelpful (Signal 15)\r\n\r\nLog output...\r\n```\r\n[I 2022-10-28 05:20:00.393 ServerApp] Jupyter Server 1.21.0 is running at:\r\n[I 2022-10-28 05:20:00.393 ServerApp] http://jupyter_service:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c\r\nor http://127.0.0.1:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c\r\n[I 2022-10-28 05:20:00.393 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).\r\n[C 2022-10-28 05:20:00.397 ServerApp] \r\n\r\nTo access the server, open this file in a browser:\r\nfile:///home/jovyan/.local/share/jupyter/runtime/jpserver-8-open.html\r\nOr copy and paste one of these URLs:\r\nhttp://jupyter_service:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c\r\nor http://127.0.0.1:8080/lab?token=929eaaf2e60f8a947761cb1f2741d745fd46dde62f6fef7c\r\nEntered start.sh with args: jupyter lab\r\nExecuting the command: jupyter lab\r\n[C 2022-10-28 05:20:46.261 ServerApp] received signal 15, stopping\r\n[I 2022-10-28 05:20:46.262 ServerApp] Shutting down 2 extensions\r\n[I 2022-10-28 05:20:46.263 ServerApp] Shutting down 0 terminals\r\n```\r\n\r\n### Expected behavior\r\n\r\nChanging the internal port should not take days of work to track down, it should be straight forward and documented.\r\n\r\nThe healthcheck should also be properly documented in jupyter-stacks documentation.\r\nThis will make it more 'swarm friendly' as well as allow others to integrate it better when port 8888 is NOT available.\r\n\r\nYes you can map the port when doing a 'docker run', but that is NOT always possible.\r\n\r\n### Actual behavior\r\n\r\nInternal Port changing is undocumented in stacks\r\n\r\nHeathcheck kills the container without notice (signal 15 hardly makes it clear) when port is different.\r\n\r\nDays of work lost trying to figure out what should be a straight forward and simple task.\r\n\r\n### Anything else?\r\n\r\nThere is an existing environment variable  \"JUPYTER_PORT\" that defines the default port.\r\nBut any such setting is currently overridden by the  configuration files in `/etc/jupyter`\r\n\r\nThis may be usable to set healthcheck, especially if the config file default is removed, or allows the env var to override.\r\n\r\nin Dockerfile....\r\n```\r\nHEALTHCHECK  --interval=15s --timeout=3s --start-period=5s --retries=3 \\\r\n    CMD wget -O- --no-verbose --tries=1 --no-check-certificate \\\r\n    http${GEN_CERT:+s}://localhost:${JUPYTER_PORT:-8888}${JUPYTERHUB_SERVICE_PREFIX:-/}api || exit 1\r\n```\r\n\r\nThat Environment variable also needs to be documented in the jupyter-stacks documentation, with the health check.\n", "before_files": [{"content": "# Copyright (c) Jupyter Development Team.\n# Distributed under the terms of the Modified BSD License.\n# mypy: ignore-errors\nimport os\nimport stat\nimport subprocess\n\nfrom jupyter_core.paths import jupyter_data_dir\n\nc = get_config()  # noqa: F821\nc.ServerApp.ip = \"0.0.0.0\"\nc.ServerApp.port = 8888\nc.ServerApp.open_browser = False\n\n# to output both image/svg+xml and application/pdf plot formats in the notebook file\nc.InlineBackend.figure_formats = {\"png\", \"jpeg\", \"svg\", \"pdf\"}\n\n# https://github.com/jupyter/notebook/issues/3130\nc.FileContentsManager.delete_to_trash = False\n\n# Generate a self-signed certificate\nOPENSSL_CONFIG = \"\"\"\\\n[req]\ndistinguished_name = req_distinguished_name\n[req_distinguished_name]\n\"\"\"\nif \"GEN_CERT\" in os.environ:\n    dir_name = jupyter_data_dir()\n    pem_file = os.path.join(dir_name, \"notebook.pem\")\n    os.makedirs(dir_name, exist_ok=True)\n\n    # Generate an openssl.cnf file to set the distinguished name\n    cnf_file = os.path.join(os.getenv(\"CONDA_DIR\", \"/usr/lib\"), \"ssl\", \"openssl.cnf\")\n    if not os.path.isfile(cnf_file):\n        with open(cnf_file, \"w\") as fh:\n            fh.write(OPENSSL_CONFIG)\n\n    # Generate a certificate if one doesn't exist on disk\n    subprocess.check_call(\n        [\n            \"openssl\",\n            \"req\",\n            \"-new\",\n            \"-newkey=rsa:2048\",\n            \"-days=365\",\n            \"-nodes\",\n            \"-x509\",\n            \"-subj=/C=XX/ST=XX/L=XX/O=generated/CN=generated\",\n            f\"-keyout={pem_file}\",\n            f\"-out={pem_file}\",\n        ]\n    )\n    # Restrict access to the file\n    os.chmod(pem_file, stat.S_IRUSR | stat.S_IWUSR)\n    c.ServerApp.certfile = pem_file\n\n# Change default umask for all subprocesses of the notebook server if set in\n# the environment\nif \"NB_UMASK\" in os.environ:\n    os.umask(int(os.environ[\"NB_UMASK\"], 8))\n", "path": "base-notebook/jupyter_server_config.py"}], "after_files": [{"content": "# Copyright (c) Jupyter Development Team.\n# Distributed under the terms of the Modified BSD License.\n# mypy: ignore-errors\nimport os\nimport stat\nimport subprocess\n\nfrom jupyter_core.paths import jupyter_data_dir\n\nc = get_config()  # noqa: F821\nc.ServerApp.ip = \"0.0.0.0\"\nc.ServerApp.open_browser = False\n\n# to output both image/svg+xml and application/pdf plot formats in the notebook file\nc.InlineBackend.figure_formats = {\"png\", \"jpeg\", \"svg\", \"pdf\"}\n\n# https://github.com/jupyter/notebook/issues/3130\nc.FileContentsManager.delete_to_trash = False\n\n# Generate a self-signed certificate\nOPENSSL_CONFIG = \"\"\"\\\n[req]\ndistinguished_name = req_distinguished_name\n[req_distinguished_name]\n\"\"\"\nif \"GEN_CERT\" in os.environ:\n    dir_name = jupyter_data_dir()\n    pem_file = os.path.join(dir_name, \"notebook.pem\")\n    os.makedirs(dir_name, exist_ok=True)\n\n    # Generate an openssl.cnf file to set the distinguished name\n    cnf_file = os.path.join(os.getenv(\"CONDA_DIR\", \"/usr/lib\"), \"ssl\", \"openssl.cnf\")\n    if not os.path.isfile(cnf_file):\n        with open(cnf_file, \"w\") as fh:\n            fh.write(OPENSSL_CONFIG)\n\n    # Generate a certificate if one doesn't exist on disk\n    subprocess.check_call(\n        [\n            \"openssl\",\n            \"req\",\n            \"-new\",\n            \"-newkey=rsa:2048\",\n            \"-days=365\",\n            \"-nodes\",\n            \"-x509\",\n            \"-subj=/C=XX/ST=XX/L=XX/O=generated/CN=generated\",\n            f\"-keyout={pem_file}\",\n            f\"-out={pem_file}\",\n        ]\n    )\n    # Restrict access to the file\n    os.chmod(pem_file, stat.S_IRUSR | stat.S_IWUSR)\n    c.ServerApp.certfile = pem_file\n\n# Change default umask for all subprocesses of the notebook server if set in\n# the environment\nif \"NB_UMASK\" in os.environ:\n    os.umask(int(os.environ[\"NB_UMASK\"], 8))\n", "path": "base-notebook/jupyter_server_config.py"}]}