Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
| ... | ... |
@@ -36,6 +36,10 @@ const ( |
| 36 | 36 |
|
| 37 | 37 |
type HttpApiFunc func(eng *engine.Engine, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error |
| 38 | 38 |
|
| 39 |
+func init() {
|
|
| 40 |
+ engine.Register("serveapi", ServeApi)
|
|
| 41 |
+} |
|
| 42 |
+ |
|
| 39 | 43 |
func hijackServer(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) {
|
| 40 | 44 |
conn, _, err := w.(http.Hijacker).Hijack() |
| 41 | 45 |
if err != nil {
|
| ... | ... |
@@ -1160,3 +1164,30 @@ func ListenAndServe(proto, addr string, eng *engine.Engine, logging, enableCors |
| 1160 | 1160 |
httpSrv := http.Server{Addr: addr, Handler: r}
|
| 1161 | 1161 |
return httpSrv.Serve(l) |
| 1162 | 1162 |
} |
| 1163 |
+ |
|
| 1164 |
+// ServeApi loops through all of the protocols sent in to docker and spawns |
|
| 1165 |
+// off a go routine to setup a serving http.Server for each. |
|
| 1166 |
+func ServeApi(job *engine.Job) engine.Status {
|
|
| 1167 |
+ protoAddrs := job.Args |
|
| 1168 |
+ chErrors := make(chan error, len(protoAddrs)) |
|
| 1169 |
+ |
|
| 1170 |
+ for _, protoAddr := range protoAddrs {
|
|
| 1171 |
+ protoAddrParts := strings.SplitN(protoAddr, "://", 2) |
|
| 1172 |
+ go func() {
|
|
| 1173 |
+ log.Printf("Listening for HTTP on %s (%s)\n", protoAddrParts[0], protoAddrParts[1])
|
|
| 1174 |
+ chErrors <- ListenAndServe(protoAddrParts[0], protoAddrParts[1], job.Eng, job.GetenvBool("Logging"), job.GetenvBool("EnableCors"), job.Getenv("Version"))
|
|
| 1175 |
+ }() |
|
| 1176 |
+ } |
|
| 1177 |
+ |
|
| 1178 |
+ for i := 0; i < len(protoAddrs); i += 1 {
|
|
| 1179 |
+ err := <-chErrors |
|
| 1180 |
+ if err != nil {
|
|
| 1181 |
+ return job.Error(err) |
|
| 1182 |
+ } |
|
| 1183 |
+ } |
|
| 1184 |
+ |
|
| 1185 |
+ // Tell the init daemon we are accepting requests |
|
| 1186 |
+ go systemd.SdNotify("READY=1")
|
|
| 1187 |
+ |
|
| 1188 |
+ return engine.StatusOK |
|
| 1189 |
+} |
| ... | ... |
@@ -83,7 +83,7 @@ func main() {
|
| 83 | 83 |
log.Fatal(err) |
| 84 | 84 |
} |
| 85 | 85 |
// Load plugin: httpapi |
| 86 |
- job := eng.Job("initapi")
|
|
| 86 |
+ job := eng.Job("initserver")
|
|
| 87 | 87 |
job.Setenv("Pidfile", *pidfile)
|
| 88 | 88 |
job.Setenv("Root", *flRoot)
|
| 89 | 89 |
job.SetenvBool("AutoRestart", *flAutoRestart)
|
| ... | ... |
@@ -103,6 +103,7 @@ func main() {
|
| 103 | 103 |
job = eng.Job("serveapi", flHosts.GetAll()...)
|
| 104 | 104 |
job.SetenvBool("Logging", true)
|
| 105 | 105 |
job.SetenvBool("EnableCors", *flEnableCors)
|
| 106 |
+ job.Setenv("Version", VERSION)
|
|
| 106 | 107 |
if err := job.Run(); err != nil {
|
| 107 | 108 |
log.Fatal(err) |
| 108 | 109 |
} |
| ... | ... |
@@ -125,7 +125,7 @@ func setupBaseImage() {
|
| 125 | 125 |
if err != nil {
|
| 126 | 126 |
log.Fatalf("Can't initialize engine at %s: %s", unitTestStoreBase, err)
|
| 127 | 127 |
} |
| 128 |
- job := eng.Job("initapi")
|
|
| 128 |
+ job := eng.Job("initserver")
|
|
| 129 | 129 |
job.Setenv("Root", unitTestStoreBase)
|
| 130 | 130 |
job.SetenvBool("Autorestart", false)
|
| 131 | 131 |
job.Setenv("BridgeIface", unitTestNetworkBridge)
|
| ... | ... |
@@ -573,7 +573,7 @@ func TestRestore(t *testing.T) {
|
| 573 | 573 |
if err != nil {
|
| 574 | 574 |
t.Fatal(err) |
| 575 | 575 |
} |
| 576 |
- job := eng.Job("initapi")
|
|
| 576 |
+ job := eng.Job("initserver")
|
|
| 577 | 577 |
job.Setenv("Root", eng.Root())
|
| 578 | 578 |
job.SetenvBool("Autorestart", false)
|
| 579 | 579 |
if err := job.Run(); err != nil {
|
| ... | ... |
@@ -605,7 +605,7 @@ func TestRestore(t *testing.T) {
|
| 605 | 605 |
} |
| 606 | 606 |
|
| 607 | 607 |
func TestReloadContainerLinks(t *testing.T) {
|
| 608 |
- // FIXME: here we don't use NewTestEngine because it calls initapi with Autorestart=false, |
|
| 608 |
+ // FIXME: here we don't use NewTestEngine because it calls initserver with Autorestart=false, |
|
| 609 | 609 |
// and we want to set it to true. |
| 610 | 610 |
root, err := newTestDirectory(unitTestStoreBase) |
| 611 | 611 |
if err != nil {
|
| ... | ... |
@@ -615,7 +615,7 @@ func TestReloadContainerLinks(t *testing.T) {
|
| 615 | 615 |
if err != nil {
|
| 616 | 616 |
t.Fatal(err) |
| 617 | 617 |
} |
| 618 |
- job := eng.Job("initapi")
|
|
| 618 |
+ job := eng.Job("initserver")
|
|
| 619 | 619 |
job.Setenv("Root", eng.Root())
|
| 620 | 620 |
job.SetenvBool("Autorestart", true)
|
| 621 | 621 |
if err := job.Run(); err != nil {
|
| ... | ... |
@@ -665,7 +665,7 @@ func TestReloadContainerLinks(t *testing.T) {
|
| 665 | 665 |
if err != nil {
|
| 666 | 666 |
t.Fatal(err) |
| 667 | 667 |
} |
| 668 |
- job = eng.Job("initapi")
|
|
| 668 |
+ job = eng.Job("initserver")
|
|
| 669 | 669 |
job.Setenv("Root", eng.Root())
|
| 670 | 670 |
job.SetenvBool("Autorestart", false)
|
| 671 | 671 |
if err := job.Run(); err != nil {
|
| ... | ... |
@@ -262,7 +262,7 @@ func TestRestartKillWait(t *testing.T) {
|
| 262 | 262 |
t.Fatal(err) |
| 263 | 263 |
} |
| 264 | 264 |
|
| 265 |
- job = eng.Job("initapi")
|
|
| 265 |
+ job = eng.Job("initserver")
|
|
| 266 | 266 |
job.Setenv("Root", eng.Root())
|
| 267 | 267 |
job.SetenvBool("AutoRestart", false)
|
| 268 | 268 |
// TestGetEnabledCors and TestOptionsRoute require EnableCors=true |
| ... | ... |
@@ -188,7 +188,7 @@ func NewTestEngine(t utils.Fataler) *engine.Engine {
|
| 188 | 188 |
} |
| 189 | 189 |
// Load default plugins |
| 190 | 190 |
// (This is manually copied and modified from main() until we have a more generic plugin system) |
| 191 |
- job := eng.Job("initapi")
|
|
| 191 |
+ job := eng.Job("initserver")
|
|
| 192 | 192 |
job.Setenv("Root", root)
|
| 193 | 193 |
job.SetenvBool("AutoRestart", false)
|
| 194 | 194 |
// TestGetEnabledCors and TestOptionsRoute require EnableCors=true |
| ... | ... |
@@ -4,12 +4,10 @@ import ( |
| 4 | 4 |
"encoding/json" |
| 5 | 5 |
"errors" |
| 6 | 6 |
"fmt" |
| 7 |
- "github.com/dotcloud/docker/api" |
|
| 8 | 7 |
"github.com/dotcloud/docker/archive" |
| 9 | 8 |
"github.com/dotcloud/docker/auth" |
| 10 | 9 |
"github.com/dotcloud/docker/engine" |
| 11 | 10 |
"github.com/dotcloud/docker/pkg/graphdb" |
| 12 |
- "github.com/dotcloud/docker/pkg/systemd" |
|
| 13 | 11 |
"github.com/dotcloud/docker/registry" |
| 14 | 12 |
"github.com/dotcloud/docker/utils" |
| 15 | 13 |
"io" |
| ... | ... |
@@ -35,13 +33,13 @@ func (srv *Server) Close() error {
|
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 | 37 |
func init() {
|
| 38 |
- engine.Register("initapi", jobInitApi)
|
|
| 38 |
+ engine.Register("initserver", jobInitServer)
|
|
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 | 41 |
// jobInitApi runs the remote api server `srv` as a daemon, |
| 42 | 42 |
// Only one api server can run at the same time - this is enforced by a pidfile. |
| 43 | 43 |
// The signals SIGINT, SIGQUIT and SIGTERM are intercepted for cleanup. |
| 44 |
-func jobInitApi(job *engine.Job) engine.Status {
|
|
| 44 |
+func jobInitServer(job *engine.Job) engine.Status {
|
|
| 45 | 45 |
job.Logf("Creating server")
|
| 46 | 46 |
srv, err := NewServer(job.Eng, DaemonConfigFromJob(job)) |
| 47 | 47 |
if err != nil {
|
| ... | ... |
@@ -77,7 +75,6 @@ func jobInitApi(job *engine.Job) engine.Status {
|
| 77 | 77 |
"restart": srv.ContainerRestart, |
| 78 | 78 |
"start": srv.ContainerStart, |
| 79 | 79 |
"kill": srv.ContainerKill, |
| 80 |
- "serveapi": srv.ListenAndServe, |
|
| 81 | 80 |
"wait": srv.ContainerWait, |
| 82 | 81 |
"tag": srv.ImageTag, |
| 83 | 82 |
"resize": srv.ContainerResize, |
| ... | ... |
@@ -112,33 +109,6 @@ func jobInitApi(job *engine.Job) engine.Status {
|
| 112 | 112 |
return engine.StatusOK |
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 |
-// ListenAndServe loops through all of the protocols sent in to docker and spawns |
|
| 116 |
-// off a go routine to setup a serving http.Server for each. |
|
| 117 |
-func (srv *Server) ListenAndServe(job *engine.Job) engine.Status {
|
|
| 118 |
- protoAddrs := job.Args |
|
| 119 |
- chErrors := make(chan error, len(protoAddrs)) |
|
| 120 |
- |
|
| 121 |
- for _, protoAddr := range protoAddrs {
|
|
| 122 |
- protoAddrParts := strings.SplitN(protoAddr, "://", 2) |
|
| 123 |
- go func() {
|
|
| 124 |
- log.Printf("Listening for HTTP on %s (%s)\n", protoAddrParts[0], protoAddrParts[1])
|
|
| 125 |
- chErrors <- api.ListenAndServe(protoAddrParts[0], protoAddrParts[1], srv.Eng, job.GetenvBool("Logging"), job.GetenvBool("EnableCors"), VERSION)
|
|
| 126 |
- }() |
|
| 127 |
- } |
|
| 128 |
- |
|
| 129 |
- for i := 0; i < len(protoAddrs); i += 1 {
|
|
| 130 |
- err := <-chErrors |
|
| 131 |
- if err != nil {
|
|
| 132 |
- return job.Error(err) |
|
| 133 |
- } |
|
| 134 |
- } |
|
| 135 |
- |
|
| 136 |
- // Tell the init daemon we are accepting requests |
|
| 137 |
- go systemd.SdNotify("READY=1")
|
|
| 138 |
- |
|
| 139 |
- return engine.StatusOK |
|
| 140 |
-} |
|
| 141 |
- |
|
| 142 | 115 |
// simpleVersionInfo is a simple implementation of |
| 143 | 116 |
// the interface VersionInfo, which is used |
| 144 | 117 |
// to provide version information for some product, |