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:
parent
943ead790e
commit
b4cf032239
1 changed files with 25 additions and 0 deletions
|
|
@ -20,6 +20,9 @@ import time
|
||||||
class Cli(contextlib.AbstractContextManager):
|
class Cli(contextlib.AbstractContextManager):
|
||||||
"""Command Line Interface"""
|
"""Command Line Interface"""
|
||||||
|
|
||||||
|
SYSLOG_RETRIES=5
|
||||||
|
SYSLOG_WAIT=2.0
|
||||||
|
|
||||||
def __init__(self, argv):
|
def __init__(self, argv):
|
||||||
self.args = None
|
self.args = None
|
||||||
self._argv = argv
|
self._argv = argv
|
||||||
|
|
@ -241,6 +244,25 @@ class Cli(contextlib.AbstractContextManager):
|
||||||
stderr=subprocess.STDOUT,
|
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
|
@staticmethod
|
||||||
def _spawn_composer(sockets):
|
def _spawn_composer(sockets):
|
||||||
cmd = [
|
cmd = [
|
||||||
|
|
@ -295,6 +317,9 @@ class Cli(contextlib.AbstractContextManager):
|
||||||
proc_worker = self._spawn_worker()
|
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 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)
|
proc_composer = self._spawn_composer(sockets)
|
||||||
|
|
||||||
if proc_composer:
|
if proc_composer:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue