From f132e3fb0362e4089076c9863d10475ad494e391 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 1 May 2014 16:13:41 -0700 Subject: [PATCH] Initial commit --- MAINTAINERS | 1 + swarmd/swarmd.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 MAINTAINERS create mode 100644 swarmd/swarmd.go diff --git a/MAINTAINERS b/MAINTAINERS new file mode 100644 index 0000000000..5a61dee410 --- /dev/null +++ b/MAINTAINERS @@ -0,0 +1 @@ +Solomon Hykes (github:shykes) diff --git a/swarmd/swarmd.go b/swarmd/swarmd.go new file mode 100644 index 0000000000..6007fa7c03 --- /dev/null +++ b/swarmd/swarmd.go @@ -0,0 +1,53 @@ +package main + +import ( + "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 + }) + eng.Register(os.Args[0], server.ServeApi) + + // Register the entrypoint job as the current proces command name, + // to get matching usage straight from the job. + go func() { + serve := eng.Job(os.Args[0], os.Args[1:]...) + serve.Stdout.Add(os.Stdout) + serve.Stderr.Add(os.Stderr) + if err := serve.Run(); err != nil { + Fatalf("%v", err) + } + }() + // There is a race condition in engine.ServeApi. + // As a workaround we sleep to give it time to register 'acceptconnections'. + time.Sleep(1) + // Notify that we're ready to receive connections + if err := eng.Job("acceptconnections").Run(); err != nil { + Fatalf("%v", err) + } + // Inifinite loop + <-make(chan struct{}) +} + +func Fatalf(msg string, args ...interface{}) { + fmt.Fprintf(os.Stderr, msg, args...) + os.Exit(1) +}