From e2447721eb1cbbbe304e1196114f6b375f6dc07e Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 2 Jun 2015 17:00:48 +0100 Subject: [PATCH] [proxy] We can only rely on receiving a signal when we are a container Due to https://github.com/docker/docker/issues/9098, there is no way to signal an exec. Instead we'll have to just poll the interface and hope. Adds `weavewait -s` which is the way to tell weavewait to skip waiting for a signal, which we use on execs --- prog/weavewait/main.go | 32 +++++++++++++++++++++----------- proxy/create_exec_interceptor.go | 3 ++- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/prog/weavewait/main.go b/prog/weavewait/main.go index bff78b05..3cb78663 100644 --- a/prog/weavewait/main.go +++ b/prog/weavewait/main.go @@ -1,32 +1,42 @@ package main import ( - "errors" "fmt" "os" "os/exec" "os/signal" "syscall" "time" + + "github.com/weaveworks/weave/net" ) func main() { - usr2 := make(chan os.Signal) - signal.Notify(usr2, syscall.SIGUSR2) - select { - case <-usr2: - case <-time.After(20 * time.Second): - checkErr(errors.New("Container timed out waiting for signal from proxy")) - } - if len(os.Args) <= 1 { os.Exit(0) } - binary, err := exec.LookPath(os.Args[1]) + args := os.Args[1:] + signalWait := 20 + if args[0] == "-s" { + signalWait = 0 + args = args[1:] + } + interfaceWait := 20 - signalWait + + usr2 := make(chan os.Signal) + signal.Notify(usr2, syscall.SIGUSR2) + select { + case <-usr2: + case <-time.After(time.Duration(signalWait) * time.Second): + } + _, err := net.EnsureInterface("ethwe", interfaceWait) checkErr(err) - checkErr(syscall.Exec(binary, os.Args[1:], os.Environ())) + binary, err := exec.LookPath(args[0]) + checkErr(err) + + checkErr(syscall.Exec(binary, args, os.Environ())) } func checkErr(err error) { diff --git a/proxy/create_exec_interceptor.go b/proxy/create_exec_interceptor.go index 8829bd50..6c604aee 100644 --- a/proxy/create_exec_interceptor.go +++ b/proxy/create_exec_interceptor.go @@ -34,7 +34,8 @@ func (i *createExecInterceptor) InterceptRequest(r *http.Request) error { if cidrs, ok := weaveCIDRsFromConfig(container.Config); ok || i.withIPAM { Info.Printf("Exec in container %s with WEAVE_CIDR \"%s\"", container.ID, strings.Join(cidrs, " ")) - options.Cmd = append(weaveWaitEntrypoint, options.Cmd...) + cmd := append(weaveWaitEntrypoint, "-s") + options.Cmd = append(cmd, options.Cmd...) } if err := marshalRequestBody(r, options); err != nil {