OUTPUT_DIR = "/run/dsa-mirror-health-{}".format(os.environ['MIRROR_CHECK_SERVICE'])
HEALTH_FILE = os.path.join(OUTPUT_DIR, "health")
URL = os.environ['MIRROR_CHECK_URL']
+HEALTH_CHECK_URL = os.environ['MIRROR_CHECK_HEALTH_URL']
INTERVAL = int(os.environ.get('MIRROR_CHECK_INTERVAL', '60'))
-latest_ts = 0
-
def retrieve_from_host(host, url):
proxies = {
'http': 'http://{}:80'.format(host),
lm = calendar.timegm(parsedate(response.headers['last-modified']))
return lm
+def healthy(response):
+ if response.status_code == 200:
+ return True
+ return False
+
def check_shutdown():
if subprocess.call(['dsa-is-shutdown-scheduled']) == 0:
logging.info("considering myself unhealthy, shutdown scheduled")
return True
def check_uptodate():
- global latest_ts
+ latest_ts = 0
for host in HOSTS:
try:
lm = last_modified(retrieve_from_host(host, URL))
logging.debug("lm for host %s: %s", host, lm)
- latest_ts = max(latest_ts, lm)
+ if healthy(retrieve_from_host(host, HEALTH_CHECK_URL)):
+ latest_ts = max(latest_ts, lm)
except (requests.exceptions.ProxyError, requests.exceptions.ReadTimeout, requests.exceptions.ConnectTimeout):
pass
try:
check_hosts => ['accumu.debian.backend.mirrors.debian.org', 'bytemark.debian.backend.mirrors.debian.org', 'conova.debian.backend.mirrors.debian.org', 'skroutz.debian.backend.mirrors.debian.org'],
check_service => 'ftp',
url => 'http://debian.backend.mirrors.debian.org/debian/dists/sid/Release',
+ health_url => 'http://debian.backend.mirrors.debian.org/_health',
}
}
Environment="MIRROR_CHECK_SERVICE=<%= @check_service %>"
Environment="MIRROR_CHECK_URL=<%= @url %>"
+Environment="MIRROR_CHECK_HEALTH_URL=<%= @health_url %>"
Environment="MIRROR_CHECK_HOSTS=<%= @check_hosts.join ' ' %>"
Environment="MIRROR_CHECK_INTERVAL=<%= @check_interval %>"