X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Froles%2Ffiles%2Fmirror_health%2Fmirror-health;h=d3df95f37bf2fa06258eae14533316b747fa68ca;hb=3d8cddc478904d0b4b8d58f99bd2c3cca23bdc42;hp=1d4fae0e3ce8fc140834d8dddf911035834b9a8c;hpb=dc142e05682ed2976e677b5b08f5d623cf9136fd;p=mirror%2Fdsa-puppet.git diff --git a/modules/roles/files/mirror_health/mirror-health b/modules/roles/files/mirror_health/mirror-health index 1d4fae0e3..d3df95f37 100755 --- a/modules/roles/files/mirror_health/mirror-health +++ b/modules/roles/files/mirror_health/mirror-health @@ -5,6 +5,7 @@ import requests import time import calendar import logging +import subprocess from email.utils import parsedate logging.basicConfig(level=logging.INFO) @@ -29,15 +30,20 @@ def last_modified(response): lm = calendar.timegm(parsedate(response.headers['last-modified'])) return lm +def check_shutdown(): + if subprocess.call(['dsa-is-shutdown-scheduled']) == 0: + logging.info("considering myself unhealthy, shutdown scheduled") + return False + return True + def check_uptodate(): global latest_ts for host in HOSTS: try: lm = last_modified(retrieve_from_host(host, URL)) logging.debug("lm for host %s: %s", host, lm) - if lm > latest_ts: - latest_ts = lm - except requests.exceptions.ProxyError: + latest_ts = max(latest_ts, lm) + except (requests.exceptions.ProxyError, requests.exceptions.ReadTimeout): pass local_lm = last_modified(retrieve_from_host('localhost', URL)) logging.debug("lm for localhost: %s", local_lm) @@ -48,7 +54,7 @@ def check_uptodate(): while True: start = time.time() - if check_uptodate(): + if check_shutdown() and check_uptodate(): logging.info("considering myself healthy") open(HEALTH_FILE, 'w').write("OK") else: