docker_windows.go 1.4 KB

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