Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions jupyterhub-docker/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

# Allow access to the host's network
c.DockerSpawner.extra_host_config = {
'extra_hosts': {'host.docker.internal': 'host-gateway'}
"extra_hosts": {"host.docker.internal": "host-gateway"}
}

# Explicitly set notebook directory because we'll be mounting a volume to it.
Expand All @@ -39,7 +39,9 @@
c.DockerSpawner.notebook_dir = notebook_dir
default_notebook = os.environ.get("DEFAULT_NOTEBOOK")
if default_notebook:
c.DockerSpawner.default_url = default_notebook
c.DockerSpawner.default_url = default_notebook + "?reset" # added reset to always open with zero files open
else:
c.DockerSpawner.default_url = "lab?reset" # added reset to always open with zero files open

# Mount the real user's Docker volume on the host to the notebook user's
# notebook directory in the container
Expand Down Expand Up @@ -72,3 +74,9 @@
admin = os.environ.get("JUPYTERHUB_ADMIN")
if admin:
c.Authenticator.admin_users = [admin]

# Limit resources per-user
c.Spawner.mem_limit = "400M"
c.Spawner.cpu_limit = 0.5
c.Spawner.stop_timeout = 30
c.Spawner.idle_timeout = 60
6 changes: 5 additions & 1 deletion jupyterhub-docker/user-notebook/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# This image is based on the Jupyter Scipy Notebook image and includes additional packages and configurations for DS Tutor.

FROM quay.io/jupyter/scipy-notebook:latest
FROM quay.io/jupyter/minimal-notebook:latest

# Create logs folder
RUN mkdir /home/jovyan/logs && \
Expand All @@ -13,6 +13,10 @@ RUN mkdir /home/jovyan/logs/processed && \
# Copy jupyterlab_pioneer config
COPY jupyter_jupyterlab_pioneer_config.py /etc/jupyter/

# Copy jupyter_notebook_config.py
COPY jupyter_notebook_config.py /etc/jupyter/


# Install additional packages
RUN pip install --no-cache-dir jupyterlab-chat jupyterlab_pioneer

Expand Down
30 changes: 30 additions & 0 deletions jupyterhub-docker/user-notebook/jupyter_notebook_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Shutdown the Jupyter server after no activity for 60 minutes
c.ServerApp.shutdown_no_activity_timeout = 3600

# Kill kernels after 30 minutes of inactivity
c.MappingKernelManager.cull_idle_timeout = 1800
c.MappingKernelManager.cull_interval = 1800
c.MappingKernelManager.cull_connected = False

# Disable terminal
c.ServerApp.terminals_enabled = False

# Max one kernel per user
from jupyter_server.services.kernels.kernelmanager import AsyncMappingKernelManager

class CustomKernelManager(AsyncMappingKernelManager):
async def start_kernel(self, kernel_id=None, path=None, **kwargs):
print("CustomKernelManager start_kernel")

# List existing kernels
kernels = self.list_kernels()

# Shut down existing kernels before starting a new one
for kernel in kernels:
await self.shutdown_kernel(kernel["id"])

# Start a new kernel (correct method call)
return await super().start_kernel(kernel_id=kernel_id, path=path, **kwargs)

# Apply the custom kernel manager
c.ServerApp.kernel_manager_class = CustomKernelManager