2014-08-01 17:34:06 +00:00
|
|
|
// +build daemon
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-10-24 17:12:35 +00:00
|
|
|
log "github.com/Sirupsen/logrus"
|
2014-08-11 15:44:31 +00:00
|
|
|
"github.com/docker/docker/builder"
|
2014-08-01 17:34:06 +00:00
|
|
|
"github.com/docker/docker/builtins"
|
2014-08-08 09:12:39 +00:00
|
|
|
"github.com/docker/docker/daemon"
|
2014-08-08 20:18:18 +00:00
|
|
|
_ "github.com/docker/docker/daemon/execdriver/lxc"
|
|
|
|
_ "github.com/docker/docker/daemon/execdriver/native"
|
2014-08-01 17:34:06 +00:00
|
|
|
"github.com/docker/docker/dockerversion"
|
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
2014-08-06 08:12:22 +00:00
|
|
|
"github.com/docker/docker/pkg/signal"
|
2014-08-20 15:31:24 +00:00
|
|
|
"github.com/docker/docker/registry"
|
2014-08-01 17:34:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const CanDaemon = true
|
|
|
|
|
2014-08-10 01:18:32 +00:00
|
|
|
var (
|
|
|
|
daemonCfg = &daemon.Config{}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
daemonCfg.InstallFlags()
|
|
|
|
}
|
|
|
|
|
2014-08-01 17:34:06 +00:00
|
|
|
func mainDaemon() {
|
|
|
|
if flag.NArg() != 0 {
|
|
|
|
flag.Usage()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
eng := engine.New()
|
2014-08-06 08:12:22 +00:00
|
|
|
signal.Trap(eng.Shutdown)
|
2014-08-20 15:31:24 +00:00
|
|
|
|
2014-11-17 19:23:41 +00:00
|
|
|
daemonCfg.TrustKeyPath = *flTrustKey
|
|
|
|
|
2014-08-01 17:34:06 +00:00
|
|
|
// Load builtins
|
|
|
|
if err := builtins.Register(eng); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-08-20 15:31:24 +00:00
|
|
|
// load registry service
|
|
|
|
if err := registry.NewService(daemonCfg.InsecureRegistries).Install(eng); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2014-08-01 17:34:06 +00:00
|
|
|
// load the daemon in the background so we can immediately start
|
|
|
|
// the http api so that connections don't fail while the daemon
|
|
|
|
// is booting
|
|
|
|
go func() {
|
2014-08-10 01:18:32 +00:00
|
|
|
d, err := daemon.NewDaemon(daemonCfg, eng)
|
2014-08-08 09:12:39 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2014-10-21 07:00:25 +00:00
|
|
|
log.Infof("docker daemon: %s %s; execdriver: %s; graphdriver: %s",
|
|
|
|
dockerversion.VERSION,
|
|
|
|
dockerversion.GITCOMMIT,
|
|
|
|
d.ExecutionDriver().Name(),
|
|
|
|
d.GraphDriver().String(),
|
|
|
|
)
|
|
|
|
|
2014-08-08 09:12:39 +00:00
|
|
|
if err := d.Install(eng); err != nil {
|
2014-08-01 17:34:06 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2014-08-11 15:44:31 +00:00
|
|
|
|
|
|
|
b := &builder.BuilderJob{eng, d}
|
|
|
|
b.Install()
|
|
|
|
|
2014-08-01 17:34:06 +00:00
|
|
|
// after the daemon is done setting up we can tell the api to start
|
|
|
|
// accepting connections
|
|
|
|
if err := eng.Job("acceptconnections").Run(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Serve api
|
2014-08-11 22:30:01 +00:00
|
|
|
job := eng.Job("serveapi", flHosts...)
|
2014-08-01 17:34:06 +00:00
|
|
|
job.SetenvBool("Logging", true)
|
|
|
|
job.SetenvBool("EnableCors", *flEnableCors)
|
|
|
|
job.Setenv("Version", dockerversion.VERSION)
|
|
|
|
job.Setenv("SocketGroup", *flSocketGroup)
|
|
|
|
|
|
|
|
job.SetenvBool("Tls", *flTls)
|
|
|
|
job.SetenvBool("TlsVerify", *flTlsVerify)
|
|
|
|
job.Setenv("TlsCa", *flCa)
|
|
|
|
job.Setenv("TlsCert", *flCert)
|
|
|
|
job.Setenv("TlsKey", *flKey)
|
|
|
|
job.SetenvBool("BufferRequests", true)
|
|
|
|
if err := job.Run(); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|