Merge pull request #1951 from SkynetLabs/silence-health-checks-when-container-not-running
skip health checks if container is not running
This commit is contained in:
commit
42e5266bca
|
@ -33,6 +33,13 @@ sc_precision = 10**24
|
||||||
setup_done = False
|
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
|
# find out local siad ip by inspecting its docker container
|
||||||
def get_docker_container_ip(container_name):
|
def get_docker_container_ip(container_name):
|
||||||
ip_regex = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
|
ip_regex = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
|
||||||
|
|
|
@ -10,7 +10,7 @@ import traceback
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import requests
|
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
|
health-checker reads the /health-check endpoint of the portal and dispatches
|
||||||
|
@ -135,6 +135,12 @@ async def check_disk():
|
||||||
async def check_health():
|
async def check_health():
|
||||||
print("\nChecking portal health status...")
|
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:
|
try:
|
||||||
endpoint = "http://{}:{}".format(get_docker_container_ip("health-check"), 3100)
|
endpoint = "http://{}:{}".format(get_docker_container_ip("health-check"), 3100)
|
||||||
except:
|
except:
|
||||||
|
|
Reference in New Issue