diff options
Diffstat (limited to 'catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py')
-rw-r--r-- | catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py b/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py new file mode 100644 index 0000000000..7d8558d644 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/sdcBePy/common/healthCheck.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +import sys +import time +from argparse import ArgumentParser +from datetime import datetime + +from sdcBePy.common.bColors import BColors +from sdcBePy.common.sdcBeProxy import SdcBeProxy + +colors = BColors() + +RETRY_TIME = 10 +RETRY_ATTEMPTS = 10 + + +def check_backend(sdc_be_proxy=None, reply_append_count=1, be_host=None, be_port=None, scheme=None, debug=False): + if sdc_be_proxy is None: + sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, debug=debug) + + for i in range(1, reply_append_count + 1): + if sdc_be_proxy.check_backend() == 200: + print('[INFO]: Backend is up and running') + return True + else: + print('[WARRING]: ' + datetime.now().strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL + + ' Backend not responding, try #' + str(i) + colors.END_C) + time.sleep(RETRY_TIME) + + return False + + +def run(be_host, be_port, protocol): + if not check_backend(reply_append_count=RETRY_ATTEMPTS, be_host=be_host, be_port=be_port, scheme=protocol): + print('[ERROR]: ' + time.strftime('%Y/%m/%d %H:%M:%S') + colors.FAIL + ' Backend is DOWN :-(' + colors.END_C) + sys.exit() + + +def get_args(): + parser = ArgumentParser() + + parser.add_argument('-i', '--ip', required=True) + parser.add_argument('-p', '--port', required=True) + parser.add_argument('--https', action='store_true') + + args = parser.parse_args() + + return [args.ip, args.port, 'https' if args.https else 'http'] + + +def main(): + run(*get_args()) + + +if __name__ == '__main__': + main() |