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
# -*- 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__':

View File

@ -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)
process = subprocess.run(args, cwd=homedir, capture_output=capture_output)
if capture_output:
print(process.stdout.decode())
if process.returncode:
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__':

View File

@ -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()