[lxc-devel] [lxd/master] Fix containers starting during migration

stgraber on Github lxc-bot at linuxcontainers.org
Tue May 14 21:24:28 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190514/6e4257e0/attachment.bin>
-------------- next part --------------
From 694cccd6cd247f86436aa30c728563359d5a1d39 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 14 May 2019 23:23:43 +0200
Subject: [PATCH 1/2] lxd: Don't start on migration

---
 lxd/containers_post.go | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/lxd/containers_post.go b/lxd/containers_post.go
index fdfa2b972a..ef9e2a732e 100644
--- a/lxd/containers_post.go
+++ b/lxd/containers_post.go
@@ -405,12 +405,6 @@ func createFromMigration(d *Daemon, project string, req *api.ContainersPost) Res
 			return err
 		}
 
-		if !migrationArgs.Live {
-			if req.Config["volatile.last_state.power"] == "RUNNING" {
-				return c.Start(false)
-			}
-		}
-
 		return nil
 	}
 

From 1025a567ef735db1e83bc4a670ac5958a9858016 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 14 May 2019 23:24:02 +0200
Subject: [PATCH 2/2] lxc/move: Start container when appropriate
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/copy.go | 28 +++++++++++++++++++++++++---
 lxc/move.go |  2 +-
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/lxc/copy.go b/lxc/copy.go
index 9e08d9897b..5e1b5c05c6 100644
--- a/lxc/copy.go
+++ b/lxc/copy.go
@@ -59,7 +59,7 @@ func (c *cmdCopy) Command() *cobra.Command {
 
 func (c *cmdCopy) copyContainer(conf *config.Config, sourceResource string,
 	destResource string, keepVolatile bool, ephemeral int, stateful bool,
-	containerOnly bool, mode string, pool string) error {
+	containerOnly bool, mode string, pool string, move bool) error {
 	// Parse the source
 	sourceRemote, sourceName, err := conf.ParseRemote(sourceResource)
 	if err != nil {
@@ -146,6 +146,7 @@ func (c *cmdCopy) copyContainer(conf *config.Config, sourceResource string,
 
 	var op lxd.RemoteOperation
 	var writable api.ContainerPut
+	var start bool
 
 	if shared.IsSnapshot(sourceName) {
 		if containerOnly {
@@ -258,6 +259,10 @@ func (c *cmdCopy) copyContainer(conf *config.Config, sourceResource string,
 			return err
 		}
 
+		if entry.StatusCode == api.Running && move && !stateful {
+			start = true
+		}
+
 		// Allow adding additional profiles
 		if c.flagProfile != nil {
 			entry.Profiles = append(entry.Profiles, c.flagProfile...)
@@ -405,6 +410,23 @@ func (c *cmdCopy) copyContainer(conf *config.Config, sourceResource string,
 		fmt.Printf(i18n.G("Container name is: %s")+"\n", fields[len(fields)-1])
 	}
 
+	// Start the container if needed
+	if start {
+		req := api.ContainerStatePut{
+			Action: string(shared.Start),
+		}
+
+		op, err := dest.UpdateContainerState(destName, req, "")
+		if err != nil {
+			return err
+		}
+
+		err = op.Wait()
+		if err != nil {
+			return err
+		}
+	}
+
 	return nil
 }
 
@@ -435,10 +457,10 @@ func (c *cmdCopy) Run(cmd *cobra.Command, args []string) error {
 	// If not target name is specified, one will be chosed by the server
 	if len(args) < 2 {
 		return c.copyContainer(conf, args[0], "", keepVolatile, ephem,
-			stateful, c.flagContainerOnly, mode, c.flagStorage)
+			stateful, c.flagContainerOnly, mode, c.flagStorage, false)
 	}
 
 	// Normal copy with a pre-determined name
 	return c.copyContainer(conf, args[0], args[1], keepVolatile, ephem,
-		stateful, c.flagContainerOnly, mode, c.flagStorage)
+		stateful, c.flagContainerOnly, mode, c.flagStorage, false)
 }
diff --git a/lxc/move.go b/lxc/move.go
index e7bbbea4ef..5985b38932 100644
--- a/lxc/move.go
+++ b/lxc/move.go
@@ -172,7 +172,7 @@ func (c *cmdMove) Run(cmd *cobra.Command, args []string) error {
 
 	// A move is just a copy followed by a delete; however, we want to
 	// keep the volatile entries around since we are moving the container.
-	err = cpy.copyContainer(conf, sourceResource, destResource, true, -1, stateful, c.flagContainerOnly, mode, c.flagStorage)
+	err = cpy.copyContainer(conf, sourceResource, destResource, true, -1, stateful, c.flagContainerOnly, mode, c.flagStorage, true)
 	if err != nil {
 		return err
 	}


More information about the lxc-devel mailing list