From bf3ecaf48acd02728eef61e5193a861f0dcc49d9 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sat, 13 May 2017 16:31:16 +0100 Subject: [PATCH 1/4] Remove proxy status.sock --- prog/weaver/main.go | 6 ++++-- proxy/proxy.go | 11 ----------- weave | 16 +--------------- 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 8217d730..8ab4efe1 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -258,9 +258,11 @@ func main() { var waitReady common.WaitGroup + var proxy *weaveproxy.Proxy + var err error if proxyConfig.Enabled { // Start Weave Proxy: - proxy, err := weaveproxy.NewProxy(*proxyConfig) + proxy, err = weaveproxy.NewProxy(*proxyConfig) if err != nil { Log.Fatalf("Could not start proxy: %s", err) } @@ -268,7 +270,6 @@ func main() { listeners := proxy.Listen() proxy.AttachExistingContainers() go proxy.Serve(listeners, waitReady.Add()) - go proxy.ListenAndServeStatus("/home/weave/status.sock") } if pktdebug { @@ -441,6 +442,7 @@ func main() { HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, &waitReady) HandleHTTPPeer(muxRouter, allocator, discoveryEndpoint, token, name.String()) muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver)) + muxRouter.Methods("GET").Path("/proxyaddrs").HandlerFunc(proxy.StatusHTTP) http.Handle("/", common.LoggingHTTPHandler(muxRouter)) Log.Println("Listening for HTTP control messages on", httpAddr) go listenAndServeHTTP(httpAddr, nil) diff --git a/proxy/proxy.go b/proxy/proxy.go index 594ade9a..d4469b70 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -310,17 +310,6 @@ func (proxy *Proxy) Serve(listeners []net.Listener, ready func()) { } } -func (proxy *Proxy) ListenAndServeStatus(socket string) { - listener, err := weavenet.ListenUnixSocket(socket) - if err != nil { - Log.Fatalf("ListenAndServeStatus failed: %s", err) - } - handler := http.HandlerFunc(proxy.StatusHTTP) - if err := (&http.Server{Handler: handler}).Serve(listener); err != nil { - Log.Fatalf("ListenAndServeStatus failed: %s", err) - } -} - func (proxy *Proxy) StatusHTTP(w http.ResponseWriter, r *http.Request) { for _, addr := range proxy.normalisedAddrs { fmt.Fprintln(w, addr) diff --git a/weave b/weave index 4ea090b6..cfdf0b9d 100755 --- a/weave +++ b/weave @@ -661,19 +661,6 @@ http_call() { return $retval } -http_call_unix() { - container="$1" - socket="$2" - http_verb="$3" - url="$4" - shift 4 - # NB: requires curl >= 7.40 - output=$(docker exec $container curl -s -S -X $http_verb --unix-socket $socket "$@" http:$url) || return 1 - # in some docker versions, `docker exec` does not fail when the executed command fails - [ -n "$output" ] || return 1 - echo $output -} - call_weave() { TMPERR=/tmp/call_weave_err_$$ retval=0 @@ -1166,10 +1153,9 @@ proxy_args() { } proxy_addrs() { - if addr="$(http_call_unix $CONTAINER_NAME status.sock GET /status 2>/dev/null)" ; then + if addr="$(call_weave GET /proxyaddrs)" ; then echo "$addr" | sed "s/0.0.0.0/$PROXY_HOST/g" else - echo "$CONTAINER_NAME container is not present. Have you launched it?" >&2 return 1 fi } From 4f08879321ac0d22ae1ba932cb7d39cc2c82c0a8 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 15 May 2017 10:17:31 +0000 Subject: [PATCH 2/4] Multiple proxy addresses need to be all on one line For some reason the previous version was de-newlined by the shell and the new version isn't. Since I can't figure out the exact reason the shell is now behaving differently (man page says it depends on the quoting that is in effect) I brute-force it with 'tr'. --- weave | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weave b/weave index cfdf0b9d..29f080e0 100755 --- a/weave +++ b/weave @@ -1154,7 +1154,7 @@ proxy_args() { proxy_addrs() { if addr="$(call_weave GET /proxyaddrs)" ; then - echo "$addr" | sed "s/0.0.0.0/$PROXY_HOST/g" + echo "$addr" | sed "s/0.0.0.0/$PROXY_HOST/g" | tr '\n' ' ' else return 1 fi From 81d79a64e68ecc76a44a2d7220b2570cf119699e Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 15 May 2017 11:31:14 +0000 Subject: [PATCH 3/4] Blank proxy_addrs should be a failure --- weave | 1 + 1 file changed, 1 insertion(+) diff --git a/weave b/weave index 29f080e0..01e1dbb7 100755 --- a/weave +++ b/weave @@ -1154,6 +1154,7 @@ proxy_args() { proxy_addrs() { if addr="$(call_weave GET /proxyaddrs)" ; then + [ -n "$addr" ] || return 1 echo "$addr" | sed "s/0.0.0.0/$PROXY_HOST/g" | tr '\n' ' ' else return 1 From e0bb49aa23bedb4e8231671e1406af2e25cc0388 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 15 May 2017 11:32:20 +0000 Subject: [PATCH 4/4] Don't crash on nil proxy in StatusHTTP --- prog/weaver/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 8ab4efe1..7e7d5dcf 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -442,7 +442,9 @@ func main() { HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, &waitReady) HandleHTTPPeer(muxRouter, allocator, discoveryEndpoint, token, name.String()) muxRouter.Methods("GET").Path("/metrics").Handler(metricsHandler(router, allocator, ns, dnsserver)) - muxRouter.Methods("GET").Path("/proxyaddrs").HandlerFunc(proxy.StatusHTTP) + if proxy != nil { + muxRouter.Methods("GET").Path("/proxyaddrs").HandlerFunc(proxy.StatusHTTP) + } http.Handle("/", common.LoggingHTTPHandler(muxRouter)) Log.Println("Listening for HTTP control messages on", httpAddr) go listenAndServeHTTP(httpAddr, nil)