зеркало из https://github.com/microsoft/docker.git
Merge dockerd into docker. 'docker -d' runs in daemon mode. For all other commands, docker auto-detects whether to run standalone or to remote-control the daemon
This commit is contained in:
Родитель
86854ffbc5
Коммит
745edc49cd
|
@ -1,6 +1,5 @@
|
|||
.vagrant
|
||||
docker/docker
|
||||
dockerd/dockerd
|
||||
.*.swp
|
||||
a.out
|
||||
*.orig
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"github.com/dotcloud/docker/future"
|
||||
"github.com/dotcloud/docker/rcli"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Run docker in "simple mode": run a single command and return.
|
||||
func SimpleMode(args []string) error {
|
||||
var oldState *State
|
||||
var err error
|
||||
if IsTerminal(0) && os.Getenv("NORAW") == "" {
|
||||
oldState, err = MakeRaw(0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer Restore(0, oldState)
|
||||
}
|
||||
// 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
|
||||
conn, err := rcli.Call("tcp", "127.0.0.1:4242", args...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
receive_stdout := future.Go(func() error {
|
||||
_, err := io.Copy(os.Stdout, conn)
|
||||
return err
|
||||
})
|
||||
send_stdin := future.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 := <-receive_stdout; err != nil {
|
||||
return err
|
||||
}
|
||||
if oldState != nil {
|
||||
Restore(0, oldState)
|
||||
}
|
||||
if !IsTerminal(0) {
|
||||
if err := <-send_stdin; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package server
|
||||
package commands
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
|
@ -24,15 +24,6 @@ import (
|
|||
|
||||
const VERSION = "0.0.1"
|
||||
|
||||
func (srv *Server) ListenAndServe() error {
|
||||
go rcli.ListenAndServeHTTP("127.0.0.1:8080", srv)
|
||||
// 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
|
||||
return rcli.ListenAndServe("tcp", "127.0.0.1:4242", srv)
|
||||
}
|
||||
|
||||
func (srv *Server) Name() string {
|
||||
return "docker"
|
||||
}
|
|
@ -1,13 +1,93 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/dotcloud/docker/client"
|
||||
"flag"
|
||||
"github.com/dotcloud/docker"
|
||||
"github.com/dotcloud/docker/commands"
|
||||
"github.com/dotcloud/docker/future"
|
||||
"github.com/dotcloud/docker/rcli"
|
||||
"github.com/dotcloud/docker/term"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := client.SimpleMode(os.Args[1:]); err != nil {
|
||||
log.Fatal(err)
|
||||
if docker.SelfPath() == "/sbin/init" {
|
||||
// Running in init mode
|
||||
docker.SysInit()
|
||||
return
|
||||
}
|
||||
fl_daemon := flag.Bool("d", false, "Daemon mode")
|
||||
flag.Parse()
|
||||
if *fl_daemon {
|
||||
if flag.NArg() != 0 {
|
||||
flag.Usage()
|
||||
return
|
||||
}
|
||||
if err := daemon(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
if err := runCommand(flag.Args()); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func daemon() error {
|
||||
service, err := commands.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return rcli.ListenAndServe("tcp", "127.0.0.1:4242", service)
|
||||
}
|
||||
|
||||
func runCommand(args []string) error {
|
||||
var oldState *term.State
|
||||
var err error
|
||||
if term.IsTerminal(0) && os.Getenv("NORAW") == "" {
|
||||
oldState, err = term.MakeRaw(0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer term.Restore(0, oldState)
|
||||
}
|
||||
// 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 {
|
||||
receive_stdout := future.Go(func() error {
|
||||
_, err := io.Copy(os.Stdout, conn)
|
||||
return err
|
||||
})
|
||||
send_stdin := future.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 := <-receive_stdout; err != nil {
|
||||
return err
|
||||
}
|
||||
if !term.IsTerminal(0) {
|
||||
if err := <-send_stdin; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
service, err := commands.New()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := rcli.LocalCall(service, os.Stdin, os.Stdout, args...); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if oldState != nil {
|
||||
term.Restore(0, oldState)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/dotcloud/docker"
|
||||
"github.com/dotcloud/docker/server"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if docker.SelfPath() == "/sbin/init" {
|
||||
// Running in init mode
|
||||
docker.SysInit()
|
||||
return
|
||||
}
|
||||
flag.Parse()
|
||||
d, err := server.New()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := d.ListenAndServe(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
|
@ -25,7 +25,12 @@ type Service interface {
|
|||
type Cmd func(io.ReadCloser, io.Writer, ...string) error
|
||||
type CmdMethod func(Service, io.ReadCloser, io.Writer, ...string) error
|
||||
|
||||
// FIXME: For reverse compatibility
|
||||
func call(service Service, stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
||||
return LocalCall(service, stdin, stdout, args...)
|
||||
}
|
||||
|
||||
func LocalCall(service Service, stdin io.ReadCloser, stdout io.Writer, args ...string) error {
|
||||
if len(args) == 0 {
|
||||
args = []string{"help"}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package client
|
||||
package term
|
||||
|
||||
import (
|
||||
"syscall"
|
|
@ -1,4 +1,4 @@
|
|||
package client
|
||||
package term
|
||||
|
||||
import "syscall"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package client
|
||||
package term
|
||||
|
||||
import "syscall"
|
||||
|
Загрузка…
Ссылка в новой задаче