remote_daemon_options.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package supervisor // import "github.com/docker/docker/libcontainerd/supervisor"
  2. import (
  3. "os"
  4. "path/filepath"
  5. "github.com/pkg/errors"
  6. )
  7. import (
  8. "github.com/containerd/log"
  9. )
  10. // WithLogLevel defines which log level to start containerd with.
  11. func WithLogLevel(lvl string) DaemonOpt {
  12. return func(r *remote) error {
  13. if lvl == "info" {
  14. // both dockerd and containerd default log-level is "info",
  15. // so don't pass the default.
  16. lvl = ""
  17. }
  18. r.logLevel = lvl
  19. return nil
  20. }
  21. }
  22. // WithLogFormat defines the containerd log format.
  23. // This only makes sense if WithStartDaemon() was set to true.
  24. func WithLogFormat(format log.OutputFormat) DaemonOpt {
  25. return func(r *remote) error {
  26. r.Debug.Format = string(format)
  27. return nil
  28. }
  29. }
  30. // WithCRIDisabled disables the CRI plugin.
  31. func WithCRIDisabled() DaemonOpt {
  32. return func(r *remote) error {
  33. r.DisabledPlugins = append(r.DisabledPlugins, "io.containerd.grpc.v1.cri")
  34. return nil
  35. }
  36. }
  37. // WithDetectLocalBinary checks if a containerd binary is present in the same
  38. // directory as the dockerd binary, and overrides the path of the containerd
  39. // binary to start if found. If no binary is found, no changes are made.
  40. func WithDetectLocalBinary() DaemonOpt {
  41. return func(r *remote) error {
  42. dockerdPath, err := os.Executable()
  43. if err != nil {
  44. return errors.Wrap(err, "looking up binary path")
  45. }
  46. localBinary := filepath.Join(filepath.Dir(dockerdPath), binaryName)
  47. fi, err := os.Stat(localBinary)
  48. if err != nil {
  49. if !errors.Is(err, os.ErrNotExist) {
  50. return err
  51. }
  52. return nil
  53. }
  54. if fi.IsDir() {
  55. return errors.Errorf("local containerd path found (%s), but is a directory", localBinary)
  56. }
  57. r.daemonPath = localBinary
  58. r.logger.WithError(err).WithField("binary", localBinary).Debug("failed to look up local containerd binary; using default binary")
  59. return nil
  60. }
  61. }