Initial commit

This commit is contained in:
Solomon Hykes 2014-05-01 16:13:41 -07:00
commit f132e3fb03
2 changed files with 54 additions and 0 deletions

1
MAINTAINERS Normal file
View File

@ -0,0 +1 @@
Solomon Hykes <solomon@docker.com> (github:shykes)

53
swarmd/swarmd.go Normal file
View File

@ -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)
}