jupyterhub / systemdspawner

Spawn JupyterHub single-user notebook servers with systemd
BSD 3-Clause "New" or "Revised" License
92 stars 45 forks source link

We need a new release desperately #93

Closed smac89 closed 2 years ago

smac89 commented 2 years ago

Proposed change

I've been scratching my head for almost a day now wondering why {USERNAME} and {USERID} are not expanded in extra properties. I kept looking at the code in this repo, and tracing all the steps and everything suggests that those variables should be expanded, yet when I run my jupyterhub, after the first user is created, any subsequent user receives 500 server error because the runtime directory created is not expanded, and the unit attempts to use the directory of another.

I see that the last release was in 2020, but the commit that allows expanding the variables was done in 2021.

Alternative options

Make a partial release which only includes this one commit

Who would use this feature?

Anyone who has read the readme recently ArcoLinux_2022-04-21_21-05-52

(Optional): Suggest a solution

welcome[bot] commented 2 years ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

smac89 commented 2 years ago

If it helps, this is how I use unit_extra_properties:

c.SystemdSpawner.unit_extra_properties = {
    "RuntimeDirectory": os.path.join(
        *(
            os.getenv("RUNTIME_DIRECTORY") # RUNTIME_DIRECTORY comes from parent's process when setting its' RuntimeDirectory
            .split(os.path.pathsep)[0]
            .split(os.path.sep)[2:]
        ),
        '{USERNAME}',
        # TODO: Would be nice to use {USERID} or {USERNAME} here...
    ),
    ...
}

Just as I posted this, I discovered a workaround, using pre_spawn_hook:

def load_course_material(spawner: "systemdspawner.SystemdSpawner") -> None:
    from subprocess import check_call

    # workaround until https://github.com/jupyterhub/systemdspawner/issues/93 is resolved
    for prop, value in spawner.unit_extra_properties.items():
        spawner.unit_extra_properties[prop] = spawner._expand_user_vars(value)

    # ...

c.Spawner.pre_spawn_hook = load_course_material

Now I can have all my users able to login and work at the same time!

yuvipanda commented 2 years ago

Thanks for the ping, @smac89! I've just released v0.16 with that PR included. Apologies for the delay, and sorry about the frustration it caused. I'm glad you were able to find a workaround though!