JupyterHub is not reloading users' ~/.jupyter/jupyter_notebook_config.py files unless I restart the whole hub

I have several users using PAMauthenticator on JupyterHub. So they are all users of the underlying Linux system. I have created ~/.jupyter/jupyter_notebook_config.py files for each user, in which I define some environment variables. So for example in the jupyter_notebook_config.py file I have:

import os
os.environ["test"] = "value"

And then inside spawned notebooks for that user, cells containing os.getenv("test") will return value.

However if I edit the jupyter_notebook_config.py file and add another variable, say os.environt["test1"] = "value1", this variable will not be visible unless I restart the whole Jupyter Hub . Spawning new notebooks, logging in and logging out of JupyterLab, restarting kernels, nothing seems to work - it seems strange that this config file is not being re-read each time a user logs in, or each time a notebook is spawned. Is there a way for the jupyter_noteboook_config.py to be re-read without restarting the whole hub?

Basically the objective is to allow users to add environment variables using the above method, to their own jupyter_notebook_config.py in their home directory from the terminal in JupyerLab. If there is another way of doing this that does not require restarting the whole hub, perhaps not using jupyter_notebook_config.py (keeping in mind that env variables must be unique for eqch user), then I’m happy to accept that as an answer too.

It pretty much depends on the spawner you use. Gor a better understanding, please share your
configuration (preferably a minimal example).

Well, there are additional ways how the environment variable can be set in the user environment (depending on the spawner). Have you considered using default server admin approaches (bash, …)? It night be nicer than having passwords hardcoded in the config, depends on your context of course.

tbh, I’m just using a completely standard Linux host where I’ve pip3 install JupyterHub and then generated a config using jupyterhub --generate-config, with very minimal changes to it. So I have no idea of the concept of how to change the spawner. I’m assuming it’s using the default one. All I really want is for different user environment variables to be translated through to the notebook, and when I add users, or when I change existing user credentials, I don’t want to have to restart the server. Which spawner should I be using to allow this, and where are the docs? Many thanks for your help.

You shouldn’t need to restart JupyterHub, it should be enough to stop a user’s singleuser server, and restart it.

And that is exactly what is NOT happening. Probably I will do an (umpteenth) virgin install and if it fails again, I will file a bug report. By “stop a user’s singleuser server” I’m assuming logging out, and back in again, for said user, achieves this? If not, what is the other way of doing it?

By default logging out won’t shutdown a user’s server in case they want to leave something running. Users can shutdown their server from the hub control panel (Hub Control Panel in the JupyterLab file menu).

You can override the behaviour if you want:

Yep this works. Sometimes the hub seems to hang a bit and go slowly if you terminate the user session but I can confirm this does reload the config. So done!

1 Like