From 04ca3d24697760e86beaee74d1a8fdee730aa190 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 4 Sep 2014 14:44:42 +0100 Subject: [PATCH] Addressed various points raised in review: error-handling, simplified Fprint call --- weaver/main.go | 8 ++++++-- weaver/weave | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/weaver/main.go b/weaver/main.go index b9cd3670..38c234af 100644 --- a/weaver/main.go +++ b/weaver/main.go @@ -6,6 +6,7 @@ import ( "crypto/sha256" "flag" "fmt" + "io" "github.com/davecheney/profile" "log" "net" @@ -136,10 +137,13 @@ func main() { func handleHttp(router *weave.Router) { http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, router.Status()) + io.WriteString(w, router.Status()) }) address := fmt.Sprintf(":%d", weave.StatusPort) - http.ListenAndServe(address, nil) + err := http.ListenAndServe(address, nil) + if err != nil { + log.Fatal("ListenAndServe: ", err) + } } diff --git a/weaver/weave b/weaver/weave index d6c208bb..0ef1e761 100755 --- a/weaver/weave +++ b/weaver/weave @@ -80,16 +80,19 @@ case "$COMMAND" in ;; 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 "weave status needs either curl or wget to function" >&2 + echo "Cannot find wget or curl. Install one of them for 'weave status' to function." >&2 exit 1 fi - # return the status from the wget or curl command, so if they fail then we fail. - exit $? + exit 0 ;; run) [ $# -gt 0 ] || usage