Skip to content

Commit

Permalink
microcloud/service/service/handler: Restart LXD on MicroCloud start t…
Browse files Browse the repository at this point in the history
…o refresh symlinks

Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
  • Loading branch information
masnax committed Jul 12, 2023
1 parent 2d49df4 commit a305f26
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion microcloud/service/service_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

lxd "github.com/canonical/lxd/client"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/microcluster/state"
"github.com/hashicorp/mdns"

Expand Down Expand Up @@ -87,7 +88,18 @@ func (s *Handler) Start(state *state.State) error {
// Attempt to wake up LXD so it can generate certificates already.
d, err := lxd.ConnectLXDUnix("/var/snap/lxd/common/lxd/unix.socket", nil)
if err == nil {
_, _, _ = d.GetServer()
_, _, err = d.RawQuery("PUT", fmt.Sprint("/internal/shutdown"), nil, "")
if err != nil {
logger.Warn("Failed to send shutdown signal to LXD")
}

// A sleep might be necessary here on slower machines?
_, _, err := d.GetServer()
if err != nil {
logger.Errorf("Failed to initialize LXD server", err)
}
} else {
logger.Warn("Failed to connect to LXD unix socket. LXD will not restart")
}

s.AuthSecret, err = shared.RandomCryptoString()
Expand Down

0 comments on commit a305f26

Please sign in to comment.