(prefix)
Ensure JupyterHub Services are set up properly
Ensure JupyterHub Services are set up properly
Ensure JupyterHub Services are set up properly
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")
def ensure_jupyterhub_service ( prefix ) : 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" )