From 7fa72f8c1910f7656b6421f79e970e400151cf24 Mon Sep 17 00:00:00 2001 From: vincent Date: Sun, 13 Feb 2022 10:36:02 +0100 Subject: [PATCH] update check service --- script/script/check_service.py | 57 +++++++++++++++++----------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/script/script/check_service.py b/script/script/check_service.py index 1853c3e..2dd83f8 100644 --- a/script/script/check_service.py +++ b/script/script/check_service.py @@ -2,22 +2,24 @@ 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") +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",) @@ -28,8 +30,7 @@ class Service(object): def is_active(self): cmd = "/usr/bin/systemctl" - proc = subprocess.Popen( - [cmd, 'is-active', self.name], stdout=subprocess.PIPE) + proc = subprocess.Popen([cmd, "is-active", self.name], stdout=subprocess.PIPE) proc.communicate() rc = proc.returncode if rc == 0: @@ -39,9 +40,8 @@ class Service(object): def get_last_log(self): cmd = "/usr/bin/journalctl" - proc = subprocess.check_output( - [cmd, '--lines=10', '-q', '-u', self.name]) - return proc.decode('UTF-8').split('\n') + proc = subprocess.check_output([cmd, "--lines=10", "-q", "-u", self.name]) + return proc.decode("UTF-8").split("\n") class Container(object): @@ -51,30 +51,29 @@ class Container(object): 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') - if (proc.find(self.name) != -1): + proc = proc.decode("UTF-8") + if proc.find(self.name) != -1: return True else: return False -if __name__ == '__main__': +if __name__ == "__main__": wait = True if len(sys.argv) > 1: if sys.argv[1] == "nowait": wait = False - if (wait): + if wait: time.sleep(15) for serviceName in services: serviceObj = Service(serviceName) - if (serviceObj.is_active()): + if serviceObj.is_active(): print(f"{serviceObj.name} is active") else: print(f"{serviceObj.name} is inactive")