docker_windows.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "io"
  4. "path/filepath"
  5. "github.com/Microsoft/go-winio/pkg/etwlogrus"
  6. "github.com/containerd/log"
  7. )
  8. func runDaemon(opts *daemonOptions) error {
  9. daemonCli := NewDaemonCli()
  10. // On Windows, this may be launching as a service or with an option to
  11. // register the service.
  12. stop, runAsService, err := initService(daemonCli)
  13. if err != nil {
  14. return err
  15. }
  16. if stop {
  17. return nil
  18. }
  19. // Windows specific settings as these are not defaulted.
  20. if opts.configFile == "" {
  21. opts.configFile = filepath.Join(opts.daemonConfig.Root, "config", "daemon.json")
  22. }
  23. if runAsService {
  24. // If Windows SCM manages the service - no need for PID files
  25. opts.daemonConfig.Pidfile = ""
  26. } else if opts.daemonConfig.Pidfile == "" {
  27. opts.daemonConfig.Pidfile = filepath.Join(opts.daemonConfig.Root, "docker.pid")
  28. }
  29. err = daemonCli.start(opts)
  30. notifyShutdown(err)
  31. return err
  32. }
  33. func initLogging(stdout, _ io.Writer) {
  34. // Maybe there is a historic reason why on non-Windows, stderr is used
  35. // for output. However, on Windows it makes no sense and there is no need.
  36. log.L.Logger.SetOutput(stdout)
  37. // Provider ID: {6996f090-c5de-5082-a81e-5841acc3a635}
  38. // Hook isn't closed explicitly, as it will exist until process exit.
  39. // GUID is generated based on name - see Microsoft/go-winio/tools/etw-provider-gen.
  40. if hook, err := etwlogrus.NewHook("Moby"); err == nil {
  41. log.L.Logger.AddHook(hook)
  42. }
  43. return
  44. }