info_unix.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // +build !windows
  2. package daemon
  3. import (
  4. "context"
  5. "os/exec"
  6. "strings"
  7. "github.com/Sirupsen/logrus"
  8. "github.com/docker/docker/api/types"
  9. "github.com/docker/docker/dockerversion"
  10. "github.com/docker/docker/pkg/sysinfo"
  11. )
  12. func (daemon *Daemon) FillPlatformInfo(v *types.InfoBase, sysInfo *sysinfo.SysInfo) {
  13. v.MemoryLimit = sysInfo.MemoryLimit
  14. v.SwapLimit = sysInfo.SwapLimit
  15. v.KernelMemory = sysInfo.KernelMemory
  16. v.OomKillDisable = sysInfo.OomKillDisable
  17. v.CPUCfsPeriod = sysInfo.CPUCfsPeriod
  18. v.CPUCfsQuota = sysInfo.CPUCfsQuota
  19. v.CPUShares = sysInfo.CPUShares
  20. v.CPUSet = sysInfo.Cpuset
  21. v.Runtimes = daemon.configStore.GetAllRuntimes()
  22. v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
  23. v.InitBinary = daemon.configStore.GetInitPath()
  24. v.ContainerdCommit.Expected = dockerversion.ContainerdCommitID
  25. if sv, err := daemon.containerd.GetServerVersion(context.Background()); err == nil {
  26. v.ContainerdCommit.ID = sv.Revision
  27. } else {
  28. logrus.Warnf("failed to retrieve containerd version: %v", err)
  29. v.ContainerdCommit.ID = "N/A"
  30. }
  31. v.RuncCommit.Expected = dockerversion.RuncCommitID
  32. if rv, err := exec.Command(DefaultRuntimeBinary, "--version").Output(); err == nil {
  33. parts := strings.Split(strings.TrimSpace(string(rv)), "\n")
  34. if len(parts) == 3 {
  35. parts = strings.Split(parts[1], ": ")
  36. if len(parts) == 2 {
  37. v.RuncCommit.ID = strings.TrimSpace(parts[1])
  38. }
  39. }
  40. if v.RuncCommit.ID == "" {
  41. logrus.Warnf("failed to retrieve %s version: unknown output format: %s", DefaultRuntimeBinary, string(rv))
  42. v.RuncCommit.ID = "N/A"
  43. }
  44. } else {
  45. logrus.Warnf("failed to retrieve %s version: %v", DefaultRuntimeBinary, err)
  46. v.RuncCommit.ID = "N/A"
  47. }
  48. v.InitCommit.Expected = dockerversion.InitCommitID
  49. if rv, err := exec.Command(DefaultInitBinary, "--version").Output(); err == nil {
  50. parts := strings.Split(strings.TrimSpace(string(rv)), " - ")
  51. if len(parts) == 2 {
  52. if dockerversion.InitCommitID[0] == 'v' {
  53. vs := strings.TrimPrefix(parts[0], "tini version ")
  54. v.InitCommit.ID = "v" + vs
  55. } else {
  56. // Get the sha1
  57. gitParts := strings.Split(parts[1], ".")
  58. if len(gitParts) == 2 && gitParts[0] == "git" {
  59. v.InitCommit.ID = gitParts[1]
  60. v.InitCommit.Expected = dockerversion.InitCommitID[0:len(gitParts[1])]
  61. }
  62. }
  63. }
  64. if v.InitCommit.ID == "" {
  65. logrus.Warnf("failed to retrieve %s version: unknown output format: %s", DefaultInitBinary, string(rv))
  66. v.InitCommit.ID = "N/A"
  67. }
  68. } else {
  69. logrus.Warnf("failed to retrieve %s version", DefaultInitBinary)
  70. v.InitCommit.ID = "N/A"
  71. }
  72. }