github.com/adxhyt/docker@v1.4.2-0.20150117221845-467b7c821390/docker/daemon.go (about) 1 // +build daemon 2 3 package main 4 5 import ( 6 log "github.com/Sirupsen/logrus" 7 "github.com/docker/docker/builder" 8 "github.com/docker/docker/builtins" 9 "github.com/docker/docker/daemon" 10 _ "github.com/docker/docker/daemon/execdriver/lxc" 11 _ "github.com/docker/docker/daemon/execdriver/native" 12 "github.com/docker/docker/dockerversion" 13 "github.com/docker/docker/engine" 14 flag "github.com/docker/docker/pkg/mflag" 15 "github.com/docker/docker/pkg/signal" 16 "github.com/docker/docker/registry" 17 ) 18 19 const CanDaemon = true 20 21 var ( 22 daemonCfg = &daemon.Config{} 23 registryCfg = ®istry.Options{} 24 ) 25 26 func init() { 27 daemonCfg.InstallFlags() 28 registryCfg.InstallFlags() 29 } 30 31 func mainDaemon() { 32 if flag.NArg() != 0 { 33 flag.Usage() 34 return 35 } 36 eng := engine.New() 37 signal.Trap(eng.Shutdown) 38 39 daemonCfg.TrustKeyPath = *flTrustKey 40 41 // Load builtins 42 if err := builtins.Register(eng); err != nil { 43 log.Fatal(err) 44 } 45 46 // load registry service 47 if err := registry.NewService(registryCfg).Install(eng); err != nil { 48 log.Fatal(err) 49 } 50 51 // load the daemon in the background so we can immediately start 52 // the http api so that connections don't fail while the daemon 53 // is booting 54 go func() { 55 d, err := daemon.NewDaemon(daemonCfg, eng) 56 if err != nil { 57 log.Fatal(err) 58 } 59 log.Infof("docker daemon: %s %s; execdriver: %s; graphdriver: %s", 60 dockerversion.VERSION, 61 dockerversion.GITCOMMIT, 62 d.ExecutionDriver().Name(), 63 d.GraphDriver().String(), 64 ) 65 66 if err := d.Install(eng); err != nil { 67 log.Fatal(err) 68 } 69 70 b := &builder.BuilderJob{eng, d} 71 b.Install() 72 73 // after the daemon is done setting up we can tell the api to start 74 // accepting connections 75 if err := eng.Job("acceptconnections").Run(); err != nil { 76 log.Fatal(err) 77 } 78 }() 79 80 // Serve api 81 job := eng.Job("serveapi", flHosts...) 82 job.SetenvBool("Logging", true) 83 job.SetenvBool("EnableCors", *flEnableCors) 84 job.Setenv("Version", dockerversion.VERSION) 85 job.Setenv("SocketGroup", *flSocketGroup) 86 87 job.SetenvBool("Tls", *flTls) 88 job.SetenvBool("TlsVerify", *flTlsVerify) 89 job.Setenv("TlsCa", *flCa) 90 job.Setenv("TlsCert", *flCert) 91 job.Setenv("TlsKey", *flKey) 92 job.SetenvBool("BufferRequests", true) 93 if err := job.Run(); err != nil { 94 log.Fatal(err) 95 } 96 }