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 73b8361
Show file tree
Hide file tree
Showing 12 changed files with 1,431 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ such, the Scope app endpoint (port 4040) should not be made accessible on
the Internet. Additionally traffic between the app and the probe is currently
insecure and should not traverse the internet.

Scope will periodically check with our servers to see if a new version is
availible. To disable this, run:

```
CHECKPOINT_DISABLE=true scope launch
```

## <a name="architecture"></a>Architecture

Weave Scope consists of two components: the app and the probe. These two
Expand Down
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 available; 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
2 changes: 2 additions & 0 deletions scope
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ 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 \
-e CHECKPOINT_DISABLE \
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --probe.docker true "$@"
}

Expand Down
Loading

0 comments on commit 73b8361

Please sign in to comment.