From 8c598b10053f49f7655d6a8e58f58516c11775fb Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 17 Sep 2024 12:46:13 +0200 Subject: [PATCH] cmd/dockerd: runDaemon: extract platform-agnostic code Signed-off-by: Sebastiaan van Stijn --- cmd/dockerd/docker.go | 13 ++++++++++++- cmd/dockerd/docker_unix.go | 13 +------------ cmd/dockerd/docker_windows.go | 14 +------------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/cmd/dockerd/docker.go b/cmd/dockerd/docker.go index 9f78745b9b689..42c0677ab40d6 100644 --- a/cmd/dockerd/docker.go +++ b/cmd/dockerd/docker.go @@ -35,7 +35,18 @@ func newDaemonCommand() (*cobra.Command, error) { Args: NoArgs, RunE: func(cmd *cobra.Command, args []string) error { opts.flags = cmd.Flags() - return runDaemon(cmd.Context(), opts) + + cli, err := newDaemonCLI(opts) + if err != nil { + return err + } + if opts.Validate { + // If config wasn't OK we wouldn't have made it this far. + _, _ = fmt.Fprintln(os.Stderr, "configuration OK") + return nil + } + + return runDaemon(cmd.Context(), cli) }, DisableFlagsInUseLine: true, Version: fmt.Sprintf("%s, build %s", dockerversion.Version, dockerversion.GitCommit), diff --git a/cmd/dockerd/docker_unix.go b/cmd/dockerd/docker_unix.go index b24fb7dfcb4e3..26b68468503ae 100644 --- a/cmd/dockerd/docker_unix.go +++ b/cmd/dockerd/docker_unix.go @@ -4,23 +4,12 @@ package main import ( "context" - "fmt" "io" - "os" "github.com/containerd/log" ) -func runDaemon(ctx context.Context, opts *daemonOptions) error { - cli, err := newDaemonCLI(opts) - if err != nil { - return err - } - if opts.Validate { - // If config wasn't OK we wouldn't have made it this far. - _, _ = fmt.Fprintln(os.Stderr, "configuration OK") - return nil - } +func runDaemon(ctx context.Context, cli *daemonCLI) error { return cli.start(ctx) } diff --git a/cmd/dockerd/docker_windows.go b/cmd/dockerd/docker_windows.go index 00ae098f3d422..d133bb88ca5f2 100644 --- a/cmd/dockerd/docker_windows.go +++ b/cmd/dockerd/docker_windows.go @@ -2,25 +2,13 @@ package main import ( "context" - "fmt" "io" - "os" "github.com/Microsoft/go-winio/pkg/etwlogrus" "github.com/containerd/log" ) -func runDaemon(ctx context.Context, opts *daemonOptions) error { - cli, err := newDaemonCLI(opts) - if err != nil { - return err - } - if opts.Validate { - // If config wasn't OK we wouldn't have made it this far. - _, _ = fmt.Fprintln(os.Stderr, "configuration OK") - return nil - } - +func runDaemon(ctx context.Context, cli *daemonCLI) error { // On Windows, this may be launching as a service or with an option to // register the service. stop, runAsService, err := initService(cli)