info_unix.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // +build !windows
  2. package daemon // import "github.com/docker/docker/daemon"
  3. import (
  4. "context"
  5. "fmt"
  6. "os/exec"
  7. "path/filepath"
  8. "strings"
  9. "github.com/docker/docker/api/types"
  10. "github.com/docker/docker/dockerversion"
  11. "github.com/docker/docker/pkg/sysinfo"
  12. "github.com/pkg/errors"
  13. "github.com/sirupsen/logrus"
  14. )
  15. // fillPlatformInfo fills the platform related info.
  16. func (daemon *Daemon) fillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo) {
  17. v.MemoryLimit = sysInfo.MemoryLimit
  18. v.SwapLimit = sysInfo.SwapLimit
  19. v.KernelMemory = sysInfo.KernelMemory
  20. v.KernelMemoryTCP = sysInfo.KernelMemoryTCP
  21. v.OomKillDisable = sysInfo.OomKillDisable
  22. v.CPUCfsPeriod = sysInfo.CPUCfsPeriod
  23. v.CPUCfsQuota = sysInfo.CPUCfsQuota
  24. v.CPUShares = sysInfo.CPUShares
  25. v.CPUSet = sysInfo.Cpuset
  26. v.PidsLimit = sysInfo.PidsLimit
  27. v.Runtimes = daemon.configStore.GetAllRuntimes()
  28. v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
  29. v.InitBinary = daemon.configStore.GetInitPath()
  30. defaultRuntimeBinary := daemon.configStore.GetRuntime(v.DefaultRuntime).Path
  31. if rv, err := exec.Command(defaultRuntimeBinary, "--version").Output(); err == nil {
  32. if _, commit, err := parseRuncVersion(string(rv)); err != nil {
  33. logrus.Warnf("failed to parse %s version: %v", defaultRuntimeBinary, err)
  34. v.RuncCommit.ID = "N/A"
  35. } else {
  36. v.RuncCommit.ID = commit
  37. }
  38. } else {
  39. logrus.Warnf("failed to retrieve %s version: %v", defaultRuntimeBinary, err)
  40. v.RuncCommit.ID = "N/A"
  41. }
  42. // runc is now shipped as a separate package. Set "expected" to same value
  43. // as "ID" to prevent clients from reporting a version-mismatch
  44. v.RuncCommit.Expected = v.RuncCommit.ID
  45. if rv, err := daemon.containerd.Version(context.Background()); err == nil {
  46. v.ContainerdCommit.ID = rv.Revision
  47. } else {
  48. logrus.Warnf("failed to retrieve containerd version: %v", err)
  49. v.ContainerdCommit.ID = "N/A"
  50. }
  51. // containerd is now shipped as a separate package. Set "expected" to same
  52. // value as "ID" to prevent clients from reporting a version-mismatch
  53. v.ContainerdCommit.Expected = v.ContainerdCommit.ID
  54. // TODO is there still a need to check the expected version for tini?
  55. // if not, we can change this, and just set "Expected" to v.InitCommit.ID
  56. v.InitCommit.Expected = dockerversion.InitCommitID
  57. defaultInitBinary := daemon.configStore.GetInitPath()
  58. if rv, err := exec.Command(defaultInitBinary, "--version").Output(); err == nil {
  59. if _, commit, err := parseInitVersion(string(rv)); err != nil {
  60. logrus.Warnf("failed to parse %s version: %s", defaultInitBinary, err)
  61. v.InitCommit.ID = "N/A"
  62. } else {
  63. v.InitCommit.ID = commit
  64. v.InitCommit.Expected = dockerversion.InitCommitID[0:len(commit)]
  65. }
  66. } else {
  67. logrus.Warnf("failed to retrieve %s version: %s", defaultInitBinary, err)
  68. v.InitCommit.ID = "N/A"
  69. }
  70. if !v.MemoryLimit {
  71. v.Warnings = append(v.Warnings, "WARNING: No memory limit support")
  72. }
  73. if !v.SwapLimit {
  74. v.Warnings = append(v.Warnings, "WARNING: No swap limit support")
  75. }
  76. if !v.KernelMemory {
  77. v.Warnings = append(v.Warnings, "WARNING: No kernel memory limit support")
  78. }
  79. if !v.KernelMemoryTCP {
  80. v.Warnings = append(v.Warnings, "WARNING: No kernel memory TCP limit support")
  81. }
  82. if !v.OomKillDisable {
  83. v.Warnings = append(v.Warnings, "WARNING: No oom kill disable support")
  84. }
  85. if !v.CPUCfsQuota {
  86. v.Warnings = append(v.Warnings, "WARNING: No cpu cfs quota support")
  87. }
  88. if !v.CPUCfsPeriod {
  89. v.Warnings = append(v.Warnings, "WARNING: No cpu cfs period support")
  90. }
  91. if !v.CPUShares {
  92. v.Warnings = append(v.Warnings, "WARNING: No cpu shares support")
  93. }
  94. if !v.CPUSet {
  95. v.Warnings = append(v.Warnings, "WARNING: No cpuset support")
  96. }
  97. if !v.IPv4Forwarding {
  98. v.Warnings = append(v.Warnings, "WARNING: IPv4 forwarding is disabled")
  99. }
  100. if !v.BridgeNfIptables {
  101. v.Warnings = append(v.Warnings, "WARNING: bridge-nf-call-iptables is disabled")
  102. }
  103. if !v.BridgeNfIP6tables {
  104. v.Warnings = append(v.Warnings, "WARNING: bridge-nf-call-ip6tables is disabled")
  105. }
  106. }
  107. func (daemon *Daemon) fillPlatformVersion(v *types.Version) {
  108. if rv, err := daemon.containerd.Version(context.Background()); err == nil {
  109. v.Components = append(v.Components, types.ComponentVersion{
  110. Name: "containerd",
  111. Version: rv.Version,
  112. Details: map[string]string{
  113. "GitCommit": rv.Revision,
  114. },
  115. })
  116. }
  117. defaultRuntime := daemon.configStore.GetDefaultRuntimeName()
  118. defaultRuntimeBinary := daemon.configStore.GetRuntime(defaultRuntime).Path
  119. if rv, err := exec.Command(defaultRuntimeBinary, "--version").Output(); err == nil {
  120. if ver, commit, err := parseRuncVersion(string(rv)); err != nil {
  121. logrus.Warnf("failed to parse %s version: %v", defaultRuntimeBinary, err)
  122. } else {
  123. v.Components = append(v.Components, types.ComponentVersion{
  124. Name: defaultRuntime,
  125. Version: ver,
  126. Details: map[string]string{
  127. "GitCommit": commit,
  128. },
  129. })
  130. }
  131. } else {
  132. logrus.Warnf("failed to retrieve %s version: %v", defaultRuntimeBinary, err)
  133. }
  134. defaultInitBinary := daemon.configStore.GetInitPath()
  135. if rv, err := exec.Command(defaultInitBinary, "--version").Output(); err == nil {
  136. if ver, commit, err := parseInitVersion(string(rv)); err != nil {
  137. logrus.Warnf("failed to parse %s version: %s", defaultInitBinary, err)
  138. } else {
  139. v.Components = append(v.Components, types.ComponentVersion{
  140. Name: filepath.Base(defaultInitBinary),
  141. Version: ver,
  142. Details: map[string]string{
  143. "GitCommit": commit,
  144. },
  145. })
  146. }
  147. } else {
  148. logrus.Warnf("failed to retrieve %s version: %s", defaultInitBinary, err)
  149. }
  150. }
  151. func fillDriverWarnings(v *types.Info) {
  152. for _, pair := range v.DriverStatus {
  153. if pair[0] == "Data loop file" {
  154. msg := fmt.Sprintf("WARNING: %s: usage of loopback devices is "+
  155. "strongly discouraged for production use.\n "+
  156. "Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.", v.Driver)
  157. v.Warnings = append(v.Warnings, msg)
  158. continue
  159. }
  160. if pair[0] == "Supports d_type" && pair[1] == "false" {
  161. backingFs := getBackingFs(v)
  162. msg := fmt.Sprintf("WARNING: %s: the backing %s filesystem is formatted without d_type support, which leads to incorrect behavior.\n", v.Driver, backingFs)
  163. if backingFs == "xfs" {
  164. msg += " Reformat the filesystem with ftype=1 to enable d_type support.\n"
  165. }
  166. msg += " Running without d_type support will not be supported in future releases."
  167. v.Warnings = append(v.Warnings, msg)
  168. continue
  169. }
  170. }
  171. }
  172. func getBackingFs(v *types.Info) string {
  173. for _, pair := range v.DriverStatus {
  174. if pair[0] == "Backing Filesystem" {
  175. return pair[1]
  176. }
  177. }
  178. return ""
  179. }
  180. // parseInitVersion parses a Tini version string, and extracts the "version"
  181. // and "git commit" from the output.
  182. //
  183. // Output example from `docker-init --version`:
  184. //
  185. // tini version 0.18.0 - git.fec3683
  186. func parseInitVersion(v string) (version string, commit string, err error) {
  187. parts := strings.Split(strings.TrimSpace(v), " - ")
  188. if len(parts) >= 2 {
  189. gitParts := strings.Split(parts[1], ".")
  190. if len(gitParts) == 2 && gitParts[0] == "git" {
  191. commit = gitParts[1]
  192. }
  193. }
  194. if strings.HasPrefix(parts[0], "tini version ") {
  195. version = strings.TrimPrefix(parts[0], "tini version ")
  196. }
  197. if version == "" && commit == "" {
  198. err = errors.Errorf("unknown output format: %s", v)
  199. }
  200. return version, commit, err
  201. }
  202. // parseRuncVersion parses the output of `runc --version` and extracts the
  203. // "version" and "git commit" from the output.
  204. //
  205. // Output example from `runc --version`:
  206. //
  207. // runc version 1.0.0-rc5+dev
  208. // commit: 69663f0bd4b60df09991c08812a60108003fa340
  209. // spec: 1.0.0
  210. func parseRuncVersion(v string) (version string, commit string, err error) {
  211. lines := strings.Split(strings.TrimSpace(v), "\n")
  212. for _, line := range lines {
  213. if strings.HasPrefix(line, "runc version") {
  214. version = strings.TrimSpace(strings.TrimPrefix(line, "runc version"))
  215. continue
  216. }
  217. if strings.HasPrefix(line, "commit:") {
  218. commit = strings.TrimSpace(strings.TrimPrefix(line, "commit:"))
  219. continue
  220. }
  221. }
  222. if version == "" && commit == "" {
  223. err = errors.Errorf("unknown output format: %s", v)
  224. }
  225. return version, commit, err
  226. }
  227. // Rootless returns true if daemon is running in rootless mode
  228. func (daemon *Daemon) Rootless() bool {
  229. return daemon.configStore.Rootless
  230. }