diff --git a/environment/container/incus/incus.go b/environment/container/incus/incus.go index 9e5bf62a..e3d9a5d6 100644 --- a/environment/container/incus/incus.go +++ b/environment/container/incus/incus.go @@ -141,8 +141,17 @@ func (c *incusRuntime) Start(ctx context.Context) error { a := c.Init(ctx) + if !c.poolImported() { + // pool not yet imported + // stop incus and import pool + a.Add(func() error { + return c.guest.RunQuiet("sudo", "systemctl", "stop", "incus.service") + }) + a.Add(c.importExistingPool) + } + a.Add(func() error { - return c.guest.RunQuiet("sudo", "service", "incus", "start") + return c.guest.RunQuiet("sudo", "systemctl", "start", "incus.service") }) a.Add(func() error { @@ -356,6 +365,13 @@ func (c *incusRuntime) hasExistingPool() bool { return c.guest.RunQuiet("sh", "-c", script) == nil } +func (c *incusRuntime) poolImported() bool { + script := strings.NewReplacer( + "{pool_name}", poolName, + ).Replace("sudo zpool list -H -o name | grep '^{pool_name}$'") + return c.guest.RunQuiet("sh", "-c", script) == nil +} + func (c *incusRuntime) importExistingPool() error { if err := c.guest.RunQuiet("sudo", "zpool", "import", poolName); err != nil { return fmt.Errorf("error importing existing zpool: %w", err)