docker_windows.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package main
  2. import (
  3. "io"
  4. "path/filepath"
  5. "github.com/Microsoft/go-winio/pkg/etwlogrus"
  6. "github.com/sirupsen/logrus"
  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. configDir, err := getDaemonConfDir(opts.daemonConfig.Root)
  22. if err != nil {
  23. return err
  24. }
  25. opts.configFile = filepath.Join(configDir, "daemon.json")
  26. }
  27. if runAsService {
  28. // If Windows SCM manages the service - no need for PID files
  29. opts.daemonConfig.Pidfile = ""
  30. } else if opts.daemonConfig.Pidfile == "" {
  31. opts.daemonConfig.Pidfile = filepath.Join(opts.daemonConfig.Root, "docker.pid")
  32. }
  33. err = daemonCli.start(opts)
  34. notifyShutdown(err)
  35. return err
  36. }
  37. func initLogging(stdout, _ io.Writer) {
  38. // Maybe there is a historic reason why on non-Windows, stderr is used
  39. // for output. However, on Windows it makes no sense and there is no need.
  40. logrus.SetOutput(stdout)
  41. // Provider ID: {6996f090-c5de-5082-a81e-5841acc3a635}
  42. // Hook isn't closed explicitly, as it will exist until process exit.
  43. // GUID is generated based on name - see Microsoft/go-winio/tools/etw-provider-gen.
  44. if hook, err := etwlogrus.NewHook("Moby"); err == nil {
  45. logrus.AddHook(hook)
  46. }
  47. return
  48. }