2016-11-11 11:02:23 -05:00
|
|
|
// +build !windows
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2016-11-11 11:02:23 -05:00
|
|
|
|
|
|
|
import (
|
2017-11-02 20:21:18 -04:00
|
|
|
"context"
|
2016-11-11 11:02:23 -05:00
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/dockerversion"
|
|
|
|
"github.com/docker/docker/pkg/sysinfo"
|
2017-03-29 07:44:14 -04:00
|
|
|
"github.com/pkg/errors"
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-11-11 11:02:23 -05:00
|
|
|
)
|
|
|
|
|
2016-11-18 18:57:11 -05:00
|
|
|
// FillPlatformInfo fills the platform related info.
|
2016-11-16 16:30:29 -05:00
|
|
|
func (daemon *Daemon) FillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo) {
|
2016-11-11 11:02:23 -05:00
|
|
|
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.RuncCommit.Expected = dockerversion.RuncCommitID
|
2017-09-22 09:52:41 -04:00
|
|
|
defaultRuntimeBinary := daemon.configStore.GetRuntime(v.DefaultRuntime).Path
|
2017-06-09 21:07:21 -04:00
|
|
|
if rv, err := exec.Command(defaultRuntimeBinary, "--version").Output(); err == nil {
|
2016-11-11 11:02:23 -05:00
|
|
|
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 == "" {
|
2017-06-06 13:36:24 -04:00
|
|
|
logrus.Warnf("failed to retrieve %s version: unknown output format: %s", defaultRuntimeBinary, string(rv))
|
2016-11-11 11:02:23 -05:00
|
|
|
v.RuncCommit.ID = "N/A"
|
|
|
|
}
|
|
|
|
} else {
|
2017-06-06 13:36:24 -04:00
|
|
|
logrus.Warnf("failed to retrieve %s version: %v", defaultRuntimeBinary, err)
|
2016-11-11 11:02:23 -05:00
|
|
|
v.RuncCommit.ID = "N/A"
|
|
|
|
}
|
|
|
|
|
2017-09-22 09:52:41 -04:00
|
|
|
v.ContainerdCommit.Expected = dockerversion.ContainerdCommitID
|
2017-11-02 20:21:18 -04:00
|
|
|
if rv, err := daemon.containerd.Version(context.Background()); err == nil {
|
|
|
|
v.ContainerdCommit.ID = rv.Revision
|
2017-09-22 09:52:41 -04:00
|
|
|
} else {
|
2017-11-02 20:21:18 -04:00
|
|
|
logrus.Warnf("failed to retrieve containerd version: %v", err)
|
2017-09-22 09:52:41 -04:00
|
|
|
v.ContainerdCommit.ID = "N/A"
|
|
|
|
}
|
|
|
|
|
2017-06-06 13:36:24 -04:00
|
|
|
defaultInitBinary := daemon.configStore.GetInitPath()
|
|
|
|
if rv, err := exec.Command(defaultInitBinary, "--version").Output(); err == nil {
|
2017-03-29 07:44:14 -04:00
|
|
|
ver, err := parseInitVersion(string(rv))
|
2017-03-28 18:18:39 -04:00
|
|
|
|
2017-03-29 07:44:14 -04:00
|
|
|
if err != nil {
|
2017-06-06 13:36:24 -04:00
|
|
|
logrus.Warnf("failed to retrieve %s version: %s", defaultInitBinary, err)
|
2016-11-11 11:02:23 -05:00
|
|
|
}
|
2017-03-29 07:44:14 -04:00
|
|
|
v.InitCommit = ver
|
2016-11-11 11:02:23 -05:00
|
|
|
} else {
|
2017-06-06 13:36:24 -04:00
|
|
|
logrus.Warnf("failed to retrieve %s version: %s", defaultInitBinary, err)
|
2016-11-11 11:02:23 -05:00
|
|
|
v.InitCommit.ID = "N/A"
|
|
|
|
}
|
|
|
|
}
|
2017-03-29 07:44:14 -04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|