1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/cmd/dockerd/docker_windows.go
Sebastiaan van Stijn 37a241768d
cmd/dockerd: fix some minor issues in Windows implementation
- properly use filepath.Join() for Windows paths
- use getDaemonConfDir() to get the path for storing daemon.json
- return error instead of logrus.Fatal(). The logrus.Fatal() was a left-over
  from when Cobra was not used, and appears to have been missed in commit
  fb83394714, which did the conversion to Cobra.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-08-09 22:50:41 +02:00

57 lines
1.5 KiB
Go

package main
import (
"io"
"path/filepath"
"github.com/Microsoft/go-winio/pkg/etwlogrus"
"github.com/sirupsen/logrus"
)
func runDaemon(opts *daemonOptions) error {
daemonCli := NewDaemonCli()
// On Windows, this may be launching as a service or with an option to
// register the service.
stop, runAsService, err := initService(daemonCli)
if err != nil {
return err
}
if stop {
return nil
}
// Windows specific settings as these are not defaulted.
if opts.configFile == "" {
configDir, err := getDaemonConfDir(opts.daemonConfig.Root)
if err != nil {
return err
}
opts.configFile = filepath.Join(configDir, "daemon.json")
}
if runAsService {
// If Windows SCM manages the service - no need for PID files
opts.daemonConfig.Pidfile = ""
} else if opts.daemonConfig.Pidfile == "" {
opts.daemonConfig.Pidfile = filepath.Join(opts.daemonConfig.Root, "docker.pid")
}
err = daemonCli.start(opts)
notifyShutdown(err)
return err
}
func initLogging(stdout, _ io.Writer) {
// Maybe there is a historic reason why on non-Windows, stderr is used
// for output. However, on Windows it makes no sense and there is no need.
logrus.SetOutput(stdout)
// Provider ID: {6996f090-c5de-5082-a81e-5841acc3a635}
// Hook isn't closed explicitly, as it will exist until process exit.
// GUID is generated based on name - see Microsoft/go-winio/tools/etw-provider-gen.
if hook, err := etwlogrus.NewHook("Moby"); err == nil {
logrus.AddHook(hook)
}
return
}