[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
This commit is contained in:
Paul Bellamy committed 2015-06-02 17:21:41 +01:00
1 parent 89074715bc
commit e2447721eb
2 files changed
+23 -12

No files matched your search

+21 -11
View File
@@ -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) {
+2 -1
View File
@@ -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 {