Removed chp service

This commit is contained in:
GeorgianaElena
2019-02-18 15:08:53 +02:00
parent ffa635dda3
commit 84d8000114
3 changed files with 59 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
"""Test traefik configuration""" """Test traefik configuration"""
import os import os
import mock from unittest import mock
import pytoml as toml import pytoml as toml

View File

@@ -99,15 +99,25 @@ sckuXINIU3DFWzZGr0QrqkuE/jyr7FXeUJj9B7cLo+s/TXo+RaVfi3kOc9BoxIvy
apt.add_source('nodesource', 'https://deb.nodesource.com/node_10.x', 'main') apt.add_source('nodesource', 'https://deb.nodesource.com/node_10.x', 'main')
apt.install_packages(['nodejs']) apt.install_packages(['nodejs'])
def remove_chp():
def ensure_chp_package(prefix):
""" """
Ensure CHP is installed Ensure CHP is not running
""" """
if not os.path.exists(os.path.join(prefix, 'node_modules', '.bin', 'configurable-http-proxy')): if os.path.exists(os.path.join(HERE, 'systemd-units', 'configurable-http-proxy.service')):
subprocess.check_output([ if systemd.check_service_active('configurable-http-proxy.service'):
'npm', 'install', 'configurable-http-proxy@3.1.0' try:
], cwd=prefix, stderr=subprocess.STDOUT) systemd.stop_service('configurable-http-proxy.service')
except subprocess.CalledProcessError:
logger.info("Cannot stop configurable-http-proxy...")
if systemd.check_service_enabled('configurable-http-proxy.service'):
try:
systemd.disable_service('configurable-http-proxy.service')
except subprocess.CalledProcessError:
logger.info("Cannot disable configurable-http-proxy...")
try:
systemd.uninstall_unit('configurable-http-proxy.service')
except subprocess.CalledProcessError:
logger.info("Cannot uninstall configurable-http-proxy...")
def ensure_jupyterhub_service(prefix): def ensure_jupyterhub_service(prefix):
@@ -117,11 +127,12 @@ def ensure_jupyterhub_service(prefix):
os.makedirs(STATE_DIR, mode=0o700, exist_ok=True) os.makedirs(STATE_DIR, mode=0o700, exist_ok=True)
remove_chp()
systemd.reload_daemon()
with open(os.path.join(HERE, 'systemd-units', 'jupyterhub.service')) as f: with open(os.path.join(HERE, 'systemd-units', 'jupyterhub.service')) as f:
hub_unit_template = f.read() hub_unit_template = f.read()
# with open(os.path.join(HERE, 'systemd-units', 'configurable-http-proxy.service')) as f:
# chp_unit_template = f.read()
with open(os.path.join(HERE, 'systemd-units', 'traefik.service')) as f: with open(os.path.join(HERE, 'systemd-units', 'traefik.service')) as f:
traefik_unit_template = f.read() traefik_unit_template = f.read()
@@ -141,7 +152,6 @@ def ensure_jupyterhub_service(prefix):
) )
systemd.install_unit('jupyterhub.service', hub_unit_template.format(**unit_params)) systemd.install_unit('jupyterhub.service', hub_unit_template.format(**unit_params))
systemd.install_unit('traefik.service', traefik_unit_template.format(**unit_params)) systemd.install_unit('traefik.service', traefik_unit_template.format(**unit_params))
# systemd.install_unit('configurable-http-proxy.service', chp_unit_template.format(**unit_params))
systemd.reload_daemon() systemd.reload_daemon()
# If JupyterHub is running, we want to restart it. # If JupyterHub is running, we want to restart it.

View File

@@ -48,6 +48,17 @@ def start_service(name):
], check=True) ], check=True)
def stop_service(name):
"""
Start service with given name.
"""
subprocess.run([
'systemctl',
'stop',
name
], check=True)
def restart_service(name): def restart_service(name):
""" """
Restart service with given name. Restart service with given name.
@@ -72,6 +83,19 @@ def enable_service(name):
], check=True) ], check=True)
def disable_service(name):
"""
Enable a service with given name.
This most likely makes the service start on bootup
"""
subprocess.run([
'systemctl',
'disable',
name
], check=True)
def check_service_active(name): def check_service_active(name):
""" """
Check if a service is currently active (running) Check if a service is currently active (running)
@@ -85,3 +109,17 @@ def check_service_active(name):
return True return True
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
return False return False
def check_service_enabled(name):
"""
Check if a service is enabled
"""
try:
subprocess.run([
'systemctl',
'is-enabled',
name
], check=True)
return True
except subprocess.CalledProcessError:
return False