mirror of https://github.com/docker/docs.git
Choose a single backend with `--backend`
Note: for now there is only one backend available, `debug`
This commit is contained in:
parent
142e43a447
commit
c22a80a071
|
@ -0,0 +1,19 @@
|
||||||
|
package backends
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/dotcloud/docker/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
// New returns a new engine, with all backends
|
||||||
|
// registered but not activated.
|
||||||
|
// To activate a backend, call a job on the resulting
|
||||||
|
// engine, named after the desired backend.
|
||||||
|
//
|
||||||
|
// Example: `New().Job("debug").Run()`
|
||||||
|
func New() *engine.Engine {
|
||||||
|
back := engine.New()
|
||||||
|
back.Logging = false
|
||||||
|
// Register all backends here
|
||||||
|
Debug().Install(back)
|
||||||
|
return back
|
||||||
|
}
|
|
@ -14,7 +14,8 @@ type debug struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *debug) Install(eng *engine.Engine) error {
|
func (d *debug) Install(eng *engine.Engine) error {
|
||||||
eng.RegisterCatchall(func(job *engine.Job) engine.Status {
|
eng.Register("debug", func(job *engine.Job) engine.Status {
|
||||||
|
job.Eng.RegisterCatchall(func(job *engine.Job) engine.Status {
|
||||||
fmt.Printf("--> %s %s\n", job.Name, strings.Join(job.Args, " "))
|
fmt.Printf("--> %s %s\n", job.Name, strings.Join(job.Args, " "))
|
||||||
for k, v := range job.Env().Map() {
|
for k, v := range job.Env().Map() {
|
||||||
fmt.Printf(" %s=%s\n", k, v)
|
fmt.Printf(" %s=%s\n", k, v)
|
||||||
|
@ -26,5 +27,7 @@ func (d *debug) Install(eng *engine.Engine) error {
|
||||||
}
|
}
|
||||||
return engine.StatusOK
|
return engine.StatusOK
|
||||||
})
|
})
|
||||||
|
return engine.StatusOK
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,13 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
"github.com/docker/swarmd/backends"
|
"github.com/docker/swarmd/backends"
|
||||||
"github.com/dotcloud/docker/api/server"
|
"github.com/dotcloud/docker/api/server"
|
||||||
"github.com/dotcloud/docker/engine"
|
"github.com/dotcloud/docker/engine"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
"github.com/codegangsta/cli"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -17,6 +17,7 @@ func main() {
|
||||||
app.Usage = "Control a heterogenous distributed system with the Docker API"
|
app.Usage = "Control a heterogenous distributed system with the Docker API"
|
||||||
app.Version = "0.0.1"
|
app.Version = "0.0.1"
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
|
cli.StringFlag{"backend", "debug", "load a backend"},
|
||||||
}
|
}
|
||||||
app.Action = cmdDaemon
|
app.Action = cmdDaemon
|
||||||
app.Run(os.Args)
|
app.Run(os.Args)
|
||||||
|
@ -26,20 +27,37 @@ func cmdDaemon(c *cli.Context) {
|
||||||
if len(c.Args()) == 0 {
|
if len(c.Args()) == 0 {
|
||||||
Fatalf("Usage: %s <proto>://<address> [<proto>://<address>]...\n", c.App.Name)
|
Fatalf("Usage: %s <proto>://<address> [<proto>://<address>]...\n", c.App.Name)
|
||||||
}
|
}
|
||||||
eng := engine.New()
|
|
||||||
eng.Logging = false
|
// Load backend
|
||||||
if err := backends.Debug().Install(eng); err != nil {
|
// FIXME: allow for multiple backends to be loaded.
|
||||||
Fatalf("backend install: %v", err)
|
// This could be done by instantiating 1 engine per backend,
|
||||||
|
// installing each backend in its respective engine,
|
||||||
|
// then registering a Catchall on the frontent engine which
|
||||||
|
// multiplexes across all backends (with routing / filtering
|
||||||
|
// logic along the way).
|
||||||
|
back := backends.New()
|
||||||
|
backendName := c.String("backend")
|
||||||
|
fmt.Printf("Loading backend '%s'\n", backendName)
|
||||||
|
if err := back.Job(backendName).Run(); err != nil {
|
||||||
|
Fatalf("%s: %v\n", backendName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the API entrypoint
|
// Register the API entrypoint
|
||||||
// (we register it as `argv[0]` so we can print usage messages straight from the job
|
// (we register it as `argv[0]` so we can print usage messages straight from the job
|
||||||
// stderr.
|
// stderr.
|
||||||
eng.Register(c.App.Name, server.ServeApi)
|
front := engine.New()
|
||||||
|
front.Logging = false
|
||||||
|
// FIXME: server should expose an engine.Installer
|
||||||
|
front.Register(c.App.Name, server.ServeApi)
|
||||||
|
front.RegisterCatchall(func(job *engine.Job) engine.Status {
|
||||||
|
fw := back.Job(job.Name, job.Args...)
|
||||||
|
fw.Run()
|
||||||
|
return engine.Status(fw.StatusCode())
|
||||||
|
})
|
||||||
|
|
||||||
// Call the API entrypoint
|
// Call the API entrypoint
|
||||||
go func() {
|
go func() {
|
||||||
serve := eng.Job(c.App.Name, c.Args()...)
|
serve := front.Job(c.App.Name, c.Args()...)
|
||||||
serve.Stdout.Add(os.Stdout)
|
serve.Stdout.Add(os.Stdout)
|
||||||
serve.Stderr.Add(os.Stderr)
|
serve.Stderr.Add(os.Stderr)
|
||||||
if err := serve.Run(); err != nil {
|
if err := serve.Run(); err != nil {
|
||||||
|
@ -50,7 +68,7 @@ func cmdDaemon(c *cli.Context) {
|
||||||
// As a workaround we sleep to give it time to register 'acceptconnections'.
|
// As a workaround we sleep to give it time to register 'acceptconnections'.
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
// Notify that we're ready to receive connections
|
// Notify that we're ready to receive connections
|
||||||
if err := eng.Job("acceptconnections").Run(); err != nil {
|
if err := front.Job("acceptconnections").Run(); err != nil {
|
||||||
Fatalf("acceptconnections: %v", err)
|
Fatalf("acceptconnections: %v", err)
|
||||||
}
|
}
|
||||||
// Inifinite loop
|
// Inifinite loop
|
||||||
|
@ -61,7 +79,6 @@ func Fatalf(msg string, args ...interface{}) {
|
||||||
if !strings.HasSuffix(msg, "\n") {
|
if !strings.HasSuffix(msg, "\n") {
|
||||||
msg = msg + "\n"
|
msg = msg + "\n"
|
||||||
}
|
}
|
||||||
panic(msg)
|
|
||||||
fmt.Fprintf(os.Stderr, msg, args...)
|
fmt.Fprintf(os.Stderr, msg, args...)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue