From 89f7d983b41a41f17dcd4d1f8a2adf5696682ed2 Mon Sep 17 00:00:00 2001 From: Florent Daigniere Date: Thu, 27 Oct 2022 10:51:45 +0200 Subject: [PATCH] Don't start rspamd until admin is up and working --- core/rspamd/start.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/rspamd/start.py b/core/rspamd/start.py index fcb33a97..b03a602f 100755 --- a/core/rspamd/start.py +++ b/core/rspamd/start.py @@ -3,7 +3,9 @@ import os import glob import logging as log +import requests import sys +import time from socrate import system, conf log.basicConfig(stream=sys.stderr, level=os.environ.get("LOG_LEVEL", "WARNING")) @@ -19,5 +21,16 @@ if os.environ.get("ANTIVIRUS") == 'clamav': for rspamd_file in glob.glob("/conf/*"): conf.jinja(rspamd_file, os.environ, os.path.join("/etc/rspamd/local.d", os.path.basename(rspamd_file))) +# Admin may not be up just yet +healthcheck = f'http://{os.environ["ADMIN_ADDRESS"]}/internal/rspamd/local_domains' +while True: + time.sleep(1) + try: + if requests.get(healthcheck,timeout=2).ok: + break + except: + pass + print("Admin is not up just yet, retrying in 1 second") + # Run rspamd os.execv("/usr/sbin/rspamd", ["rspamd", "-i", "-f"])