The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7128
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === This fixes #7126.
From cf637d79802f2a63df211faa77121377a330fe8b Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Fri, 3 Apr 2020 08:47:39 +0200 Subject: [PATCH 1/4] lxd/main_activateifneeded: s/container/instance/ This replaces the string "container" with "instance". Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- lxd/main_activateifneeded.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lxd/main_activateifneeded.go b/lxd/main_activateifneeded.go index 99331ead84..f1be7d5f2c 100644 --- a/lxd/main_activateifneeded.go +++ b/lxd/main_activateifneeded.go @@ -33,8 +33,8 @@ func (c *cmdActivateifneeded) Command() *cobra.Command { cmd.Long = `Description: Check if LXD should be started - This command will check if LXD has any auto-started containers, - containers which were running prior to LXD's last shutdown or if it's + This command will check if LXD has any auto-started instances, + instances which were running prior to LXD's last shutdown or if it's configured to listen on the network address. If at least one of those is true, then a connection will be attempted to the @@ -86,13 +86,13 @@ func (c *cmdActivateifneeded) Run(cmd *cobra.Command, args []string) error { return err } - // Load the idmap for unprivileged containers + // Load the idmap for unprivileged instances d.os.IdmapSet, err = idmap.DefaultIdmapSet("", "") if err != nil { return err } - // Look for auto-started or previously started containers + // Look for auto-started or previously started instances path = d.os.GlobalDatabasePath() if !shared.PathExists(path) { path = d.os.LegacyGlobalDatabasePath() @@ -111,19 +111,19 @@ func (c *cmdActivateifneeded) Run(cmd *cobra.Command, args []string) error { return err } - var containers []db.Instance + var instances []db.Instance err = d.cluster.Transaction(func(tx *db.ClusterTx) error { filter := db.InstanceFilter{Type: instancetype.Container} var err error - containers, err = tx.InstanceList(filter) + instances, err = tx.InstanceList(filter) return err }) if err != nil { return err } - for _, container := range containers { - c, err := instance.LoadByProjectAndName(d.State(), container.Project, container.Name) + for _, inst := range instances { + c, err := instance.LoadByProjectAndName(d.State(), inst.Project, inst.Name) if err != nil { sqldb.Close() return err @@ -135,14 +135,14 @@ func (c *cmdActivateifneeded) Run(cmd *cobra.Command, args []string) error { if c.IsRunning() { sqldb.Close() - logger.Debugf("Daemon has running containers, activating...") + logger.Debugf("Daemon has running instances, activating...") _, err := lxd.ConnectLXDUnix("", nil) return err } if lastState == "RUNNING" || lastState == "Running" || shared.IsTrue(autoStart) { sqldb.Close() - logger.Debugf("Daemon has auto-started containers, activating...") + logger.Debugf("Daemon has auto-started instances, activating...") _, err := lxd.ConnectLXDUnix("", nil) return err } From b0239a80518090c65b152174e2192e0997ff175f Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Fri, 3 Apr 2020 08:54:32 +0200 Subject: [PATCH 2/4] lxd/main_activateifneeded: Retrieve all instances Instead of retrieving only containers in default project, this includes all instance types (containers and VMs) in all projects. Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- lxd/main_activateifneeded.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lxd/main_activateifneeded.go b/lxd/main_activateifneeded.go index f1be7d5f2c..cd4618d8b8 100644 --- a/lxd/main_activateifneeded.go +++ b/lxd/main_activateifneeded.go @@ -11,7 +11,6 @@ import ( lxd "github.com/lxc/lxd/client" "github.com/lxc/lxd/lxd/db" "github.com/lxc/lxd/lxd/instance" - "github.com/lxc/lxd/lxd/instance/instancetype" "github.com/lxc/lxd/lxd/node" "github.com/lxc/lxd/shared" "github.com/lxc/lxd/shared/idmap" @@ -113,10 +112,22 @@ func (c *cmdActivateifneeded) Run(cmd *cobra.Command, args []string) error { var instances []db.Instance err = d.cluster.Transaction(func(tx *db.ClusterTx) error { - filter := db.InstanceFilter{Type: instancetype.Container} - var err error - instances, err = tx.InstanceList(filter) - return err + // Get all projects + projects, err := tx.ProjectList(db.ProjectFilter{}) + if err != nil { + return err + } + + // Get instances of all projects + for _, project := range projects { + filter := db.InstanceFilter{Project: project.Name} + instances, err = tx.InstanceList(filter) + if err != nil { + return err + } + } + + return nil }) if err != nil { return err From 00f7c6dc2bf2c308d7fe2c0bfb7cf98541ca13db Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Fri, 3 Apr 2020 09:27:15 +0200 Subject: [PATCH 3/4] lxd/main_activateifneeded: Check for scheduled instance snapshots This checks for scheduled instance snapshots, and activates LXD if enabled. Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- lxd/main_activateifneeded.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lxd/main_activateifneeded.go b/lxd/main_activateifneeded.go index cd4618d8b8..64e4a395f4 100644 --- a/lxd/main_activateifneeded.go +++ b/lxd/main_activateifneeded.go @@ -157,6 +157,16 @@ func (c *cmdActivateifneeded) Run(cmd *cobra.Command, args []string) error { _, err := lxd.ConnectLXDUnix("", nil) return err } + + // Check for scheduled instance snapshots + snapshotsSchedule := config["snapshots.schedule"] + + if snapshotsSchedule != "" { + sqldb.Close() + logger.Debugf("Daemon has scheduled instance snapshots, activating...") + _, err := lxd.ConnectLXDUnix("", nil) + return err + } } sqldb.Close() From 27cf3d63b56c771cba1d29c9850821fff8c6f307 Mon Sep 17 00:00:00 2001 From: Thomas Hipp <thomas.h...@canonical.com> Date: Fri, 3 Apr 2020 09:28:09 +0200 Subject: [PATCH 4/4] lxd/main_activateifneeded: Check for scheduled volume snapshots This checks for scheduled volume snapshots, and activates LXD if enabled. Signed-off-by: Thomas Hipp <thomas.h...@canonical.com> --- lxd/main_activateifneeded.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lxd/main_activateifneeded.go b/lxd/main_activateifneeded.go index 64e4a395f4..b64bde5e14 100644 --- a/lxd/main_activateifneeded.go +++ b/lxd/main_activateifneeded.go @@ -169,6 +169,22 @@ func (c *cmdActivateifneeded) Run(cmd *cobra.Command, args []string) error { } } + // Check for scheduled volume snapshots + volumes, err := d.cluster.StoragePoolVolumesGetAllByType(db.StoragePoolVolumeTypeCustom) + if err != nil { + return err + } + + for _, vol := range volumes { + snapshotsSchedule := vol.Config["snapshots.schedule"] + if snapshotsSchedule != "" { + sqldb.Close() + logger.Debugf("Daemon has scheduled volume snapshots, activating...") + _, err := lxd.ConnectLXDUnix("", nil) + return err + } + } + sqldb.Close() logger.Debugf("No need to start the daemon now") return nil
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel