From 6db4a527e6390d9b7ee6fadfb3803224f605a6b6 Mon Sep 17 00:00:00 2001 From: vincent Date: Sun, 30 Jan 2022 17:05:29 +0100 Subject: [PATCH] lint check service --- script/script/check_service.py | 86 +++++++++++++++++----------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/script/script/check_service.py b/script/script/check_service.py index 1c47bc9..1853c3e 100644 --- a/script/script/check_service.py +++ b/script/script/check_service.py @@ -2,58 +2,61 @@ import subprocess import time import sys -services=("syncthing@vincent", - "postgresql", - "nginx", - "php-fpm", - "gitea", - "tt-rss", - "gunicorn-chainetv.socket", - "supysonic-server", - "rsyncd.service", - "fail2ban", - "supysonic-daemon", - "home-assistant", - "radicale", - "chisel-server", - "JDownloader", - "vaultwarden") - -containers=("pihole",) +services = ("syncthing@vincent", + "postgresql", + "nginx", + "php-fpm", + "gitea", + "tt-rss", + "gunicorn-chainetv.socket", + "supysonic-server", + "rsyncd.service", + "fail2ban", + "supysonic-daemon", + "home-assistant", + "radicale", + "chisel-server", + "JDownloader", + "vaultwarden") +containers = ("pihole",) class Service(object): def __init__(self, serviceName): - self.name=serviceName - + self.name = serviceName + def is_active(self): - cmd="/usr/bin/systemctl" - proc=subprocess.Popen([cmd,'is-active',self.name],stdout=subprocess.PIPE) + cmd = "/usr/bin/systemctl" + proc = subprocess.Popen( + [cmd, 'is-active', self.name], stdout=subprocess.PIPE) proc.communicate() - rc=proc.returncode + rc = proc.returncode if rc == 0: return True else: return False def get_last_log(self): - cmd="/usr/bin/journalctl" - proc=subprocess.check_output([cmd,'--lines=10','-q','-u',self.name]) + cmd = "/usr/bin/journalctl" + proc = subprocess.check_output( + [cmd, '--lines=10', '-q', '-u', self.name]) return proc.decode('UTF-8').split('\n') + class Container(object): def __init__(self, containerName): - self.name=containerName + self.name = containerName - def is_active (self): - cmd="/usr/bin/docker" + def is_active(self): + cmd = "/usr/bin/docker" try: - proc=subprocess.check_output([cmd,'ps'],stderr=subprocess.STDOUT) + proc = subprocess.check_output( + [cmd, 'ps'], stderr=subprocess.STDOUT) except: - proc=b'' + proc = b'' pass - proc=proc.decode('UTF-8') + proc = proc.decode('UTF-8') if (proc.find(self.name) != -1): return True else: @@ -61,26 +64,25 @@ class Container(object): if __name__ == '__main__': - wait=True + wait = True if len(sys.argv) > 1: if sys.argv[1] == "nowait": - wait=False - + wait = False + if (wait): time.sleep(15) - for serviceName in services: - serviceObj=Service(serviceName) + serviceObj = Service(serviceName) if (serviceObj.is_active()): - print (f"{serviceObj.name} is active") + print(f"{serviceObj.name} is active") else: - print (f"{serviceObj.name} is inactive") + print(f"{serviceObj.name} is inactive") for line in serviceObj.get_last_log(): - print(line) + print(line) for containerName in containers: - containerObj=Container(containerName) + containerObj = Container(containerName) if containerObj.is_active(): - print (f"{containerObj.name} is active") + print(f"{containerObj.name} is active") else: - print (f"{containerObj.name} is inactive") + print(f"{containerObj.name} is inactive")