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