From c6c4da981c06c7e117f00fe9afb7e46fafd3bd85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 22 Oct 2020 16:41:00 +0200 Subject: [PATCH] chg: Improve start/stop --- bin/start.py | 12 +++++++++--- bin/update.py | 25 +++++++++++++++---------- lookyloo/modules.py | 4 ---- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/bin/start.py b/bin/start.py index d7dfa2e..68382de 100755 --- a/bin/start.py +++ b/bin/start.py @@ -1,17 +1,23 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from subprocess import Popen +from subprocess import run, Popen from lookyloo.helpers import get_homedir def main(): # Just fail if the env isn't set. get_homedir() - p = Popen(['run_backend', '--start']) - p.wait() + print('Start backend (redis)...') + p = run(['run_backend', '--start']) + p.check_returncode() + print('done.') + print('Start asynchronous ingestor...') Popen(['async_scrape']) + print('done.') + print('Start website...') Popen(['start_website']) + print('done.') if __name__ == '__main__': diff --git a/bin/update.py b/bin/update.py index 1c65acb..99b5eed 100755 --- a/bin/update.py +++ b/bin/update.py @@ -30,12 +30,13 @@ def keep_going(ignore=False): sys.exit() -def run_command(command): +def run_command(command, expect_fail: bool=False, capture_output: bool=True): args = shlex.split(command) homedir = get_homedir() - process = subprocess.run(args, cwd=homedir, capture_output=True) - print(process.stdout.decode()) - if process.returncode: + process = subprocess.run(args, cwd=homedir, capture_output=capture_output) + if capture_output: + print(process.stdout.decode()) + if process.returncode and not expect_fail: print(process.stderr.decode()) sys.exit() @@ -91,13 +92,17 @@ def main(): print('* Restarting Lookyloo.') keep_going(args.yes) service = "lookyloo" - p = subprocess.Popen(["systemctl", "is-active", service], stdout=subprocess.PIPE) - (output, err) = p.communicate() - if output.decode('utf-8') == "active\n": + p = subprocess.run(["systemctl", "is-active", "--quiet", service]) + try: + p.check_returncode() + print('Restarting Lookyloo with systemd...') run_command('sudo service lookyloo restart') - else: - run_command('poetry run stop') - run_command('poetry run start') + print('done.') + except subprocess.CalledProcessError: + print('Restarting Lookyloo with poetry...') + run_command('poetry run stop', expect_fail=True) + run_command('poetry run start', capture_output=False) + print('Lookyloo started.') if __name__ == '__main__': diff --git a/lookyloo/modules.py b/lookyloo/modules.py index da8c40b..d4ecf28 100644 --- a/lookyloo/modules.py +++ b/lookyloo/modules.py @@ -170,10 +170,6 @@ class VirusTotal(): self.storage_dir_vt = get_homedir() / 'vt_url' self.storage_dir_vt.mkdir(parents=True, exist_ok=True) - def __del__(self) -> None: - if hasattr(self, 'client'): - self.client.close() - def __get_cache_directory(self, url: str) -> Path: url_id = vt.url_id(url) m = hashlib.md5()