split api and server. run return exit code. import, pull and commit uses the smae endpoint. non zero status code on failure

This commit is contained in:
Victor Vieux
2013-05-06 11:31:22 +02:00
parent 75418ec849
commit 04cd20fa62
7 changed files with 726 additions and 579 deletions
+5 -51
View File
@@ -4,14 +4,10 @@ import (
"flag"
"fmt"
"github.com/dotcloud/docker"
"github.com/dotcloud/docker/rcli"
"github.com/dotcloud/docker/term"
"io"
"io/ioutil"
"log"
"os"
"os/signal"
"runtime"
"strconv"
"syscall"
)
@@ -49,10 +45,12 @@ func main() {
}
if err := daemon(*pidfile, *flAutoRestart); err != nil {
log.Fatal(err)
os.Exit(-1)
}
} else {
if err := docker.ParseCommands(flag.Args()); err != nil {
if err := docker.ParseCommands(flag.Args()...); err != nil {
log.Fatal(err)
os.Exit(-1)
}
}
}
@@ -99,54 +97,10 @@ func daemon(pidfile string, autoRestart bool) error {
os.Exit(0)
}()
if runtime.GOARCH != "amd64" {
log.Fatalf("The docker runtime currently only supports amd64 (not %s). This will change in the future. Aborting.", runtime.GOARCH)
}
runtime, err := docker.NewRuntime(autoRestart)
server, err := docker.NewServer(autoRestart)
if err != nil {
return err
}
return docker.ListenAndServe("0.0.0.0:4243", runtime)
}
func runCommand(args []string) error {
// FIXME: we want to use unix sockets here, but net.UnixConn doesn't expose
// CloseWrite(), which we need to cleanly signal that stdin is closed without
// closing the connection.
// See http://code.google.com/p/go/issues/detail?id=3345
if conn, err := rcli.Call("tcp", "127.0.0.1:4242", args...); err == nil {
options := conn.GetOptions()
if options.RawTerminal &&
term.IsTerminal(int(os.Stdin.Fd())) &&
os.Getenv("NORAW") == "" {
if oldState, err := rcli.SetRawTerminal(); err != nil {
return err
} else {
defer rcli.RestoreTerminal(oldState)
}
}
receiveStdout := docker.Go(func() error {
_, err := io.Copy(os.Stdout, conn)
return err
})
sendStdin := docker.Go(func() error {
_, err := io.Copy(conn, os.Stdin)
if err := conn.CloseWrite(); err != nil {
log.Printf("Couldn't send EOF: " + err.Error())
}
return err
})
if err := <-receiveStdout; err != nil {
return err
}
if !term.IsTerminal(int(os.Stdin.Fd())) {
if err := <-sendStdin; err != nil {
return err
}
}
} else {
return fmt.Errorf("Can't connect to docker daemon. Is 'docker -d' running on this host?")
}
return nil
return docker.ListenAndServe("0.0.0.0:4243", server)
}