Ejemplo n.º 1
0
def ensure_jupyterhub_service(prefix):
    """
    Ensure JupyterHub Services are set up properly
    """

    remove_chp()
    systemd.reload_daemon()

    with open(os.path.join(HERE, 'systemd-units', 'jupyterhub.service')) as f:
        hub_unit_template = f.read()

    with open(os.path.join(HERE, 'systemd-units', 'traefik.service')) as f:
        traefik_unit_template = f.read()

    #Set up proxy / hub secret token if it is not already setup
    proxy_secret_path = os.path.join(STATE_DIR, 'traefik-api.secret')
    if not os.path.exists(proxy_secret_path):
        with open(proxy_secret_path, 'w') as f:
            f.write(secrets.token_hex(32))

    traefik.ensure_traefik_config(STATE_DIR)

    unit_params = dict(
        python_interpreter_path=sys.executable,
        jupyterhub_config_path=os.path.join(HERE, 'jupyterhub_config.py'),
        install_prefix=INSTALL_PREFIX,
    )
    systemd.install_unit('jupyterhub.service',
                         hub_unit_template.format(**unit_params))
    systemd.install_unit('traefik.service',
                         traefik_unit_template.format(**unit_params))
    systemd.reload_daemon()

    # If JupyterHub is running, we want to restart it.
    systemd.restart_service('jupyterhub')
    systemd.restart_service('traefik')

    # Mark JupyterHub & traefik to start at boot time
    systemd.enable_service('jupyterhub')
    systemd.enable_service('traefik')
Ejemplo n.º 2
0
def reload_component(component):
    """
    Reload a TLJH component.

    component can be 'hub' or 'proxy'.
    """
    # import here to avoid circular imports
    from tljh import systemd, traefik

    if component == 'hub':
        systemd.restart_service('jupyterhub')
        # Ensure hub is back up
        while not systemd.check_service_active('jupyterhub'):
            time.sleep(1)
        while not check_hub_ready():
            time.sleep(1)
        print('Hub reload with new configuration complete')
    elif component == 'proxy':
        traefik.ensure_traefik_config(STATE_DIR)
        systemd.restart_service('traefik')
        while not systemd.check_service_active('traefik'):
            time.sleep(1)
        print('Proxy reload with new configuration complete')
Ejemplo n.º 3
0
def ensure_builder_units():
    gallery_builder_service = 'tljh-voila-gallery-builder.service'
    with resource_stream(__name__,
                         f'./systemd-units/{gallery_builder_service}') as f:
        builder_unit_template = f.read().decode('utf-8')

    gallery_builder_timer = 'tljh-voila-gallery-builder.timer'
    with resource_stream(__name__,
                         f'./systemd-units/{gallery_builder_timer}') as f:
        builder_timer_template = f.read().decode('utf-8')

    unit_params = dict(python_interpreter_path=sys.executable, )

    systemd.install_unit(gallery_builder_service,
                         builder_unit_template.format(**unit_params))
    systemd.install_unit(gallery_builder_timer,
                         builder_timer_template.format(**unit_params))

    for unit in [gallery_builder_service, gallery_builder_timer]:
        systemd.restart_service(unit)
        systemd.enable_service(unit)

    systemd.reload_daemon()
Ejemplo n.º 4
0
def ensure_jupyterhub_service(prefix):
    """
    Ensure JupyterHub & CHP Services are set up properly
    """
    with open(os.path.join(HERE, 'systemd-units', 'jupyterhub.service')) as f:
        hub_unit_template = f.read()

    with open(os.path.join(HERE, 'systemd-units', 'configurable-http-proxy.service')) as f:
        proxy_unit_template = f.read()

    unit_params = dict(
        python_interpreter_path=sys.executable,
        jupyterhub_config_path=os.path.join(HERE, 'jupyterhub_config.py'),
        install_prefix=INSTALL_PREFIX
    )
    systemd.install_unit('configurable-http-proxy.service', proxy_unit_template.format(**unit_params))
    systemd.install_unit('jupyterhub.service', hub_unit_template.format(**unit_params))
    systemd.reload_daemon()

    # Set up proxy / hub secret oken if it is not already setup
    # FIXME: Check umask here properly
    proxy_secret_path = os.path.join(INSTALL_PREFIX, 'configurable-http-proxy.secret')
    if not os.path.exists(proxy_secret_path):
        with open(proxy_secret_path, 'w') as f:
            f.write('CONFIGPROXY_AUTH_TOKEN=' + secrets.token_hex(32))
        # If we are changing CONFIGPROXY_AUTH_TOKEN, restart configurable-http-proxy!
        systemd.restart_service('configurable-http-proxy')

    os.makedirs(os.path.join(INSTALL_PREFIX, 'hub', 'state'), mode=0o700, exist_ok=True)
    # Start CHP if it has already not been started
    systemd.start_service('configurable-http-proxy')
    # If JupyterHub is running, we want to restart it.
    systemd.restart_service('jupyterhub')

    # Mark JupyterHub & CHP to start at boot ime
    systemd.enable_service('jupyterhub')
    systemd.enable_service('configurable-http-proxy')
Ejemplo n.º 5
0
def reload_component(component):
    """
    Reload a TLJH component.

    component can be 'hub' or 'proxy'.
    """
    # import here to avoid circular imports
    from tljh import systemd, traefik
    if component == 'hub':
        systemd.restart_service('jupyterhub')
        # FIXME: Verify hub is back up?
        print('Hub reload with new configuration complete')
    elif component == 'proxy':
        traefik.ensure_traefik_config(STATE_DIR)
        systemd.restart_service('configurable-http-proxy')
        systemd.restart_service('traefik')
        print('Proxy reload with new configuration complete')