Browse code

Engine: centralize checks for supported architectures and kernel versions

Solomon Hykes authored on 2013/10/23 15:53:40
Showing 3 changed files
... ...
@@ -3,6 +3,9 @@ package engine
3 3
 import (
4 4
 	"fmt"
5 5
 	"os"
6
+	"log"
7
+	"runtime"
8
+	"github.com/dotcloud/docker/utils"
6 9
 )
7 10
 
8 11
 
... ...
@@ -31,6 +34,24 @@ type Engine struct {
31 31
 // Changing the contents of the root without executing a job will cause unspecified
32 32
 // behavior.
33 33
 func New(root string) (*Engine, error) {
34
+	// Check for unsupported architectures
35
+	if runtime.GOARCH != "amd64" {
36
+		return nil, fmt.Errorf("The docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH)
37
+	}
38
+	// Check for unsupported kernel versions
39
+	// FIXME: it would be cleaner to not test for specific versions, but rather
40
+	// test for specific functionalities.
41
+	// Unfortunately we can't test for the feature "does not cause a kernel panic"
42
+	// without actually causing a kernel panic, so we need this workaround until
43
+	// the circumstances of pre-3.8 crashes are clearer.
44
+	// For details see http://github.com/dotcloud/docker/issues/407
45
+	if k, err := utils.GetKernelVersion(); err != nil {
46
+		log.Printf("WARNING: %s\n", err)
47
+	} else {
48
+		if utils.CompareKernelVersion(k, &utils.KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0}) < 0 {
49
+			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())
50
+		}
51
+	}
34 52
 	if err := os.MkdirAll(root, 0700); err != nil && !os.IsExist(err) {
35 53
 		return nil, err
36 54
 	}
... ...
@@ -577,14 +577,6 @@ func NewRuntime(config *DaemonConfig) (*Runtime, error) {
577 577
 	if err != nil {
578 578
 		return nil, err
579 579
 	}
580
-
581
-	if k, err := utils.GetKernelVersion(); err != nil {
582
-		log.Printf("WARNING: %s\n", err)
583
-	} else {
584
-		if utils.CompareKernelVersion(k, &utils.KernelVersionInfo{Kernel: 3, Major: 8, Minor: 0}) < 0 {
585
-			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())
586
-		}
587
-	}
588 580
 	runtime.UpdateCapabilities(false)
589 581
 	return runtime, nil
590 582
 }
... ...
@@ -1430,9 +1430,6 @@ func (srv *Server) ContainerCopy(name string, resource string, out io.Writer) er
1430 1430
 }
1431 1431
 
1432 1432
 func NewServer(config *DaemonConfig) (*Server, error) {
1433
-	if runtime.GOARCH != "amd64" {
1434
-		log.Fatalf("The docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH)
1435
-	}
1436 1433
 	runtime, err := NewRuntime(config)
1437 1434
 	if err != nil {
1438 1435
 		return nil, err