From 93c6e790cddec9f86299779ea9b503a0c699cf7b Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Thu, 31 Mar 2022 11:32:47 +0200 Subject: [PATCH 1/2] skip health checks if container is not running --- setup-scripts/bot_utils.py | 6 ++++++ setup-scripts/health-checker.py | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/setup-scripts/bot_utils.py b/setup-scripts/bot_utils.py index b987e464..c6d0f201 100644 --- a/setup-scripts/bot_utils.py +++ b/setup-scripts/bot_utils.py @@ -32,6 +32,12 @@ sc_precision = 10**24 # Environment variable globals setup_done = False +# get docker container id and return None if container not found +def get_docker_container_id(container_name): + docker_cmd = "docker ps -q -f name=" + container_name + output = subprocess.check_output(docker_cmd, shell=True).decode("utf-8") + return None if output == "" else output + # find out local siad ip by inspecting its docker container def get_docker_container_ip(container_name): diff --git a/setup-scripts/health-checker.py b/setup-scripts/health-checker.py index 091ebe30..947ae307 100755 --- a/setup-scripts/health-checker.py +++ b/setup-scripts/health-checker.py @@ -10,7 +10,7 @@ import traceback from datetime import datetime, timedelta import requests -from bot_utils import setup, send_msg, get_docker_container_ip +from bot_utils import setup, send_msg, get_docker_container_id, get_docker_container_ip """ health-checker reads the /health-check endpoint of the portal and dispatches @@ -135,6 +135,12 @@ async def check_disk(): async def check_health(): print("\nChecking portal health status...") + # do not try to run health checks if health-check container does not exist + # possible use case is fresh or taken down server that has only skyd running + if not get_docker_container_id("health-check"): + print("Container health-check not found - skipping health checks") + return + try: endpoint = "http://{}:{}".format(get_docker_container_ip("health-check"), 3100) except: From 42f3ef3e22c38cd06c745b5eb67a7f7dc9bb63f5 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Thu, 31 Mar 2022 15:23:58 +0200 Subject: [PATCH 2/2] add missing newline to satisfy flake8 --- setup-scripts/bot_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup-scripts/bot_utils.py b/setup-scripts/bot_utils.py index c6d0f201..65e45bcb 100644 --- a/setup-scripts/bot_utils.py +++ b/setup-scripts/bot_utils.py @@ -32,6 +32,7 @@ sc_precision = 10**24 # Environment variable globals setup_done = False + # get docker container id and return None if container not found def get_docker_container_id(container_name): docker_cmd = "docker ps -q -f name=" + container_name