diff --git a/README.md b/README.md index abd2a532..649e2d83 100644 --- a/README.md +++ b/README.md @@ -349,12 +349,9 @@ The log verbosity can be increased by supplying the `-debug` flag when launching weave. Be warned, this will log information on a per-packet basis, so can produce a lot of output. -One can ask a weave router to log a status report by sending it a USR1 -signal, e.g. +One can ask a weave router to report its status with - kill -USR1 `docker inspect --format='{{ .State.Pid }}' weave` - -and then inspect the logs. + weave status ## Installation with Boot2Docker diff --git a/consts.go b/consts.go index d682b0c7..e90a27ad 100644 --- a/consts.go +++ b/consts.go @@ -10,6 +10,7 @@ const ( EthernetOverhead = 14 UDPOverhead = 28 // 20 bytes for IPv4, 8 bytes for UDP Port = 6783 + StatusPort = Port + 1 DefaultPMTU = 65535 MaxUDPPacketSize = 65536 ChannelSize = 16 diff --git a/weaver/main.go b/weaver/main.go index 7edc2268..c0be4ea5 100644 --- a/weaver/main.go +++ b/weaver/main.go @@ -6,9 +6,11 @@ import ( "crypto/sha256" "flag" "fmt" + "io" "github.com/davecheney/profile" "log" "net" + "net/http" "os" "os/signal" "runtime" @@ -129,9 +131,22 @@ func main() { } }() } + go handleHttp(router) handleSignals(router) } +func handleHttp(router *weave.Router) { + http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, router.Status()) + }) + address := fmt.Sprintf(":%d", weave.StatusPort) + err := http.ListenAndServe(address, nil) + if err != nil { + log.Fatal("Unable to create http listener: ", err) + } +} + + func handleSignals(router *weave.Router) { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGQUIT, syscall.SIGUSR1) diff --git a/weaver/weave b/weaver/weave index 202b650b..4b323d7a 100755 --- a/weaver/weave +++ b/weaver/weave @@ -7,10 +7,17 @@ usage() { echo "weave run / ..." echo "weave expose /" echo "weave hide /" + echo "weave status" echo "weave stop" exit 1 } +# utility function to check whether a command can be executed by the shell +# see http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script +command_exists () { + command -v $1 >/dev/null 2>&1 +} + [ `id -u` = 0 ] || { echo "weave must be run as 'root'" exit 1 @@ -71,6 +78,22 @@ case "$COMMAND" in echo $CONTAINER IFACE=eth0 ;; + status) + DOCKERIP=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' weave) + if [ -z "$DOCKERIP" ] ; then + echo "The weave container is not running." >&2 + exit 1 + fi + if command_exists wget ; then + wget -O - -q $DOCKERIP:6784/status + elif command_exists curl ; then + curl $DOCKERIP:6784/status + else + echo "Cannot find wget or curl. Install one of them for 'weave status' to function." >&2 + exit 1 + fi + exit 0 + ;; run) [ $# -gt 0 ] || usage IPADDR=$1 @@ -103,7 +126,7 @@ case "$COMMAND" in stop) docker kill weave > /dev/null docker rm weave > /dev/null - if command -v conntrack >/dev/null 2>&1 + if command_exists conntrack then conntrack -D -p udp --dport 6783 >/dev/null 2>&1 else @@ -145,7 +168,7 @@ ip netns exec $NSPID ip link set $GUEST_IFNAME name $CONTAINER_IFNAME ip netns exec $NSPID ip addr add $IPADDR dev $CONTAINER_IFNAME ip netns exec $NSPID ip link set $CONTAINER_IFNAME up -if command -v ethtool >/dev/null 2>&1 +if command_exists ethtool then ip netns exec $NSPID ethtool -K $IFACE tx off > /dev/null else