chg: Improve start/stop

pull/105/head
Raphaël Vinot 2020-10-22 16:41:00 +02:00
parent fafcc8ff89
commit c6c4da981c
3 changed files with 24 additions and 17 deletions

View File

@ -1,17 +1,23 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from subprocess import Popen from subprocess import run, Popen
from lookyloo.helpers import get_homedir from lookyloo.helpers import get_homedir
def main(): def main():
# Just fail if the env isn't set. # Just fail if the env isn't set.
get_homedir() get_homedir()
p = Popen(['run_backend', '--start']) print('Start backend (redis)...')
p.wait() p = run(['run_backend', '--start'])
p.check_returncode()
print('done.')
print('Start asynchronous ingestor...')
Popen(['async_scrape']) Popen(['async_scrape'])
print('done.')
print('Start website...')
Popen(['start_website']) Popen(['start_website'])
print('done.')
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -30,12 +30,13 @@ def keep_going(ignore=False):
sys.exit() sys.exit()
def run_command(command): def run_command(command, expect_fail: bool=False, capture_output: bool=True):
args = shlex.split(command) args = shlex.split(command)
homedir = get_homedir() homedir = get_homedir()
process = subprocess.run(args, cwd=homedir, capture_output=True) process = subprocess.run(args, cwd=homedir, capture_output=capture_output)
print(process.stdout.decode()) if capture_output:
if process.returncode: print(process.stdout.decode())
if process.returncode and not expect_fail:
print(process.stderr.decode()) print(process.stderr.decode())
sys.exit() sys.exit()
@ -91,13 +92,17 @@ def main():
print('* Restarting Lookyloo.') print('* Restarting Lookyloo.')
keep_going(args.yes) keep_going(args.yes)
service = "lookyloo" service = "lookyloo"
p = subprocess.Popen(["systemctl", "is-active", service], stdout=subprocess.PIPE) p = subprocess.run(["systemctl", "is-active", "--quiet", service])
(output, err) = p.communicate() try:
if output.decode('utf-8') == "active\n": p.check_returncode()
print('Restarting Lookyloo with systemd...')
run_command('sudo service lookyloo restart') run_command('sudo service lookyloo restart')
else: print('done.')
run_command('poetry run stop') except subprocess.CalledProcessError:
run_command('poetry run start') 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__': if __name__ == '__main__':

View File

@ -170,10 +170,6 @@ class VirusTotal():
self.storage_dir_vt = get_homedir() / 'vt_url' self.storage_dir_vt = get_homedir() / 'vt_url'
self.storage_dir_vt.mkdir(parents=True, exist_ok=True) 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: def __get_cache_directory(self, url: str) -> Path:
url_id = vt.url_id(url) url_id = vt.url_id(url)
m = hashlib.md5() m = hashlib.md5()