#!/usr/bin/env python3 import argparse import requests parser = argparse.ArgumentParser(description='Make an HTTP request and retry a health check if successful.') parser.add_argument('url', help='the URL to request') parser.add_argument('--hs', help='the health check URL') args = parser.parse_args() response = requests.get(args.url) if response.status_code == 200: if args.hs: retry_count = 3 while retry_count > 0: try: requests.get(args.hs) break except requests.exceptions.RequestException: retry_count -= 1 else: print('Health check URL not provided, skipping...') else: print(f'HTTP status code is {response.status_code}, aborting...') exit(1)