Add a simple installer!

Sortof re-invents what debian packages do a little bit.
This commit is contained in:
yuvipanda
2018-06-26 18:37:24 -07:00
parent 4042288e91
commit 5f4aed5b4b
3 changed files with 62 additions and 0 deletions

1
MANIFEST.in Normal file
View File

@@ -0,0 +1 @@
include tljh/systemd-units/*

49
tljh/installer.py Normal file
View File

@@ -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')

View File

@@ -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}