From 52694ebe165d8d55f3fe4f207e9effa25a9764e8 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 21 Feb 2024 15:06:21 +0100 Subject: [PATCH] cmd/dockerd: windows: move setting PIDFile location to setPlatformOptions Unlike Linux, which uses fixed locations as default, the Windows daemon uses paths relative to the data-root as defaults for storing both the PIDFile, and the daemon configuration file (daemon.json). The data-root is configurable both through command-line options (`--data-root`), and through the daemon configuration file (daemon.json). This patch moves Windows- specific config handling to config-related code. Signed-off-by: Sebastiaan van Stijn --- cmd/dockerd/daemon_windows.go | 9 ++++++++- cmd/dockerd/docker_windows.go | 5 ----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/dockerd/daemon_windows.go b/cmd/dockerd/daemon_windows.go index a04c42eac2..8c1ff01319 100644 --- a/cmd/dockerd/daemon_windows.go +++ b/cmd/dockerd/daemon_windows.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "path/filepath" "time" "github.com/containerd/log" @@ -23,8 +24,14 @@ func getDefaultDaemonConfigFile() string { } // setPlatformOptions applies platform-specific CLI configuration options. -// There is none on windows, so this is a no-op. func setPlatformOptions(conf *config.Config) error { + if conf.Pidfile == "" { + // On Windows, the pid-file location is relative to the daemon's data-root, + // which is configurable, so we cannot use a fixed default location. + // Instead, we set the location here, after we parsed command-line flags + // and loaded the configuration file (if any). + conf.Pidfile = filepath.Join(conf.Root, "docker.pid") + } return nil } diff --git a/cmd/dockerd/docker_windows.go b/cmd/dockerd/docker_windows.go index fb37dec74c..158490c3f5 100644 --- a/cmd/dockerd/docker_windows.go +++ b/cmd/dockerd/docker_windows.go @@ -4,17 +4,12 @@ import ( "fmt" "io" "os" - "path/filepath" "github.com/Microsoft/go-winio/pkg/etwlogrus" "github.com/containerd/log" ) func runDaemon(opts *daemonOptions) error { - // Windows specific settings as these are not defaulted. - if opts.daemonConfig.Pidfile == "" { - opts.daemonConfig.Pidfile = filepath.Join(opts.daemonConfig.Root, "docker.pid") - } cli, err := NewDaemonCli(opts) if err != nil { return err