mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
17b1288760
- Moved DefaultInitBinary from daemon/daemon.go to daemon/config/config.go since it's a daemon config and is referred in config package files. - Added condition in GetInitPath to check for any explicitly configured DefaultInitBinary. If not, the default value of DefaultInitBinary is returned. - Changed all references of DefaultInitBinary to refer to the variable from new location. - Added TestCommonUnixGetInitPath to test for the various values of GetInitPath. Fixes #32314 Signed-off-by: Sunny Gogoi <indiasuny000@gmail.com>
92 lines
2.9 KiB
Go
92 lines
2.9 KiB
Go
// +build !windows
|
|
|
|
package daemon
|
|
|
|
import (
|
|
"context"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/docker/docker/api/types"
|
|
daemonconfig "github.com/docker/docker/daemon/config"
|
|
"github.com/docker/docker/dockerversion"
|
|
"github.com/docker/docker/pkg/sysinfo"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// FillPlatformInfo fills the platform related info.
|
|
func (daemon *Daemon) FillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo) {
|
|
v.MemoryLimit = sysInfo.MemoryLimit
|
|
v.SwapLimit = sysInfo.SwapLimit
|
|
v.KernelMemory = sysInfo.KernelMemory
|
|
v.OomKillDisable = sysInfo.OomKillDisable
|
|
v.CPUCfsPeriod = sysInfo.CPUCfsPeriod
|
|
v.CPUCfsQuota = sysInfo.CPUCfsQuota
|
|
v.CPUShares = sysInfo.CPUShares
|
|
v.CPUSet = sysInfo.Cpuset
|
|
v.Runtimes = daemon.configStore.GetAllRuntimes()
|
|
v.DefaultRuntime = daemon.configStore.GetDefaultRuntimeName()
|
|
v.InitBinary = daemon.configStore.GetInitPath()
|
|
|
|
v.ContainerdCommit.Expected = dockerversion.ContainerdCommitID
|
|
if sv, err := daemon.containerd.GetServerVersion(context.Background()); err == nil {
|
|
v.ContainerdCommit.ID = sv.Revision
|
|
} else {
|
|
logrus.Warnf("failed to retrieve containerd version: %v", err)
|
|
v.ContainerdCommit.ID = "N/A"
|
|
}
|
|
|
|
v.RuncCommit.Expected = dockerversion.RuncCommitID
|
|
if rv, err := exec.Command(DefaultRuntimeBinary, "--version").Output(); err == nil {
|
|
parts := strings.Split(strings.TrimSpace(string(rv)), "\n")
|
|
if len(parts) == 3 {
|
|
parts = strings.Split(parts[1], ": ")
|
|
if len(parts) == 2 {
|
|
v.RuncCommit.ID = strings.TrimSpace(parts[1])
|
|
}
|
|
}
|
|
|
|
if v.RuncCommit.ID == "" {
|
|
logrus.Warnf("failed to retrieve %s version: unknown output format: %s", DefaultRuntimeBinary, string(rv))
|
|
v.RuncCommit.ID = "N/A"
|
|
}
|
|
} else {
|
|
logrus.Warnf("failed to retrieve %s version: %v", DefaultRuntimeBinary, err)
|
|
v.RuncCommit.ID = "N/A"
|
|
}
|
|
|
|
if rv, err := exec.Command(daemonconfig.DefaultInitBinary, "--version").Output(); err == nil {
|
|
ver, err := parseInitVersion(string(rv))
|
|
|
|
if err != nil {
|
|
logrus.Warnf("failed to retrieve %s version: %s", daemonconfig.DefaultInitBinary, err)
|
|
}
|
|
v.InitCommit = ver
|
|
} else {
|
|
logrus.Warnf("failed to retrieve %s version: %s", daemonconfig.DefaultInitBinary, err)
|
|
v.InitCommit.ID = "N/A"
|
|
}
|
|
}
|
|
|
|
// parseInitVersion parses a Tini version string, and extracts the version.
|
|
func parseInitVersion(v string) (types.Commit, error) {
|
|
version := types.Commit{ID: "", Expected: dockerversion.InitCommitID}
|
|
parts := strings.Split(strings.TrimSpace(v), " - ")
|
|
|
|
if len(parts) >= 2 {
|
|
gitParts := strings.Split(parts[1], ".")
|
|
if len(gitParts) == 2 && gitParts[0] == "git" {
|
|
version.ID = gitParts[1]
|
|
version.Expected = dockerversion.InitCommitID[0:len(version.ID)]
|
|
}
|
|
}
|
|
if version.ID == "" && strings.HasPrefix(parts[0], "tini version ") {
|
|
version.ID = "v" + strings.TrimPrefix(parts[0], "tini version ")
|
|
}
|
|
if version.ID == "" {
|
|
version.ID = "N/A"
|
|
return version, errors.Errorf("unknown output format: %s", v)
|
|
}
|
|
return version, nil
|
|
}
|