diff --git a/backends/debug.go b/backends/debug.go new file mode 100644 index 0000000000..ad30844008 --- /dev/null +++ b/backends/debug.go @@ -0,0 +1,30 @@ +package backends + +import ( + "fmt" + "github.com/dotcloud/docker/engine" + "strings" +) + +func Debug() engine.Installer { + return &debug{} +} + +type debug struct { +} + +func (d *debug) Install(eng *engine.Engine) error { + eng.RegisterCatchall(func(job *engine.Job) engine.Status { + fmt.Printf("--> %s %s\n", job.Name, strings.Join(job.Args, " ")) + for k, v := range job.Env().Map() { + fmt.Printf(" %s=%s\n", k, v) + } + // This helps us detect the race condition if our time.Sleep + // missed it. (see comment in main) + if job.Name == "acceptconnections" { + panic("race condition in github.com/dotcloud/docker/api/server/ServeApi") + } + return engine.StatusOK + }) + return nil +} diff --git a/swarmd/swarmd.go b/swarmd/swarmd.go index 6007fa7c03..5a5d7c992d 100644 --- a/swarmd/swarmd.go +++ b/swarmd/swarmd.go @@ -1,29 +1,20 @@ package main import ( + "fmt" + "github.com/docker/swarmd/backends" "github.com/dotcloud/docker/api/server" "github.com/dotcloud/docker/engine" - "strings" "os" - "fmt" "time" ) func main() { eng := engine.New() eng.Logging = false - eng.RegisterCatchall(func(job *engine.Job) engine.Status { - fmt.Printf("--> %s %s\n", job.Name, strings.Join(job.Args, " ")) - for k, v := range job.Env().Map() { - fmt.Printf(" %s=%s\n", k, v) - } - // This helps us detect the race condition if our time.Sleep - // missed it. (see comment below) - if job.Name == "acceptconnections" { - panic("race condition in github.com/dotcloud/docker/api/server/ServeApi") - } - return engine.StatusOK - }) + if err := backends.Debug().Install(eng); err != nil { + Fatalf("%v", err) + } eng.Register(os.Args[0], server.ServeApi) // Register the entrypoint job as the current proces command name,