From fee2898c05eb86b276d90ff7fa009cfccc67bad5 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 8 Jun 2015 21:19:18 +0100 Subject: [PATCH] remove detailed proxy status There are two problems with obtaining the proxy status via the normal proxy endpoint... 1. when TLS is enabled, this requires using TLS at the client end 2. the status URL is mixed in with the docker remote API, which is rather unclean There is limited value to having some status output from the proxy, since all the output is constant. So instead we log the version and command line args, and in `weave status` only report whether the proxy is running. We still want a way to wait for the proxy to start up, and log a nice error if it dies. We do this by polling the docker logs for a startup message. Fixes #877. Fixes #876. Undoes most of #756, #800, #854. --- prog/weaveproxy/main.go | 4 ++++ proxy/proxy.go | 28 +---------------------- site/proxy.md | 9 ++------ weave | 49 ++++++++++++++++++++++++++--------------- 4 files changed, 38 insertions(+), 52 deletions(-) diff --git a/prog/weaveproxy/main.go b/prog/weaveproxy/main.go index bc19d365..836beeb7 100644 --- a/prog/weaveproxy/main.go +++ b/prog/weaveproxy/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "strings" "code.google.com/p/getopt" . "github.com/weaveworks/weave/common" @@ -48,6 +49,9 @@ func main() { InitDefaultLogging(true) } + Info.Println("weave proxy", version) + Info.Println("Command line arguments:", strings.Join(os.Args[1:], " ")) + p, err := proxy.NewProxy(c) if err != nil { Error.Fatalf("Could not start proxy: %s", err) diff --git a/proxy/proxy.go b/proxy/proxy.go index 83ac1313..c351fac5 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -1,14 +1,11 @@ package proxy import ( - "bytes" "crypto/tls" - "fmt" "net" "net/http" "net/url" "regexp" - "strings" "github.com/fsouza/go-dockerclient" . "github.com/weaveworks/weave/common" @@ -94,9 +91,6 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { proxy.serveWithInterceptor(&startContainerInterceptor{proxy.client, proxy.WithDNS, proxy.WithIPAM}, w, r) case execCreateRegexp.MatchString(path): proxy.serveWithInterceptor(&createExecInterceptor{proxy.client, proxy.WithIPAM}, w, r) - case strings.HasPrefix(path, "/status"): - fmt.Fprintln(w, "weave proxy", proxy.Version) - fmt.Fprintln(w, proxy.Status()) default: proxy.serveWithInterceptor(&nullInterceptor{}, w, r) } @@ -106,24 +100,6 @@ func (proxy *Proxy) serveWithInterceptor(i interceptor, w http.ResponseWriter, r newClient(proxy.dial, i).ServeHTTP(w, r) } -// Return status string -func (proxy *Proxy) Status() string { - var buf bytes.Buffer - fmt.Fprintln(&buf, "Listen address is", proxy.ListenAddr) - fmt.Fprintln(&buf, "Docker address is", proxy.DockerAddr) - switch { - case proxy.TLSConfig.Verify: - fmt.Fprintln(&buf, "TLS verify") - case proxy.TLSConfig.Enabled: - fmt.Fprintln(&buf, "TLS on") - default: - fmt.Fprintln(&buf, "TLS off") - } - fmt.Fprintln(&buf, "DNS", OnOff(proxy.WithDNS)) - fmt.Fprintln(&buf, "IPAM", OnOff(proxy.WithIPAM)) - return buf.String() -} - func (proxy *Proxy) ListenAndServe() error { listener, err := net.Listen("tcp", proxy.ListenAddr) if err != nil { @@ -132,11 +108,9 @@ func (proxy *Proxy) ListenAndServe() error { if proxy.TLSConfig.enabled() { listener = tls.NewListener(listener, proxy.TLSConfig.Config) - Info.Println("TLS Enabled") } - Info.Printf("Listening on %s", proxy.ListenAddr) - Info.Printf("Proxying %s", proxy.DockerAddr) + Info.Println("proxy listening") return (&http.Server{Handler: proxy}).Serve(listener) } diff --git a/site/proxy.md b/site/proxy.md index fa40d04b..1dc35801 100644 --- a/site/proxy.md +++ b/site/proxy.md @@ -206,16 +206,11 @@ The command weave status reports on the current status of various weave components, including -the proxy: +the proxy, if it is running: ```` ... -weave proxy git-03ede29e7ee4 -Listen address is :12375 -Docker address is unix:///var/run/docker.sock -TLS off -DNS off -IPAM off +weave proxy is running ```` Information on the operation of the proxy can be obtained from the diff --git a/weave b/weave index 6df73cf9..26f631cb 100755 --- a/weave +++ b/weave @@ -562,11 +562,12 @@ http_call() { http_call_ip $CONTAINER_IP "$@" } -# Wait until container $1 on IP $2, port $3 is alive enough to respond -# to its status call -wait_for_status_ip() { +# Wait until container $1 is alive enough to respond to "GET /status" +# http request on its docker-assigned IP, port $2 +wait_for_status() { + container_ip $1 "$1 container has died." "$1 container has died." || return 1 while true ; do - http_call_ip $2 $3 GET /status >/dev/null && return 0 + http_call_ip $CONTAINER_IP $2 GET /status >/dev/null && return 0 if ! container_id $1 >/dev/null 2>&1 ; then echo "$1 container has died." >&2 return 1 @@ -575,9 +576,19 @@ wait_for_status_ip() { done } -wait_for_status() { - container_ip $1 "$1 container has died." "$1 container has died." || return 1 - wait_for_status_ip $1 $CONTAINER_IP $2 +# Wait until container $1 outputs a line containing $2 in its log +wait_for_log() { + fifo=/tmp/tmpfifo.$$ + mkfifo $fifo || exit 1 + docker logs -f $1 2>/dev/null >$fifo & + res=0 + grep -q "$2" $fifo || res=1 + kill $! 2>/dev/null || true + rm $fifo + if [ $res -eq 1 ] ; then + echo "$1 container has died." >&2 + fi + return $res } # Call $1 for all containers, passing container ID, all MACs and all IPs @@ -643,20 +654,20 @@ dns_args() { } # Print an error to stderr and return with an indicative exit status -# if the weaveDNS container does not exist or isn't running. -check_dns_running() { - if ! STATUS=$(docker inspect --format='{{.State.Running}}' $DNS_CONTAINER_NAME 2>/dev/null); then - echo "$DNS_CONTAINER_NAME container is not present. Have you launched it?" >&2 +# if the container $1 does not exist or isn't running. +check_running() { + if ! STATUS=$(docker inspect --format='{{.State.Running}}' $1 2>/dev/null); then + echo "$1 container is not present. Have you launched it?" >&2 return 1 elif [ "$STATUS" != "true" ] ; then - echo "$DNS_CONTAINER_NAME container is not running." >&2 + echo "$1 container is not running." >&2 return 2 fi } # Execute $@ only if the weaveDNS container is running when_dns_running() { - if check_dns_running 2>/dev/null; then + if check_running $DNS_CONTAINER_NAME 2>/dev/null; then "$@" fi } @@ -940,7 +951,7 @@ case "$COMMAND" in -e PROCFS=/hostproc \ --entrypoint=/home/weave/weaveproxy \ $WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $PROXY_ARGS) - wait_for_status_ip $PROXY_CONTAINER_NAME 127.0.0.1 $PROXY_PORT + wait_for_log $PROXY_CONTAINER_NAME "proxy listening" echo $PROXY_CONTAINER ;; connect) @@ -960,8 +971,10 @@ case "$COMMAND" in http_call $CONTAINER_NAME $HTTP_PORT GET /status || res=1 echo http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status 2>/dev/null || true - echo - http_call_ip 127.0.0.1 $PROXY_PORT GET /status 2>/dev/null || true + if check_running $PROXY_CONTAINER_NAME 2>/dev/null ; then + echo + echo "weave proxy is running" + fi [ $res -eq 0 ] ;; ps) @@ -1040,7 +1053,7 @@ case "$COMMAND" in collect_ip_args "$@" shift $IP_COUNT [ $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) ] || usage - check_dns_running + check_running $DNS_CONTAINER_NAME CONTAINER=$(container_id $1) if [ $# -eq 1 ] ; then with_container_fqdn $CONTAINER put_dns_fqdn $IP_ARGS @@ -1052,7 +1065,7 @@ case "$COMMAND" in collect_ip_args "$@" shift $IP_COUNT [ $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) ] || usage - check_dns_running + check_running $DNS_CONTAINER_NAME CONTAINER=$(container_id $1) if [ $# -eq 1 ] ; then delete_dns $CONTAINER $IP_ARGS