info_unix.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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.KernelMemoryTCP {
  78. v.Warnings = append(v.Warnings, "WARNING: No kernel memory TCP limit support")
  79. }
  80. if !v.OomKillDisable {
  81. v.Warnings = append(v.Warnings, "WARNING: No oom kill disable support")
  82. }
  83. if !v.CPUCfsQuota {
  84. v.Warnings = append(v.Warnings, "WARNING: No cpu cfs quota support")
  85. }
  86. if !v.CPUCfsPeriod {
  87. v.Warnings = append(v.Warnings, "WARNING: No cpu cfs period support")
  88. }
  89. if !v.CPUShares {
  90. v.Warnings = append(v.Warnings, "WARNING: No cpu shares support")
  91. }
  92. if !v.CPUSet {
  93. v.Warnings = append(v.Warnings, "WARNING: No cpuset support")
  94. }
  95. if !v.IPv4Forwarding {
  96. v.Warnings = append(v.Warnings, "WARNING: IPv4 forwarding is disabled")
  97. }
  98. if !v.BridgeNfIptables {
  99. v.Warnings = append(v.Warnings, "WARNING: bridge-nf-call-iptables is disabled")
  100. }
  101. if !v.BridgeNfIP6tables {
  102. v.Warnings = append(v.Warnings, "WARNING: bridge-nf-call-ip6tables is disabled")
  103. }
  104. }
  105. func fillDriverWarnings(v *types.Info) {
  106. for _, pair := range v.DriverStatus {
  107. if pair[0] == "Data loop file" {
  108. msg := fmt.Sprintf("WARNING: %s: usage of loopback devices is "+
  109. "strongly discouraged for production use.\n "+
  110. "Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.", v.Driver)
  111. v.Warnings = append(v.Warnings, msg)
  112. continue
  113. }
  114. if pair[0] == "Supports d_type" && pair[1] == "false" {
  115. backingFs := getBackingFs(v)
  116. msg := fmt.Sprintf("WARNING: %s: the backing %s filesystem is formatted without d_type support, which leads to incorrect behavior.\n", v.Driver, backingFs)
  117. if backingFs == "xfs" {
  118. msg += " Reformat the filesystem with ftype=1 to enable d_type support.\n"
  119. }
  120. msg += " Running without d_type support will not be supported in future releases."
  121. v.Warnings = append(v.Warnings, msg)
  122. continue
  123. }
  124. }
  125. }
  126. func getBackingFs(v *types.Info) string {
  127. for _, pair := range v.DriverStatus {
  128. if pair[0] == "Backing Filesystem" {
  129. return pair[1]
  130. }
  131. }
  132. return ""
  133. }
  134. // parseInitVersion parses a Tini version string, and extracts the version.
  135. func parseInitVersion(v string) (types.Commit, error) {
  136. version := types.Commit{ID: "", Expected: dockerversion.InitCommitID}
  137. parts := strings.Split(strings.TrimSpace(v), " - ")
  138. if len(parts) >= 2 {
  139. gitParts := strings.Split(parts[1], ".")
  140. if len(gitParts) == 2 && gitParts[0] == "git" {
  141. version.ID = gitParts[1]
  142. version.Expected = dockerversion.InitCommitID[0:len(version.ID)]
  143. }
  144. }
  145. if version.ID == "" && strings.HasPrefix(parts[0], "tini version ") {
  146. version.ID = "v" + strings.TrimPrefix(parts[0], "tini version ")
  147. }
  148. if version.ID == "" {
  149. version.ID = "N/A"
  150. return version, errors.Errorf("unknown output format: %s", v)
  151. }
  152. return version, nil
  153. }