jupyterhub / jupyterhub/systemdspawner
jupyterhub passes invalid (old) config params to sudospawner-singleuser
- Dominant language
- Python
- Stars
- 100
- Forks
- 44
- PR merge metrics
- No merged PRs in 30d
Description
### Bug description
When jupyterhub spawns a new single user instance it passes not the current parameters from the given config file, but outdated/wrong values from a previous run.
### How to reproduce
0. Insert into [systemdspawner/systemd.py](https://github.com/jupyterhub/systemdspawner/blob/main/systemdspawner/systemd.py#L168) a "debug line" like this to see, what gets passed:
```python
sys.stderr.write(" ".join(run_cmd) + "\n")
```
3. start jupyterhub e.g. like this:
```ksh
#!/bin/ksh93
LOGFILE=~${LOGNAME}/jupyterhub.log
[[ ${LOGLEVEL} =~ ^(DEBUG|INFO|WARN|ERROR|CRITICAL)$ ]] || LOGLEVEL=WARN
export JUPYTER_PATH=/usr/local/jupyter
export PATH=${JUPYTER_PATH}/bin:${PATH}
CMD=( ${ python3 -V ; } )
CMD=( ${CMD[1]//./ } )
export PYTHONPATH=${JUPYTER_PATH}/lib/python${CMD}.${CMD[1]}/site-packages
export NPM_CONFIG_GLOBALCONFIG=/usr/local/jupyter/npmrc
export HOST=${ uname -n; }
exec "${JUPYTER_PATH}/bin/jupyterhub" ${SSL} \
-f "/etc/jhub_cfg.py" \
--log-level=${LOGLEVEL} \
>${LOGFILE} 2>&1 &
```
and _/etc/jhub_cfg.py_:
```python
import os
import re
c = get_config()
c.JupyterHub.base_url = '/'.join([ '/jupyter', os.environ['HOST'] ])
c.JupyterHub.spawner_class = 'systemdspawner.SystemdSpawner'
c.JupyterHub.shutdown_on_logout = True
c.Spawner.args = ['--ServerApp.allow_origin=*']
c.Spawner.notebook_dir = '~/'
c.Authenticator.admin_users = {'foobar','barfuss'}
c.Authenticator.admin_groups = {'nobrain'}
c.Authenticator.allow_all = True
c.Authenticator.allow_existing_users = True
c.ConfigurableHTTPProxy.debug = True
c.SystemdSpawner.default_shell = '/bin/bash'
c.SystemdSpawner.unit_name_template = 'jsu-{USERNAME}'
c.SystemdSpawner.slice = 'jhub-' + (os.environ['HOST']).replace('-',':')
c.SystemdSpawner.unit_extra_properties = { 'RuntimeDirectory': 'jhub/jsu-{USERNAME}' }
```
2. Try to connect to the service, login and wait (let it fail).
3. Stop the jupyterhub service.
4. Change the config e.g. by setting `SystemdSpawner.unit_name_template` to something else, e.g. `'jhub-{USERNAME}'`.
5. Start the jupyterhub service as in 1.
6. Try to connect/login to the service again.
7. Check the log
#### Expected behaviour
On the second try `systemd-run --unit jhub-*` should have been used to start the jupyterhub user instance.
#### Actual behaviour
It still uses `systemd-run --unit jsu-*` as in the first run (and Note, the jupyterhab got properly shutdown before starting it with the new config).
- OS: ubuntu 24.04
- Version(s):
```
Selected Jupyter core packages...
IPython : 9.5.0
ipykernel : 6.30.1
ipywidgets : 8.1.7
jupyter_client : 8.6.3
jupyter_core : 5.8.1
jupyter_server : 2.17.0
jupyterlab : 4.4.7
nbclient : 0.10.2
nbconvert : 7.16.6
nbformat : 5.10.4
notebook : 7.4.5
qtconsole : not installed
traitlets : 5.14.3
```
```
...
jsd-helper systemd-run --unit jsu-foobar --working-directory /home/foobar --uid=1234 --gid=5678 --slice=jhub-n02:00 --property=NoNewPrivileges=yes --property=RuntimeDirectory=jhub/jsu-foobar --property=RuntimeDirectoryMode=755 --property=RuntimeDirectoryPreserve=restart --property=OOMPolicy=continue --property=EnvironmentFile=/run/jhub/jsu-foobar/jsu-foobar.env /usr/local/jupyter/bin/jupyterhub-singleuser --ServerApp.allow_origin=*
[W 2025-09-25 20:45:23.492 JupyterHub metrics:456] Event loop was unresponsive for at least 29.99s!
[W 2025-09-25 20:45:23.494 JupyterHub base:1229] User foobar is slow to start (timeout=10)
...
```
Contributor guide
Research direction
Inspect systemdspawner/systemd.py around line 168, focusing on how the systemd-run command is assembled and whether values from an earlier run can persist. Reproduce the restart and configuration-change sequence in the issue, then verify that the second launch uses the updated unit name and other current parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter, python
- Domain
- backend, devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100