From 7821412bf786844919afd2d104671cbf11fd214b Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 2 Jul 2015 15:43:03 +0100 Subject: [PATCH] [proxy] print all stderr from callWeave to the proxy logs, even if successful --- proxy/common.go | 9 ++++++--- proxy/proxy.go | 4 ++-- proxy/start_container_interceptor.go | 8 +++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/proxy/common.go b/proxy/common.go index 7231226c..985fae9a 100644 --- a/proxy/common.go +++ b/proxy/common.go @@ -18,13 +18,16 @@ var ( weaveWaitEntrypoint = []string{"/w/w"} ) -func callWeave(args ...string) ([]byte, error) { +func callWeave(args ...string) ([]byte, []byte, error) { args = append([]string{"--local"}, args...) Log.Debug("Calling weave", args) cmd := exec.Command("./weave", args...) cmd.Env = []string{"PROCFS=/hostproc", "PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"} - out, err := cmd.CombinedOutput() - return out, err + var stdout, stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + err := cmd.Run() + return stdout.Bytes(), stderr.Bytes(), err } func marshalRequestBody(r *http.Request, body interface{}) error { diff --git a/proxy/proxy.go b/proxy/proxy.go index 0812ab4b..2993d00d 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -57,9 +57,9 @@ func NewProxy(c Config) (*Proxy, error) { p.client = client if !p.WithoutDNS { - dockerBridgeIP, err := callWeave("docker-bridge-ip") + dockerBridgeIP, stderr, err := callWeave("docker-bridge-ip") if err != nil { - return nil, err + return nil, fmt.Errorf(string(stderr)) } p.dockerBridgeIP = string(dockerBridgeIP) } diff --git a/proxy/start_container_interceptor.go b/proxy/start_container_interceptor.go index b7da0505..1a4de456 100644 --- a/proxy/start_container_interceptor.go +++ b/proxy/start_container_interceptor.go @@ -30,9 +30,11 @@ func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error { args := []string{"attach"} args = append(args, cidrs...) args = append(args, "--or-die", container.ID) - if output, err := callWeave(args...); err != nil { - Log.Warningf("Attaching container %s to weave network failed: %s", container.ID, string(output)) - return errors.New(string(output)) + if _, stderr, err := callWeave(args...); err != nil { + Log.Warningf("Attaching container %s to weave network failed: %s", container.ID, string(stderr)) + return errors.New(string(stderr)) + } else if len(stderr) > 0 { + Log.Warningf("Attaching container %s to weave network: %s", container.ID, string(stderr)) } return i.proxy.client.KillContainer(docker.KillContainerOptions{ID: container.ID, Signal: docker.SIGUSR2})