2018-06-15 16:54:40 -07:00
|
|
|
"""
|
|
|
|
|
JupyterHub config for the littlest jupyterhub.
|
|
|
|
|
"""
|
2018-06-26 23:30:06 -07:00
|
|
|
from escapism import escape
|
2018-06-15 16:17:07 -07:00
|
|
|
import os
|
2018-06-26 23:30:06 -07:00
|
|
|
from systemdspawner import SystemdSpawner
|
|
|
|
|
from tljh import user
|
2018-06-15 16:17:07 -07:00
|
|
|
|
2018-06-26 23:30:06 -07:00
|
|
|
INSTALL_PREFIX = os.environ.get('TLJH_INSTALL_PREFIX')
|
2018-06-26 18:36:42 -07:00
|
|
|
USER_ENV_PREFIX = os.path.join(INSTALL_PREFIX, 'user')
|
|
|
|
|
|
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?
|
|
|
|
|
user.ensure_user(self.user.name)
|
|
|
|
|
user.ensure_user_group(self.user.name, 'jupyterhub-users')
|
|
|
|
|
if self.user.admin:
|
|
|
|
|
user.ensure_user_group(self.user.name, 'jupyterhub-admins')
|
2018-06-27 00:33:41 -07:00
|
|
|
else:
|
|
|
|
|
user.remove_user_group(self.user.name, 'jupyterhub-admins')
|
2018-06-26 23:30:06 -07:00
|
|
|
return super().start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.JupyterHub.spawner_class = CustomSpawner
|
2018-06-15 16:17:07 -07:00
|
|
|
c.JupyterHub.authenticator_class = 'dummyauthenticator.DummyAuthenticator'
|
|
|
|
|
|
2018-06-26 18:36:42 -07:00
|
|
|
c.SystemdSpawner.extra_paths = [os.path.join(USER_ENV_PREFIX, 'bin')]
|
2018-06-26 04:14:29 -07:00
|
|
|
c.SystemdSpawner.use_sudo = True
|