Move kernel version/capabilities detection to NewDaemon

Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
Solomon Hykes 2014-07-30 06:51:43 +00:00
parent e92a9e0b53
commit 4949e070fb
2 changed files with 30 additions and 32 deletions

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"path" "path"
"regexp" "regexp"
"runtime"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -29,6 +30,7 @@ import (
"github.com/docker/docker/pkg/namesgenerator" "github.com/docker/docker/pkg/namesgenerator"
"github.com/docker/docker/pkg/networkfs/resolvconf" "github.com/docker/docker/pkg/networkfs/resolvconf"
"github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/parsers/kernel"
"github.com/docker/docker/pkg/sysinfo" "github.com/docker/docker/pkg/sysinfo"
"github.com/docker/docker/pkg/truncindex" "github.com/docker/docker/pkg/truncindex"
"github.com/docker/docker/runconfig" "github.com/docker/docker/runconfig"
@ -767,6 +769,10 @@ func NewDaemonFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*D
if os.Geteuid() != 0 { if os.Geteuid() != 0 {
log.Fatalf("The Docker daemon needs to be run as root") 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 // set up the TempDir to use a canonical path
tmp := os.TempDir() tmp := os.TempDir()
realTmp, err := utils.ReadSymlinkedDirectory(tmp) realTmp, err := utils.ReadSymlinkedDirectory(tmp)
@ -1156,3 +1162,27 @@ func (daemon *Daemon) ImageGetCached(imgID string, config *runconfig.Config) (*i
} }
return match, nil 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
}

View File

@ -9,7 +9,6 @@ import (
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"github.com/docker/docker/api" "github.com/docker/docker/api"
@ -19,7 +18,6 @@ import (
"github.com/docker/docker/engine" "github.com/docker/docker/engine"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/parsers/kernel"
"github.com/docker/docker/sysinit" "github.com/docker/docker/sysinit"
"github.com/docker/docker/utils" "github.com/docker/docker/utils"
) )
@ -118,12 +116,6 @@ func main() {
flag.Usage() flag.Usage()
return return
} }
if err := checkKernelAndArch(); err != nil {
log.Fatal(err)
}
eng := engine.New() eng := engine.New()
// Load builtins // Load builtins
if err := builtins.Register(eng); err != nil { if err := builtins.Register(eng); err != nil {
@ -255,27 +247,3 @@ func main() {
func showVersion() { func showVersion() {
fmt.Printf("Docker version %s, build %s\n", dockerversion.VERSION, dockerversion.GITCOMMIT) 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
}