From 4949e070fbcac1ef9fbeabe59e3f39cdb830e5fd Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 30 Jul 2014 06:51:43 +0000 Subject: [PATCH] Move kernel version/capabilities detection to NewDaemon Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- daemon/daemon.go | 30 ++++++++++++++++++++++++++++++ docker/docker.go | 32 -------------------------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index b8543e78a6..1d0f6748af 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -8,6 +8,7 @@ import ( "os" "path" "regexp" + "runtime" "strings" "sync" "time" @@ -29,6 +30,7 @@ import ( "github.com/docker/docker/pkg/namesgenerator" "github.com/docker/docker/pkg/networkfs/resolvconf" "github.com/docker/docker/pkg/parsers" + "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/sysinfo" "github.com/docker/docker/pkg/truncindex" "github.com/docker/docker/runconfig" @@ -767,6 +769,10 @@ func NewDaemonFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*D if os.Geteuid() != 0 { log.Fatalf("The Docker daemon needs to be run as root") } + if err := checkKernelAndArch(); err != nil { + log.Fatal(err) + } + // set up the TempDir to use a canonical path tmp := os.TempDir() realTmp, err := utils.ReadSymlinkedDirectory(tmp) @@ -1156,3 +1162,27 @@ func (daemon *Daemon) ImageGetCached(imgID string, config *runconfig.Config) (*i } return match, nil } + +func checkKernelAndArch() error { + // Check for unsupported architectures + if runtime.GOARCH != "amd64" { + return fmt.Errorf("The Docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH) + } + // Check for unsupported kernel versions + // FIXME: it would be cleaner to not test for specific versions, but rather + // test for specific functionalities. + // Unfortunately we can't test for the feature "does not cause a kernel panic" + // without actually causing a kernel panic, so we need this workaround until + // the circumstances of pre-3.8 crashes are clearer. + // For details see http://github.com/docker/docker/issues/407 + if k, err := kernel.GetKernelVersion(); err != nil { + log.Printf("WARNING: %s\n", err) + } else { + if kernel.CompareKernelVersion(k, &kernel.KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0}) < 0 { + if os.Getenv("DOCKER_NOWARN_KERNEL_VERSION") == "" { + log.Printf("WARNING: You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.8.0.", k.String()) + } + } + } + return nil +} diff --git a/docker/docker.go b/docker/docker.go index 155ce1cc50..679c91b462 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -9,7 +9,6 @@ import ( "net" "os" "path/filepath" - "runtime" "strings" "github.com/docker/docker/api" @@ -19,7 +18,6 @@ import ( "github.com/docker/docker/engine" "github.com/docker/docker/opts" flag "github.com/docker/docker/pkg/mflag" - "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/sysinit" "github.com/docker/docker/utils" ) @@ -118,12 +116,6 @@ func main() { flag.Usage() return } - - - if err := checkKernelAndArch(); err != nil { - log.Fatal(err) - } - eng := engine.New() // Load builtins if err := builtins.Register(eng); err != nil { @@ -255,27 +247,3 @@ func main() { func showVersion() { fmt.Printf("Docker version %s, build %s\n", dockerversion.VERSION, dockerversion.GITCOMMIT) } - -func checkKernelAndArch() error { - // Check for unsupported architectures - if runtime.GOARCH != "amd64" { - return fmt.Errorf("The Docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH) - } - // Check for unsupported kernel versions - // FIXME: it would be cleaner to not test for specific versions, but rather - // test for specific functionalities. - // Unfortunately we can't test for the feature "does not cause a kernel panic" - // without actually causing a kernel panic, so we need this workaround until - // the circumstances of pre-3.8 crashes are clearer. - // For details see http://github.com/docker/docker/issues/407 - if k, err := kernel.GetKernelVersion(); err != nil { - log.Printf("WARNING: %s\n", err) - } else { - if kernel.CompareKernelVersion(k, &kernel.KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0}) < 0 { - if os.Getenv("DOCKER_NOWARN_KERNEL_VERSION") == "" { - log.Printf("WARNING: You are running linux kernel version %s, which might be unstable running docker. Please upgrade your kernel to 3.8.0.", k.String()) - } - } - } - return nil -}