Skip to content

Commit

Permalink
Periodically check for newer versions of scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwilkie committed Feb 4, 2016
1 parent 6e4e542 commit 79b73de
Show file tree
Hide file tree
Showing 11 changed files with 1,423 additions and 0 deletions.
14 changes: 14 additions & 0 deletions prog/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/weaveworks/go-checkpoint"
"github.com/weaveworks/weave/common"

"github.com/weaveworks/scope/app"
Expand Down Expand Up @@ -42,6 +43,19 @@ func appMain() {

defer log.Print("app exiting")

// Start background version checking
params := checkpoint.CheckParams{
Product: "scope-app",
Version: app.Version,
SignatureFile: signatureFile,
}
checkpoint.CheckInterval(&params, 2*60*time.Minute, func(r *checkpoint.CheckResponse, err error) {
if r.Outdated {
log.Printf("Scope version %s is availible; please update at %s",
r.CurrentVersion, r.CurrentDownloadURL)
}
})

rand.Seed(time.Now().UnixNano())
app.UniqueID = strconv.FormatInt(rand.Int63(), 16)
app.Version = version
Expand Down
27 changes: 27 additions & 0 deletions prog/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/armon/go-metrics"
"github.com/weaveworks/go-checkpoint"
"github.com/weaveworks/weave/common"

"github.com/weaveworks/scope/common/hostname"
Expand All @@ -30,6 +31,31 @@ import (
"github.com/weaveworks/scope/report"
)

const (
signatureFile = "/etc/weave/signature"
)

func check() {
handleResponse := func(r *checkpoint.CheckResponse, err error) {
if err != nil {
log.Printf("Error checking version: %v", err)
} else if r.Outdated {
log.Printf("Scope version %s is availible; please update at %s",
r.CurrentVersion, r.CurrentDownloadURL)
}
}

// Start background version checking
params := checkpoint.CheckParams{
Product: "scope-probe",
Version: version,
SignatureFile: signatureFile,
}
resp, err := checkpoint.Check(&params)
handleResponse(resp, err)
checkpoint.CheckInterval(&params, 2*60*time.Minute, handleResponse)
}

// Main runs the probe
func probeMain() {
var (
Expand Down Expand Up @@ -77,6 +103,7 @@ func probeMain() {
hostID = hostName // TODO(pb): we should sanitize the hostname
)
log.Printf("probe starting, version %s, ID %s", version, probeID)
go check()

addrs, err := net.InterfaceAddrs()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions scope
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ check_not_running() {
launch_command() {
echo docker run --privileged -d --name=$SCOPE_CONTAINER_NAME --net=host --pid=host \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /etc/weave:/etc/weave \
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --probe.docker true "$@"
}

Expand Down
Loading

0 comments on commit 79b73de

Please sign in to comment.