containers/osbuild-composer: wait for fluentd in entrypoint

to avoid composer crashing and restarting when fluentd is not up
HMS-1496
This commit is contained in:
Diaa Sami 2023-03-28 11:51:11 +02:00 committed by Sanne Raymaekers
parent 943ead790e
commit b4cf032239

View file

@ -20,6 +20,9 @@ import time
class Cli(contextlib.AbstractContextManager):
"""Command Line Interface"""
SYSLOG_RETRIES=5
SYSLOG_WAIT=2.0
def __init__(self, argv):
self.args = None
self._argv = argv
@ -241,6 +244,25 @@ class Cli(contextlib.AbstractContextManager):
stderr=subprocess.STDOUT,
)
@staticmethod
def _wait_for_syslog(addr):
print("Waiting for fluentd syslog server", file=sys.stderr)
for _ in range(Cli.SYSLOG_RETRIES):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(addr)
except ConnectionRefusedError:
time.sleep(Cli.SYSLOG_WAIT)
continue
except (NameError, ConnectionError) as ex:
print("Unexpected error:", ex , file=sys.stderr)
break
finally:
sock.close()
print("fluentd syslog server is up", file=sys.stderr)
break
@staticmethod
def _spawn_composer(sockets):
cmd = [
@ -295,6 +317,9 @@ class Cli(contextlib.AbstractContextManager):
proc_worker = self._spawn_worker()
if any([self.args.weldr_api, self.args.composer_api, self.args.local_worker_api, self.args.remote_worker_api]):
if "SYSLOG_SERVER" in os.environ:
addr, port = os.environ["SYSLOG_SERVER"].split(":")
self._wait_for_syslog((addr, int(port)))
proc_composer = self._spawn_composer(sockets)
if proc_composer: