info_unix.go 5.4 KB

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