Skip to content

Commit

Permalink
EXPERIMENTAL feat: keep lxc instances running
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau committed May 14, 2024
1 parent 0f0f35d commit 5c15b65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
28 changes: 15 additions & 13 deletions craft_providers/lxd/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,23 +394,25 @@ def _launch_existing_instance(

if instance.is_running():
logger.debug("Instance exists and is running.")
logger.debug("Cancelling any pending shutdown.")
instance.execute_run(["shutdown", "-c"], capture_output=True)
else:
logger.debug("Instance exists and is not running. Starting instance.")
instance.start()

try:
base_configuration.warmup(executor=instance)
except bases.BaseCompatibilityError as error:
# delete the instance so a new instance can be created
if auto_clean:
logger.debug(
"Cleaning incompatible instance %r (reason: %s).",
instance.instance_name,
error.reason,
)
instance.delete()
return False
raise
try:
base_configuration.warmup(executor=instance)
except bases.BaseCompatibilityError as error:
# delete the instance so a new instance can be created
if auto_clean:
logger.debug(
"Cleaning incompatible instance %r (reason: %s).",
instance.instance_name,
error.reason,
)
instance.delete()
return False
raise

return True

Expand Down
9 changes: 7 additions & 2 deletions craft_providers/lxd/lxd_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,13 @@ def stop(self) -> None:
:raises LXDError: on unexpected error.
"""
self.lxc.stop(
instance_name=self.instance_name, project=self.project, remote=self.remote
# self.lxc.stop(
# instance_name=self.instance_name, project=self.project, remote=self.remote
# )
logger.debug("Leaving instance running for 15 minutes in case it's needed again.")
self.execute_run(
["shutdown", "+15"], # TODO: make the time configurable.
capture_output=True,
)

def supports_mount(self) -> bool:
Expand Down

0 comments on commit 5c15b65

Please sign in to comment.