Skip to content

Commit

Permalink
Fix: Explicitly handle an unknown container state upon start. (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
csadorf authored Mar 1, 2022
1 parent fae8112 commit 2155f85
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions aiidalab_launch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ async def _async_start(
InstanceStatus = instance.AiidaLabInstanceStatus # local alias for brevity

status = await instance.status()

# Container needs to be started.
if status in (
InstanceStatus.DOWN,
InstanceStatus.CREATED,
Expand All @@ -350,6 +352,8 @@ async def _async_start(
instance.recreate()
with spinner("Starting container..."):
instance.start()

# Container is already up.
elif status is InstanceStatus.UP and restart:
with spinner("Restarting container..."):
if configuration_changed:
Expand All @@ -370,9 +374,17 @@ async def _async_start(
"Container was already running, use --restart to restart it.",
err=True,
)

# Container is already starting.
elif status is InstanceStatus.STARTING:
click.echo("Container is already starting up...", err=True)

# Unknown condition.
else:
raise RuntimeError(
"Container already exists, but failed to determine status."
)

except docker.errors.APIError as error:
LOGGER.debug(f"Error during startup: {error}")
if instance.profile.port and "port is already allocated" in str(error):
Expand Down

0 comments on commit 2155f85

Please sign in to comment.