diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..3a88b27 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include tljh/systemd-units/* diff --git a/tljh/installer.py b/tljh/installer.py new file mode 100644 index 0000000..070b7b8 --- /dev/null +++ b/tljh/installer.py @@ -0,0 +1,49 @@ +import sys +import os +import tljh.systemd as systemd +import tljh.conda as conda + +INSTALL_PREFIX = os.environ.get('TLJH_INSTALL_PREFIX', '/opt/tljh') +HUB_ENV_PREFIX = os.path.join(INSTALL_PREFIX, 'hub') +USER_ENV_PREFIX = os.path.join(INSTALL_PREFIX, 'user') + +HERE = os.path.abspath(os.path.dirname(__file__)) + + +def ensure_jupyterhub_service(prefix): + with open(os.path.join(HERE, 'systemd-units', 'jupyterhub.service')) as f: + unit_template = f.read() + + unit = unit_template.format( + python_interpreter_path=sys.executable, + jupyterhub_config_path=os.path.join(HERE, 'jupyterhub_config.py'), + prefix=prefix + ) + systemd.install_unit('jupyterhub.service', unit) + + +def ensure_jupyterhub_package(prefix): + """ + Install JupyterHub into our conda environment if needed. + + Conda constructor does not play well with conda-forge, so we can ship this + with constructor + """ + # FIXME: Use fully deterministic package lists here + conda.ensure_conda_packages(prefix, ['jupyterhub==0.9.0']) + conda.ensure_pip_packages(prefix, [ + 'jupyterhub-dummyauthenticator==0.3.1', + 'jupyterhub-systemdspawner==0.9.12' + ]) + + +ensure_jupyterhub_package(HUB_ENV_PREFIX) +ensure_jupyterhub_service(HUB_ENV_PREFIX) + +conda.ensure_conda_env(USER_ENV_PREFIX) +conda.ensure_conda_packages(USER_ENV_PREFIX, [ + 'jupyterhub==0.9.0', + 'notebook==5.5.0' +]) +systemd.reload_daemon() +systemd.start_service('jupyterhub') diff --git a/tljh/systemd-units/jupyterhub.service b/tljh/systemd-units/jupyterhub.service new file mode 100644 index 0000000..232fc1e --- /dev/null +++ b/tljh/systemd-units/jupyterhub.service @@ -0,0 +1,12 @@ +# Template file for JupyterHub systemd service +# Runs both JupyterHub and ConfigurableHTTPProxy +# Uses simple string.format() for 'templating' +[Unit] +Wants=network-online.target + +[Service] +User=root +Restart=always +StateDirectory=jupyterhub +WorkingDirectory=/var/lib/jupyterhub +ExecStart={python_interpreter_path} -m jupyterhub.app -f {jupyterhub_config_path}