+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 False
+ return True
+
+def check_uptodate():
+ 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)
+ 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, requests.exceptions.ConnectionError):
+ pass
+ try:
+ local_lm = last_modified(retrieve_from_host('localhost', URL))
+ except (requests.exceptions.ProxyError, requests.exceptions.ReadTimeout, requests.exceptions.ConnectTimeout, requests.exceptions.ConnectionError):
+ return False
+ logging.debug("lm for localhost: %s", local_lm)
+ if local_lm < latest_ts:
+ logging.info("considering myself unhealthy my ts=%s latest_ts=%s", local_lm, latest_ts)
+ return False
+ return True
+