Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #878 from rade/877_remove_proxy_status
Browse files Browse the repository at this point in the history
remove most of proxy status
  • Loading branch information
paulbellamy committed Jun 9, 2015
2 parents 2d70197 + fee2898 commit 03fa95f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 52 deletions.
4 changes: 4 additions & 0 deletions prog/weaveproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strings"

"code.google.com/p/getopt"
. "github.com/weaveworks/weave/common"
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 1 addition & 27 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 {
Expand All @@ -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)
}
9 changes: 2 additions & 7 deletions site/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 31 additions & 18 deletions weave
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 03fa95f

Please sign in to comment.