in src/monitor.py [0:0]
def run(session: Session, config: Dict[str, str]):
attempts = 0
while attempts < 10:
attempts += 1
response = send_request(config['SECUREDROP_URL'])
passes_healthcheck = healthcheck(response)
if passes_healthcheck:
logger.info(f'Healthcheck: passed on attempt {attempts}')
upload_website_index(session, config, passes_healthcheck)
if get_uptime() < 1600:
send_message(config, passes_healthcheck)
elif hour_is_0900():
send_message(config, passes_healthcheck)
elif attempts > 3:
send_message(config, passes_healthcheck)
break
logger.info(f'Healthcheck: unable to reach site on attempt {attempts}')
# Restart tor service on second failure, and wait for 6 minutes before attempt 2, and total possible time taken
# to complete all attempts should be calculated to be less than (3600*number of runs per hour)
if attempts == 3:
logger.info('Healthcheck: rebuilding tor circuits')
os.popen('systemctl restart tor')
time.sleep(300)
time.sleep(80)
else:
logger.info('Healthcheck: failed healthcheck')
upload_website_index(session, config, False)
send_message(config, passed=False)
send_failure_email(session, config)