diff --git a/README.md b/README.md index 9b099f716c..1aaabfde3a 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,9 @@ Weave Net respects the environment variable `DOCKER_HOST`, so you can run it locally to control a weave network on a remote host. Weave Net will periodically check with our servers to see if a new version is available. -New versions are announced in the log. To disable this, run: +New versions are announced in the log and in +[the status summary](http://docs.weave.works/weave/latest_release/troubleshooting.html#weave-status). +To disable this, run: ``` CHECKPOINT_DISABLE=true weave launch diff --git a/prog/weaver/http.go b/prog/weaver/http.go index 57945539d3..d7a6605eeb 100644 --- a/prog/weaver/http.go +++ b/prog/weaver/http.go @@ -7,10 +7,12 @@ import ( "net/http" "strings" "text/template" + "time" "github.com/gorilla/mux" "github.com/weaveworks/mesh" + "github.com/weaveworks/go-checkpoint" "github.com/weaveworks/weave/ipam" "github.com/weaveworks/weave/nameserver" "github.com/weaveworks/weave/net/address" @@ -116,6 +118,19 @@ var rootTemplate = template.New("root").Funcs(map[string]interface{}{ "trimSuffix": strings.TrimSuffix, }) +func (v *VersionCheck) String() string { + switch { + case !v.Enabled: + return "version check update disabled" + case v.NewVersion != "": + return fmt.Sprintf("version %s available - please upgrade!", + v.NewVersion) + default: + return fmt.Sprintf("up to date; next check at %s", + v.NextCheckAt.Format("2006/01/02 15:04:05")) + } +} + // Print counts in a specified order func printCounts(counts map[string]int, keys []string) string { var stringCounts []string @@ -138,7 +153,7 @@ func defTemplate(name string, text string) *template.Template { } var statusTemplate = defTemplate("status", `\ - Version: {{.Version}} + Version: {{.Version}} ({{.VersionCheck}}) Service: router Protocol: {{.Router.Protocol}} \ @@ -217,17 +232,42 @@ var dnsEntriesTemplate = defTemplate("dnsEntries", `\ var ipamTemplate = defTemplate("ipamTemplate", `{{printIPAMRanges .Router .IPAM}}`) +type VersionCheck struct { + Enabled bool + NewVersion string + NextCheckAt time.Time +} + type WeaveStatus struct { - Version string - Router *weave.NetworkRouterStatus `json:"Router,omitempty"` - IPAM *ipam.Status `json:"IPAM,omitempty"` - DNS *nameserver.Status `json:"DNS,omitempty"` + Version string + VersionCheck *VersionCheck `json:"VersionCheck,omitempty"` + Router *weave.NetworkRouterStatus `json:"Router,omitempty"` + IPAM *ipam.Status `json:"IPAM,omitempty"` + DNS *nameserver.Status `json:"DNS,omitempty"` +} + +func versionCheck() *VersionCheck { + v := &VersionCheck{ + Enabled: true, + NewVersion: "", + } + + if checkpoint.IsCheckDisabled() { + v.Enabled = false + return v + } + + v.NewVersion = newVersion.Load().(string) + v.NextCheckAt = checker.NextCheckAt() + + return v } func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRouter, allocator *ipam.Allocator, defaultSubnet address.CIDR, ns *nameserver.Nameserver, dnsserver *nameserver.DNSServer) { status := func() WeaveStatus { return WeaveStatus{ version, + versionCheck(), weave.NewNetworkRouterStatus(router), ipam.NewStatus(allocator, defaultSubnet), nameserver.NewStatus(ns, dnsserver)} @@ -279,5 +319,4 @@ func HandleHTTP(muxRouter *mux.Router, version string, router *weave.NetworkRout defHandler("/status/peers", peersTemplate) defHandler("/status/dns", dnsEntriesTemplate) defHandler("/status/ipam", ipamTemplate) - } diff --git a/prog/weaver/main.go b/prog/weaver/main.go index cb2971175f..2f6a86b4ba 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -8,6 +8,7 @@ import ( "os" "runtime" "strings" + "sync/atomic" "time" "github.com/davecheney/profile" @@ -27,6 +28,8 @@ import ( ) var version = "(unreleased version)" +var checker *checkpoint.Checker +var newVersion atomic.Value var Log = common.Log @@ -51,10 +54,15 @@ const ( ) func checkForUpdates() { + newVersion.Store("") + handleResponse := func(r *checkpoint.CheckResponse, err error) { if err != nil { Log.Printf("Error checking version: %v", err) - } else if r.Outdated { + return + } + if r.Outdated { + newVersion.Store(r.CurrentVersion) Log.Printf("Weave version %s is available; please update at %s", r.CurrentVersion, r.CurrentDownloadURL) } @@ -66,9 +74,7 @@ func checkForUpdates() { Version: version, SignatureFile: "", } - resp, err := checkpoint.Check(¶ms) - handleResponse(resp, err) - checkpoint.CheckInterval(¶ms, updateCheckPeriod, handleResponse) + checker = checkpoint.CheckInterval(¶ms, updateCheckPeriod, handleResponse) } func (c ipamConfig) Enabled() bool { @@ -183,7 +189,7 @@ func main() { Log.Println("Command line options:", options()) - go checkForUpdates() + checkForUpdates() if prof != "" { p := *profile.CPUProfile diff --git a/site/troubleshooting.md b/site/troubleshooting.md index 3a50e724b5..a891d4cacd 100644 --- a/site/troubleshooting.md +++ b/site/troubleshooting.md @@ -48,7 +48,7 @@ A status summary can be obtained using `weave status`: ```` $ weave status - Version: 1.1.0 + Version: 1.1.0 (up to date; next check at 2016/04/06 12:30:00) Service: router Protocol: weave 1..2 @@ -80,7 +80,9 @@ $ weave status The terms used here are explained further at [How Weave Net Works](/site/router-topology/overview.md). - * **Version** - shows the Weave Net version. + * **Version** - shows the Weave Net version. If checkpoint is enabled (i.e. +`CHECKPOINT_DISABLE` is not set), information about existence of a new version +will be shown. * **Protocol**- indicates the Weave Router inter-peer communication protocol name and supported versions (min..max). diff --git a/test/700_status_and_report_test.sh b/test/700_status_and_report_test.sh index 1e0ee15471..4fe64750fc 100755 --- a/test/700_status_and_report_test.sh +++ b/test/700_status_and_report_test.sh @@ -26,4 +26,19 @@ weave_on $HOST1 connect 10.2.2.1 assert "weave_on $HOST1 status targets" "10.2.2.1" assert "weave_on $HOST1 status connections | tr -s ' ' | cut -d ' ' -f 2" "10.2.2.1:6783" +assert "weave_on $HOST1 report -f '{{.VersionCheck.Enabled}}'" "false" +assert_raises "weave_on $HOST1 status | grep 'version check update disabled'" + +weave_on $HOST1 reset + +CHECKPOINT_DISABLE="" weave_on $HOST1 launch +assert "weave_on $HOST1 report -f '{{.VersionCheck.Enabled}}'" "true" + +NEW_VSN=$(weave_on $HOST1 report -f "{{.VersionCheck.NewVersion}}") +if [ -z "$NEW_VSN" ]; then + assert_raises "weave_on $HOST1 status | grep 'up to date; next check at '" +else + assert_raises "weave_on $HOST1 status | grep \"version $NEW_VSN available - please upgrade!\"" +fi + end_suite diff --git a/test/config.sh b/test/config.sh index 63f02ae3af..1997180b62 100644 --- a/test/config.sh +++ b/test/config.sh @@ -44,6 +44,8 @@ CHECK_ETHWE_MISSING="test ! -d /sys/class/net/ethwe" DOCKER_PORT=2375 +CHECKPOINT_DISABLE=true + upload_executable() { host=$1 file=$2 @@ -118,7 +120,7 @@ weave_on() { host=$1 shift 1 [ -z "$DEBUG" ] || greyly echo "Weave on $host:$DOCKER_PORT: $@" >&2 - CHECKPOINT_DISABLE=true DOCKER_HOST=tcp://$host:$DOCKER_PORT $WEAVE "$@" + CHECKPOINT_DISABLE="$CHECKPOINT_DISABLE" DOCKER_HOST=tcp://$host:$DOCKER_PORT $WEAVE "$@" } stop_router_on() { diff --git a/vendor/github.com/weaveworks/go-checkpoint b/vendor/github.com/weaveworks/go-checkpoint index d99cc14f13..7bed3b8c61 160000 --- a/vendor/github.com/weaveworks/go-checkpoint +++ b/vendor/github.com/weaveworks/go-checkpoint @@ -1 +1 @@ -Subproject commit d99cc14f13e7845b370a7dc81d47cafb29cdc97f +Subproject commit 7bed3b8c619aa2df29a3c6771e0e25c8675881c1