[lxc-devel] [lxd/master] lxd/patches: Force a one-time config re-gen

stgraber on Github lxc-bot at linuxcontainers.org
Fri Jul 6 06:25:39 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 443 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180706/911760b7/attachment.bin>
-------------- next part --------------
From 622a9e908572ca61db5696bcc9290ed1c7023c7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 6 Jul 2018 02:21:52 -0400
Subject: [PATCH] lxd/patches: Force a one-time config re-gen
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is to catch anyone who's upgraded to 3.0 but still has some 2.0
configs around.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/patches.go | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/lxd/patches.go b/lxd/patches.go
index 91a4acb0d..b098e0d40 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -54,6 +54,7 @@ var patches = []patch{
 	{name: "storage_api_ceph_size_remove", run: patchStorageApiCephSizeRemove},
 	{name: "devices_new_naming_scheme", run: patchDevicesNewNamingScheme},
 	{name: "storage_api_permissions", run: patchStorageApiPermissions},
+	{name: "container_config_regen", run: patchContainerConfigRegen},
 }
 
 type patch struct {
@@ -1897,6 +1898,45 @@ func patchStorageApiV1(name string, d *Daemon) error {
 	return nil
 }
 
+func patchContainerConfigRegen(name string, d *Daemon) error {
+	cts, err := d.cluster.ContainersNodeList(db.CTypeRegular)
+	if err != nil {
+		return err
+	}
+
+	for _, ct := range cts {
+		// Load the container from the database.
+		c, err := containerLoadByName(d.State(), ct)
+		if err != nil {
+			return err
+		}
+
+		if !c.IsRunning() {
+			continue
+		}
+
+		lxcCt, ok := c.(*containerLXC)
+		if !ok {
+			continue
+		}
+
+		err = lxcCt.initLXC(true)
+		if err != nil {
+			return err
+		}
+
+		// Generate the LXC config
+		configPath := filepath.Join(lxcCt.LogPath(), "lxc.conf")
+		err = lxcCt.c.SaveConfigFile(configPath)
+		if err != nil {
+			os.Remove(configPath)
+			return err
+		}
+	}
+
+	return nil
+}
+
 func patchStorageApiDirCleanup(name string, d *Daemon) error {
 	fingerprints, err := d.cluster.ImagesGet(false)
 	if err != nil {


More information about the lxc-devel mailing list