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 <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2024-02-21 15:06:21 +01:00
parent 44a3bba2a2
commit 52694ebe16
2 changed files with 8 additions and 6 deletions

View File

@@ -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
}

View File

@@ -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