Stop inactive servers or stop server upon logout z2jh

Hi,

I’m going to deploy jupyterhub with nbgrader for a course. Would it be possible to stop server upon logout? is it recommended? what are the consequences? how can I stop inactive servers after some time in z2jh?
are setting these options enough to achieve that?

cull:
    enabled: false
    users: true
    timeout: 259200
    every: 3600

what about these options:

c.MappingKernelManager.cull_connected = False
c.MappingKernelManager.cull_busy = False
c.MappingKernelManager.cull_idle_timeout = 259200
c.NotebookApp.shutdown_no_activity_timeout = 259200

Thanks
best

Update:
As far as I understood from the tutorial, cull idle is a service running on the hub and will kill inactive singleusers servers. But in order for that to work, according to Customizing User Management — Zero to JupyterHub with Kubernetes documentation one should mount jupyterhub_notebook_config.json in /etc/jupyter to send signal to the hub. Is it correct?

I followed the instruction in the mentioned page and added the below code

singleuser:
  extraFiles:
    # jupyter_notebook_config reference: https://jupyter-notebook.readthedocs.io/en/stable/config.html
    jupyter_notebook_config.json:
      mountPath: /etc/jupyter/jupyter_notebook_config.json
      # data is a YAML structure here but will be rendered to JSON file as our
      # file extension is ".json".
      data:
        MappingKernelManager:
          # cull_idle_timeout: timeout (in seconds) after which an idle kernel is
          # considered ready to be culled
          cull_idle_timeout: 1200 # default: 0

          # cull_interval: the interval (in seconds) on which to check for idle
          # kernels exceeding the cull timeout value
          cull_interval: 120 # default: 300

          # cull_connected: whether to consider culling kernels which have one
          # or more connections
          cull_connected: true # default: false

          # cull_busy: whether to consider culling kernels which are currently
          # busy running some code
          cull_busy: false # default: false

But it didn’t work with this error:

2024-01-15T13:29:19Z [Warning] Error: failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/var/lib/kubelet/pods/5cd8b5c0-3652-4716-b0cc-5bfb6e5a72df/volume-subpaths/files/notebook/1" to rootfs at "/etc/jupyter/jupyter_notebook_config.json": mount /var/lib/kubelet/pods/5cd8b5c0-3652-4716-b0cc-5bfb6e5a72df/volume-subpaths/files/notebook/1:/etc/jupyter/jupyter_notebook_config.json (via /proc/self/fd/6), flags: 0x5001: not a directory: unknown

What should be the contents of jupyterhub_notebook_config.json so that I can add it using a configMap?

best

does cull also kills hub-managed services?

There are two different ways of culling servers, one is driven by the hub, the other is done by the singleuser server itself. This is a good writeup:

No, if they were killed there’d be no way to restart them!

1 Like

Thanks. what about stopping server upon logout?

You can set c.JupyterHub.shutdown_on_logout

e.g. try something like

hub:
  config:
    JupyterHub:
      shutdown_on_logout: true
1 Like

@manics what if you just want to shut down the single user server when that user logs out, and not shut down the hub itself?

A user can have multiple servers running if the named servers functionality is activated. The hub remains running, but all the servers owned by the logging out user will be shut down.

1 Like

Thank you! If I can make a suggestion, I think the docs for shutdown_on_logout could be improved with your note. As is, it’s tough to interpret that’s the expected behavior.

1 Like

I absolutely agree, if you or someone would open a PR to improve it i think it could be swiftly accepted and merged!

2 Likes

@consideRatio more than happy to! If possible, please direct me to any contributor best practices and I’ll open a PR.