info_unix.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // +build !windows
  2. package daemon // import "github.com/docker/docker/daemon"
  3. import (
  4. "context"
  5. "fmt"
  6. "os/exec"
  7. "strings"
  8. "github.com/docker/docker/api/types"
  9. "github.com/docker/docker/dockerversion"
  10. "github.com/docker/docker/pkg/sysinfo"
  11. "github.com/pkg/errors"
  12. "github.com/sirupsen/logrus"
  13. )
  14. // fillPlatformInfo fills the platform related info.
  15. func (daemon *Daemon) fillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo) {
  16. v.MemoryLimit = sysInfo.MemoryLimit
  17. v.SwapLimit = sysInfo.SwapLimit
  18. v.KernelMemory = sysInfo.KernelMemory
  19. v.KernelMemoryTCP = sysInfo.KernelMemoryTCP
  20. v.OomKillDisable = sysInfo.OomKillDisable
  21. v.CPUCfsPeriod = sysInfo.CPUCfsPeriod
  22. v.CPUCfsQuota = sysInfo.CPUCfsQuota
  23. v.CPUShares = sysInfo.CPUShares
  24. v.CPUSet = sysInfo.Cpuset
  25. v.Runtimes = daemon.configStore.GetAllRuntimes()
  26. v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
  27. v.InitBinary = daemon.configStore.GetInitPath()
  28. defaultRuntimeBinary := daemon.configStore.GetRuntime(v.DefaultRuntime).Path
  29. if rv, err := exec.Command(defaultRuntimeBinary, "--version").Output(); err == nil {
  30. parts := strings.Split(strings.TrimSpace(string(rv)), "\n")
  31. if len(parts) == 3 {
  32. parts = strings.Split(parts[1], ": ")
  33. if len(parts) == 2 {
  34. v.RuncCommit.ID = strings.TrimSpace(parts[1])
  35. }
  36. }
  37. if v.RuncCommit.ID == "" {
  38. logrus.Warnf("failed to retrieve %s version: unknown output format: %s", defaultRuntimeBinary, string(rv))
  39. v.RuncCommit.ID = "N/A"
  40. }
  41. } else {
  42. logrus.Warnf("failed to retrieve %s version: %v", defaultRuntimeBinary, err)
  43. v.RuncCommit.ID = "N/A"
  44. }
  45. // runc is now shipped as a separate package. Set "expected" to same value
  46. // as "ID" to prevent clients from reporting a version-mismatch
  47. v.RuncCommit.Expected = v.RuncCommit.ID
  48. if rv, err := daemon.containerd.Version(context.Background()); err == nil {
  49. v.ContainerdCommit.ID = rv.Revision
  50. } else {
  51. logrus.Warnf("failed to retrieve containerd version: %v", err)
  52. v.ContainerdCommit.ID = "N/A"
  53. }
  54. // containerd is now shipped as a separate package. Set "expected" to same
  55. // value as "ID" to prevent clients from reporting a version-mismatch
  56. v.ContainerdCommit.Expected = v.ContainerdCommit.ID
  57. defaultInitBinary := daemon.configStore.GetInitPath()
  58. if rv, err := exec.Command(defaultInitBinary, "--version").Output(); err == nil {
  59. ver, err := parseInitVersion(string(rv))
  60. if err != nil {
  61. logrus.Warnf("failed to retrieve %s version: %s", defaultInitBinary, err)
  62. }
  63. v.InitCommit = ver
  64. } else {
  65. logrus.Warnf("failed to retrieve %s version: %s", defaultInitBinary, err)
  66. v.InitCommit.ID = "N/A"
  67. }
  68. if !v.MemoryLimit {
  69. v.Warnings = append(v.Warnings, "WARNING: No memory limit support")
  70. }
  71. if !v.SwapLimit {
  72. v.Warnings = append(v.Warnings, "WARNING: No swap limit support")
  73. }
  74. if !v.KernelMemory {
  75. v.Warnings = append(v.Warnings, "WARNING: No kernel memory limit support")
  76. }
  77. if !v.OomKillDisable {
  78. v.Warnings = append(v.Warnings, "WARNING: No oom kill disable support")
  79. }
  80. if !v.CPUCfsQuota {
  81. v.Warnings = append(v.Warnings, "WARNING: No cpu cfs quota support")
  82. }
  83. if !v.CPUCfsPeriod {
  84. v.Warnings = append(v.Warnings, "WARNING: No cpu cfs period support")
  85. }
  86. if !v.CPUShares {
  87. v.Warnings = append(v.Warnings, "WARNING: No cpu shares support")
  88. }
  89. if !v.CPUSet {
  90. v.Warnings = append(v.Warnings, "WARNING: No cpuset support")
  91. }
  92. if !v.IPv4Forwarding {
  93. v.Warnings = append(v.Warnings, "WARNING: IPv4 forwarding is disabled")
  94. }
  95. if !v.BridgeNfIptables {
  96. v.Warnings = append(v.Warnings, "WARNING: bridge-nf-call-iptables is disabled")
  97. }
  98. if !v.BridgeNfIP6tables {
  99. v.Warnings = append(v.Warnings, "WARNING: bridge-nf-call-ip6tables is disabled")
  100. }
  101. }
  102. func fillDriverWarnings(v *types.Info) {
  103. for _, pair := range v.DriverStatus {
  104. if pair[0] == "Data loop file" {
  105. msg := fmt.Sprintf("WARNING: %s: usage of loopback devices is "+
  106. "strongly discouraged for production use.\n "+
  107. "Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.", v.Driver)
  108. v.Warnings = append(v.Warnings, msg)
  109. continue
  110. }
  111. if pair[0] == "Supports d_type" && pair[1] == "false" {
  112. backingFs := getBackingFs(v)
  113. msg := fmt.Sprintf("WARNING: %s: the backing %s filesystem is formatted without d_type support, which leads to incorrect behavior.\n", v.Driver, backingFs)
  114. if backingFs == "xfs" {
  115. msg += " Reformat the filesystem with ftype=1 to enable d_type support.\n"
  116. }
  117. msg += " Running without d_type support will not be supported in future releases."
  118. v.Warnings = append(v.Warnings, msg)
  119. continue
  120. }
  121. }
  122. }
  123. func getBackingFs(v *types.Info) string {
  124. for _, pair := range v.DriverStatus {
  125. if pair[0] == "Backing Filesystem" {
  126. return pair[1]
  127. }
  128. }
  129. return ""
  130. }
  131. // parseInitVersion parses a Tini version string, and extracts the version.
  132. func parseInitVersion(v string) (types.Commit, error) {
  133. version := types.Commit{ID: "", Expected: dockerversion.InitCommitID}
  134. parts := strings.Split(strings.TrimSpace(v), " - ")
  135. if len(parts) >= 2 {
  136. gitParts := strings.Split(parts[1], ".")
  137. if len(gitParts) == 2 && gitParts[0] == "git" {
  138. version.ID = gitParts[1]
  139. version.Expected = dockerversion.InitCommitID[0:len(version.ID)]
  140. }
  141. }
  142. if version.ID == "" && strings.HasPrefix(parts[0], "tini version ") {
  143. version.ID = "v" + strings.TrimPrefix(parts[0], "tini version ")
  144. }
  145. if version.ID == "" {
  146. version.ID = "N/A"
  147. return version, errors.Errorf("unknown output format: %s", v)
  148. }
  149. return version, nil
  150. }