diff --git a/hyperglass/cli/commands.py b/hyperglass/cli/commands.py index 7aadc1d..11078a4 100644 --- a/hyperglass/cli/commands.py +++ b/hyperglass/cli/commands.py @@ -136,6 +136,7 @@ def setup(unattended): make_systemd, write_to_file, migrate_static_assets, + install_systemd, ) user_path = Path.home() / "hyperglass" @@ -150,7 +151,10 @@ def setup(unattended): ] if not unattended: answer = inquirer.prompt(install_paths) + if answer is None: + error("A directory for hyperglass is required") install_path = answer["install_path"] + elif unattended: install_path = user_path @@ -160,6 +164,7 @@ def setup(unattended): create_dir(install_path) create_dir(ui_dir, parents=True) create_dir(custom_dir, parents=True) + migrate_static_assets(install_path) example_dir = WORKING_DIR.parent / "examples" files = example_dir.iterdir() @@ -188,5 +193,4 @@ def setup(unattended): systemd_file = install_path / "hyperglass.service" systemd = make_systemd(user) write_to_file(systemd_file, systemd) - - migrate_static_assets(install_path) + install_systemd(install_path) diff --git a/hyperglass/cli/util.py b/hyperglass/cli/util.py index 2ee241e..83642ca 100644 --- a/hyperglass/cli/util.py +++ b/hyperglass/cli/util.py @@ -373,3 +373,32 @@ def migrate_static_assets(app_path): callback = success callback(msg, a=a, b=b) + + +def install_systemd(app_path): + """Installs generated systemd file to system's systemd directory. + + Arguments: + app_path {Path} -- hyperglass runtime path + + Raises: + ClickException: Raised if the /etc/systemd/system does not exist + ClickException: Raised if the symlinked file does not exit + + Returns: + {bool} -- True if successful + """ + service = app_path / "hyperglass.service" + systemd = Path("/etc/systemd/system") + installed = systemd / "hyperglass.service" + + if not systemd.exists(): + error("{e} does not exist. Unable to install systemd service.", e=systemd) + + installed.symlink_to(service) + + if not installed.exists(): + error("Unable to symlink {s} to {d}", s=service, d=installed) + + success("Symlinked {s} to {d}", s=service, d=installed) + return True