X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Fmirror_health%2Ffiles%2Fmirror-health;h=8c7498cc0ae2d380398246b2afd8dbca76a72bd5;hb=689a1da09e35835d4f266891eb30182a5d6b6018;hp=025382e78c78545dd33b6f877755b38ceb9f94d5;hpb=0b6cb05ea797df93a05d5ba0d3ec549f16f7063d;p=mirror%2Fdsa-puppet.git diff --git a/modules/mirror_health/files/mirror-health b/modules/mirror_health/files/mirror-health index 025382e78..8c7498cc0 100755 --- a/modules/mirror_health/files/mirror-health +++ b/modules/mirror_health/files/mirror-health @@ -7,6 +7,8 @@ import calendar import logging import subprocess from email.utils import parsedate +import urllib3.util.connection + logging.basicConfig(level=logging.INFO) if 'MIRROR_CHECK_HOSTS' in os.environ: @@ -21,12 +23,16 @@ HEALTH_CHECK_URL = os.environ['MIRROR_CHECK_HEALTH_URL'] INTERVAL = int(os.environ.get('MIRROR_CHECK_INTERVAL', '60')) def retrieve_from_host(host, url): - proxies = { - 'http': 'http://{}:80'.format(host), - 'https': 'http://{}:443'.format(host), - } + orig_create_connection = urllib3.util.connection.create_connection + def patched_create_connection(address, *args, **kwargs): + _host, port = address + return orig_create_connection((host, port), *args, **kwargs) headers = {'User-Agent': 'mirror-health'} - return requests.get(url, headers=headers, timeout=5, proxies=proxies, allow_redirects=False) + urllib3.util.connection.create_connection = patched_create_connection + try: + return requests.get(url, headers=headers, timeout=5, allow_redirects=False) + finally: + urllib3.util.connection.create_connection = orig_create_connection def last_modified(response): lm = 0 @@ -40,7 +46,7 @@ def healthy(response): return False def check_shutdown(): - if subprocess.call(['dsa-is-shutdown-scheduled']) == 0: + if os.path.exists('/run/systemd/shutdown/scheduled'): logging.info("considering myself unhealthy, shutdown scheduled") return False return True