Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add optional-components/jupyterhub-stop-idle #389

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 10 additions & 0 deletions birdhouse/config/jupyterhub/default.env
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export JUPYTER_LOGIN_BANNER_BOTTOM_SECTION=""
# server for the change to take effect.
export JUPYTERHUB_README=""

# Additional configuration to be provided by services or components managed by the stack.
# Any component extending this configuration using this variable *MUST* include it back to allow further
# components to extend it as well. Also, they *MUST* extend the variable with each new definitions applied on
# a new line (without indents) to ensure that Python configurations will be executable without syntax error.
# This variable differs from 'JUPYTERHUB_CONFIG_OVERRIDE' that does not require users to include it back to make
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "include it back"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing something in the form:

export JUPYTERHUB_CONFIG_EXTENDED="
${JUPYTERHUB_CONFIG_EXTENDED}
<extra python here>
"

# its definition extensible by other components. However, 'JUPYTERHUB_CONFIG_OVERRIDE' will still be applied
# after 'JUPYTERHUB_CONFIG_EXTENDED' to ensure it can override anything as needed after all components were resolved.
export JUPYTERHUB_CONFIG_EXTENDED=""

# Allow for adding new config or override existing config in
# config/jupyterhub/jupyterhub_config.py.template.
export JUPYTERHUB_CONFIG_OVERRIDE=""
Expand All @@ -65,6 +74,7 @@ OPTIONAL_VARS="
\$JUPYTER_LOGIN_BANNER_TOP_SECTION
\$JUPYTER_LOGIN_BANNER_BOTTOM_SECTION
\$JUPYTER_LOGIN_TERMS_URL
\$JUPYTERHUB_CONFIG_EXTENDED
\$JUPYTERHUB_CONFIG_OVERRIDE
\$JUPYTERHUB_DOCKER
\$JUPYTERHUB_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,5 @@ blocked_users = {'authtest', '${CATALOG_USERNAME}', 'anonymous'}
c.Authenticator.blacklist = blocked_users # v0.9+
c.Authenticator.blocked_users = blocked_users # v1.2+

${JUPYTERHUB_CONFIG_EXTENDED} # noqa
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not re-use the existing JUPYTERHUB_CONFIG_OVERRIDE?

If you want to keep both, please leave 2 lines between the 2 variables so that when both are actually in use, they do not look mixed up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing that, but given that some instances already use export JUPYTERHUB_CONFIG_OVERRIDE=... in their env.local, which is sourced when runninig pavics-compose.sh, any overrides applied along the way get ignored.

Because of how JUPYTERHUB_CONFIG_EXTENDED gets defined using extra newlines, they are already separated by multiple extra lines. I could add more though, or even add comments in the template to separate them explicitly.

${JUPYTERHUB_CONFIG_OVERRIDE} # noqa
74 changes: 74 additions & 0 deletions birdhouse/optional-components/jupyterhub-stop-idle/default.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/sh

# All env in this default.env can be overridden by env.local.

# All env in this default.env must NOT depend on any other env. If they do, they
# must use single quotes to avoid early expansion before overrides in env.local
# are applied and must be added to the list of DELAYED_EVAL.

# idle timeout of a user jupyterhub server to be shut down automatically (default: 1 day)
export JUPYTERHUB_STOP_IDLE_TIMEOUT=${JUPYTERHUB_STOP_IDLE_TIMEOUT:-86400}

# maximum age before stoping user servers (includiung active/running ones, regardless of last activity status)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this maximum age in seconds? Pleas specify the unit of time.

# if not specified, this will not be defined by the utility
# (i.e.: users that provide activity status before timeout could run their server indefinitely)
export JUPYTERHUB_STOP_IDLE_MAX_AGE=

# for details about the configuration, see https://github.com/jupyterhub/jupyterhub-idle-culler
# WARNING: be careful about indents here, Python code execution depends on it
export JUPYTERHUB_STOP_IDLE_CONFIG="
import sys

jupyterhub_stop_idle_timeout = ${JUPYTERHUB_STOP_IDLE_TIMEOUT}
c.JupyterHub.load_roles = [
{
'name': 'jupyterhub-idle-culler-role',
'scopes': [
'list:users',
'read:users:activity',
'read:servers',
'delete:servers',
],
'services': ['jupyterhub-idle-culler-service'],
}
]
jupyterhub_stop_idle_max_age = ${JUPYTERHUB_STOP_IDLE_MAX_AGE:-None}
jupyterhub_idle_culler_xargs = []
if jupyterhub_stop_idle_max_age:
jupyterhub_idle_culler_xargs = ['--max-age', jupyterhub_stop_idle_max_age]
c.JupyterHub.services = [
{
'name': 'jupyterhub-idle-culler-service',
'command': [
sys.executable,
'-m', 'jupyterhub_idle_culler',
'--timeout', jupyterhub_stop_idle_timeout,
] + jupyterhub_idle_culler_xargs,
}
]
# we need to ensure that the activity update interval is lower than the stop-idle timeout
# otherwise, the updated information will not be available for the utility to do its job
# however, jupyter has by default 5min intervals, which is usually much lower than 'JUPYTERHUB_STOP_IDLE_TIMEOUT'
c.JupyterHub.last_activity_interval = int(min(jupyterhub_stop_idle_timeout / 2, 300))
"

export JUPYTERHUB_CONFIG_EXTENDED="
${JUPYTERHUB_CONFIG_EXTENDED}
${JUPYTERHUB_STOP_IDLE_CONFIG}
"

#export DELAYED_EVAL="
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code please

# $DELAYED_EVAL
# JUPYTERHUB_CONFIG_EXTENDED
#"

OPTIONAL_VARS="
$OPTIONAL_VARS
\$JUPYTERHUB_STOP_IDLE_TIMEOUT
\$JUPYTERHUB_STOP_IDLE_MAX_AGE
"

# add any component that this component requires to run
COMPONENT_DEPENDENCIES="
./config/jupyterhub
"
Loading