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.
This commit is contained in:
Matthias Radestock committed 2015-06-09 14:03:52 +01:00
1 parent 2d70197221
commit fee2898c05
4 files changed
+38 -52

No files matched your search

+4
View File
@@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
"code.google.com/p/getopt" "code.google.com/p/getopt"
. "github.com/weaveworks/weave/common" . "github.com/weaveworks/weave/common"
@@ -48,6 +49,9 @@ func main() {
InitDefaultLogging(true) InitDefaultLogging(true)
} }
Info.Println("weave proxy", version)
Info.Println("Command line arguments:", strings.Join(os.Args[1:], " "))
p, err := proxy.NewProxy(c) p, err := proxy.NewProxy(c)
if err != nil { if err != nil {
Error.Fatalf("Could not start proxy: %s", err) Error.Fatalf("Could not start proxy: %s", err)
+1 -27
View File
@@ -1,14 +1,11 @@
package proxy package proxy
import ( import (
"bytes"
"crypto/tls" "crypto/tls"
"fmt"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"regexp" "regexp"
"strings"
"github.com/fsouza/go-dockerclient" "github.com/fsouza/go-dockerclient"
. "github.com/weaveworks/weave/common" . "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) proxy.serveWithInterceptor(&startContainerInterceptor{proxy.client, proxy.WithDNS, proxy.WithIPAM}, w, r)
case execCreateRegexp.MatchString(path): case execCreateRegexp.MatchString(path):
proxy.serveWithInterceptor(&createExecInterceptor{proxy.client, proxy.WithIPAM}, w, r) 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: default:
proxy.serveWithInterceptor(&nullInterceptor{}, w, r) 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) 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 { func (proxy *Proxy) ListenAndServe() error {
listener, err := net.Listen("tcp", proxy.ListenAddr) listener, err := net.Listen("tcp", proxy.ListenAddr)
if err != nil { if err != nil {
@@ -132,11 +108,9 @@ func (proxy *Proxy) ListenAndServe() error {
if proxy.TLSConfig.enabled() { if proxy.TLSConfig.enabled() {
listener = tls.NewListener(listener, proxy.TLSConfig.Config) listener = tls.NewListener(listener, proxy.TLSConfig.Config)
Info.Println("TLS Enabled")
} }
Info.Printf("Listening on %s", proxy.ListenAddr) Info.Println("proxy listening")
Info.Printf("Proxying %s", proxy.DockerAddr)
return (&http.Server{Handler: proxy}).Serve(listener) return (&http.Server{Handler: proxy}).Serve(listener)
} }
+2 -7
View File
@@ -206,16 +206,11 @@ The command
weave status weave status
reports on the current status of various weave components, including reports on the current status of various weave components, including
the proxy: the proxy, if it is running:
```` ````
... ...
weave proxy git-03ede29e7ee4 weave proxy is running
Listen address is :12375
Docker address is unix:///var/run/docker.sock
TLS off
DNS off
IPAM off
```` ````
Information on the operation of the proxy can be obtained from the Information on the operation of the proxy can be obtained from the
+31 -18
View File
@@ -562,11 +562,12 @@ http_call() {
http_call_ip $CONTAINER_IP "$@" http_call_ip $CONTAINER_IP "$@"
} }
# Wait until container $1 on IP $2, port $3 is alive enough to respond # Wait until container $1 is alive enough to respond to "GET /status"
# to its status call # http request on its docker-assigned IP, port $2
wait_for_status_ip() { wait_for_status() {
container_ip $1 "$1 container has died." "$1 container has died." || return 1
while true ; do 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 if ! container_id $1 >/dev/null 2>&1 ; then
echo "$1 container has died." >&2 echo "$1 container has died." >&2
return 1 return 1
@@ -575,9 +576,19 @@ wait_for_status_ip() {
done done
} }
wait_for_status() { # Wait until container $1 outputs a line containing $2 in its log
container_ip $1 "$1 container has died." "$1 container has died." || return 1 wait_for_log() {
wait_for_status_ip $1 $CONTAINER_IP $2 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 # 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 # Print an error to stderr and return with an indicative exit status
# if the weaveDNS container does not exist or isn't running. # if the container $1 does not exist or isn't running.
check_dns_running() { check_running() {
if ! STATUS=$(docker inspect --format='{{.State.Running}}' $DNS_CONTAINER_NAME 2>/dev/null); then if ! STATUS=$(docker inspect --format='{{.State.Running}}' $1 2>/dev/null); then
echo "$DNS_CONTAINER_NAME container is not present. Have you launched it?" >&2 echo "$1 container is not present. Have you launched it?" >&2
return 1 return 1
elif [ "$STATUS" != "true" ] ; then elif [ "$STATUS" != "true" ] ; then
echo "$DNS_CONTAINER_NAME container is not running." >&2 echo "$1 container is not running." >&2
return 2 return 2
fi fi
} }
# Execute $@ only if the weaveDNS container is running # Execute $@ only if the weaveDNS container is running
when_dns_running() { when_dns_running() {
if check_dns_running 2>/dev/null; then if check_running $DNS_CONTAINER_NAME 2>/dev/null; then
"$@" "$@"
fi fi
} }
@@ -940,7 +951,7 @@ case "$COMMAND" in
-e PROCFS=/hostproc \ -e PROCFS=/hostproc \
--entrypoint=/home/weave/weaveproxy \ --entrypoint=/home/weave/weaveproxy \
$WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $PROXY_ARGS) $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 echo $PROXY_CONTAINER
;; ;;
connect) connect)
@@ -960,8 +971,10 @@ case "$COMMAND" in
http_call $CONTAINER_NAME $HTTP_PORT GET /status || res=1 http_call $CONTAINER_NAME $HTTP_PORT GET /status || res=1
echo echo
http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status 2>/dev/null || true http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status 2>/dev/null || true
echo if check_running $PROXY_CONTAINER_NAME 2>/dev/null ; then
http_call_ip 127.0.0.1 $PROXY_PORT GET /status 2>/dev/null || true echo
echo "weave proxy is running"
fi
[ $res -eq 0 ] [ $res -eq 0 ]
;; ;;
ps) ps)
@@ -1040,7 +1053,7 @@ case "$COMMAND" in
collect_ip_args "$@" collect_ip_args "$@"
shift $IP_COUNT shift $IP_COUNT
[ $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) ] || usage [ $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) ] || usage
check_dns_running check_running $DNS_CONTAINER_NAME
CONTAINER=$(container_id $1) CONTAINER=$(container_id $1)
if [ $# -eq 1 ] ; then if [ $# -eq 1 ] ; then
with_container_fqdn $CONTAINER put_dns_fqdn $IP_ARGS with_container_fqdn $CONTAINER put_dns_fqdn $IP_ARGS
@@ -1052,7 +1065,7 @@ case "$COMMAND" in
collect_ip_args "$@" collect_ip_args "$@"
shift $IP_COUNT shift $IP_COUNT
[ $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) ] || usage [ $# -eq 1 -o \( $# -eq 3 -a "$2" = "-h" \) ] || usage
check_dns_running check_running $DNS_CONTAINER_NAME
CONTAINER=$(container_id $1) CONTAINER=$(container_id $1)
if [ $# -eq 1 ] ; then if [ $# -eq 1 ] ; then
delete_dns $CONTAINER $IP_ARGS delete_dns $CONTAINER $IP_ARGS