Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daemon: Allow shutdown during startup #15025

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lxd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ func (d *Daemon) init() error {
options = append(options, driver.WithTracing(dqliteClient.LogDebug))
}

d.db.Cluster, err = db.OpenCluster(context.Background(), "db.bin", store, localClusterAddress, dir, d.config.DqliteSetupTimeout, nil, options...)
d.db.Cluster, err = db.OpenCluster(d.shutdownCtx, "db.bin", store, localClusterAddress, dir, d.config.DqliteSetupTimeout, nil, options...)
if err == nil {
logger.Info("Initialized global database")
break
Expand Down
12 changes: 7 additions & 5 deletions lxd/main_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
flagGroup string
}

func (c *cmdDaemon) Command() *cobra.Command {

Check failure on line 24 in lxd/main_daemon.go

View workflow job for this annotation

GitHub Actions / Code

exported: exported method cmdDaemon.Command should have comment or be unexported (revive)
cmd := &cobra.Command{}
cmd.Use = "lxd"
cmd.Short = "The LXD container manager (daemon)"
Expand All @@ -40,7 +40,7 @@
return cmd
}

func (c *cmdDaemon) Run(cmd *cobra.Command, args []string) error {

Check failure on line 43 in lxd/main_daemon.go

View workflow job for this annotation

GitHub Actions / Code

exported: exported method cmdDaemon.Run should have comment or be unexported (revive)
if len(args) > 1 || (len(args) == 1 && args[0] != "daemon" && args[0] != "") {
return fmt.Errorf("unknown command \"%s\" for \"%s\"", args[0], cmd.CommandPath())
}
Expand Down Expand Up @@ -74,10 +74,12 @@
chIgnore := make(chan os.Signal, 1)
signal.Notify(chIgnore, unix.SIGHUP)

err := d.Init()
if err != nil {
return err
}
go func() {
err := d.Init()
if err != nil {
d.shutdownDoneCh <- err
}
}()

for {
select {
Expand All @@ -91,7 +93,7 @@
}()
}

case err = <-d.shutdownDoneCh:
case err := <-d.shutdownDoneCh:
return err
}
}
Expand Down
Loading