From 358f0b481d8620cad4954e3fe418054b9a8c3ecd Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Thu, 4 Nov 2021 20:41:28 +0100 Subject: containers: T2216: bugfix config error on image upgrade As it takes time for the OS to settle while booting up the first time a container is started after image upgrade it will fail big time. To prevent this we try to start the container up to 10 times before we generate a hard error. This makes error-free image upgrade possible again when using containers. --- src/conf_mode/containers.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/conf_mode/containers.py b/src/conf_mode/containers.py index 4511eb7e9..20b84b858 100755 --- a/src/conf_mode/containers.py +++ b/src/conf_mode/containers.py @@ -237,17 +237,6 @@ def apply(container): if os.path.exists(tmp): os.unlink(tmp) - service_name = 'podman.service' - if 'network' in container or 'name' in container: - # Start podman if it's required and not yet running - if not is_systemd_service_active(service_name): - _cmd(f'systemctl start {service_name}') - # Wait for podman to be running - while not is_systemd_service_running(service_name): - sleep(0.250) - else: - _cmd(f'systemctl stop {service_name}') - # Add container if 'name' in container: for name, container_config in container['name'].items(): @@ -318,7 +307,17 @@ def apply(container): if 'address' in container_config['network'][network]: address = container_config['network'][network]['address'] ipparam = f'--ip {address}' - _cmd(f'{container_base_cmd} --net {network} {ipparam} {image}') + + counter = 0 + while True: + if counter >= 10: + break + try: + _cmd(f'{container_base_cmd} --net {network} {ipparam} {image}') + break + except: + counter = counter +1 + sleep(0.5) return None -- cgit v1.2.3