2018-06-15 16:54:40 -07:00
|
|
|
"""
|
|
|
|
|
JupyterHub config for the littlest jupyterhub.
|
|
|
|
|
"""
|
2018-07-31 12:02:47 +02:00
|
|
|
import copy
|
2018-06-15 16:17:07 -07:00
|
|
|
import os
|
2018-07-31 12:02:47 +02:00
|
|
|
|
2018-07-15 13:40:17 -07:00
|
|
|
import yaml
|
2018-06-15 16:17:07 -07:00
|
|
|
|
2018-07-31 12:02:47 +02:00
|
|
|
from systemdspawner import SystemdSpawner
|
|
|
|
|
from tljh import user, configurer
|
|
|
|
|
from tljh.config import INSTALL_PREFIX, USER_ENV_PREFIX
|
2018-06-26 18:36:42 -07:00
|
|
|
|
2018-07-12 13:33:24 -07:00
|
|
|
|
2018-06-26 23:30:06 -07:00
|
|
|
class CustomSpawner(SystemdSpawner):
|
|
|
|
|
def start(self):
|
|
|
|
|
"""
|
|
|
|
|
Perform system user activities before starting server
|
|
|
|
|
"""
|
|
|
|
|
# FIXME: Move this elsewhere? Into the Authenticator?
|
2018-07-12 13:33:24 -07:00
|
|
|
system_username = 'jupyter-' + self.user.name
|
|
|
|
|
user.ensure_user(system_username)
|
|
|
|
|
user.ensure_user_group(system_username, 'jupyterhub-users')
|
2018-06-26 23:30:06 -07:00
|
|
|
if self.user.admin:
|
2018-07-12 13:33:24 -07:00
|
|
|
user.ensure_user_group(system_username, 'jupyterhub-admins')
|
2018-06-27 00:33:41 -07:00
|
|
|
else:
|
2018-07-12 13:33:24 -07:00
|
|
|
user.remove_user_group(system_username, 'jupyterhub-admins')
|
2018-06-26 23:30:06 -07:00
|
|
|
return super().start()
|
|
|
|
|
|
2018-07-12 13:33:24 -07:00
|
|
|
|
2018-06-26 23:30:06 -07:00
|
|
|
c.JupyterHub.spawner_class = CustomSpawner
|
2018-06-15 16:17:07 -07:00
|
|
|
|
2018-06-27 17:38:42 -07:00
|
|
|
# Use a high port so users can try this on machines with a JupyterHub already present
|
|
|
|
|
c.JupyterHub.hub_port = 15001
|
|
|
|
|
|
|
|
|
|
c.ConfigurableHTTPProxy.should_start = False
|
|
|
|
|
c.ConfigurableHTTPProxy.api_url = 'http://127.0.0.1:15002'
|
|
|
|
|
|
2018-06-26 18:36:42 -07:00
|
|
|
c.SystemdSpawner.extra_paths = [os.path.join(USER_ENV_PREFIX, 'bin')]
|
2018-06-28 01:33:28 -07:00
|
|
|
c.SystemdSpawner.default_shell = '/bin/bash'
|
2018-06-29 01:24:30 -07:00
|
|
|
# Drop the '-singleuser' suffix present in the default template
|
|
|
|
|
c.SystemdSpawner.unit_name_template = 'jupyter-{USERNAME}'
|
2018-06-27 01:18:07 -07:00
|
|
|
|
2018-07-15 13:40:17 -07:00
|
|
|
config_overrides_path = os.path.join(INSTALL_PREFIX, 'config.yaml')
|
|
|
|
|
if os.path.exists(config_overrides_path):
|
|
|
|
|
with open(config_overrides_path) as f:
|
|
|
|
|
config_overrides = yaml.safe_load(f)
|
|
|
|
|
else:
|
|
|
|
|
config_overrides = {}
|
|
|
|
|
configurer.apply_config(config_overrides, c)
|