Merge pull request #750 from weaveworks/749-version

Rationalise version handling
This commit is contained in:
Paul Bellamy
2015-12-11 13:43:10 +00:00
5 changed files with 18 additions and 19 deletions

View File

@@ -68,6 +68,11 @@ mkdir -p /etc/weave
APP_ARGS=""
PROBE_ARGS=""
if [ "$1" = version ]; then
/home/weave/scope version
exit 0
fi
while true; do
case "$1" in
--app.*)

View File

@@ -2,7 +2,6 @@ package main
import (
"flag"
"fmt"
"log"
"math/rand"
"net/http"
@@ -32,18 +31,12 @@ func router(c app.Collector) *mux.Router {
// Main runs the app
func appMain() {
var (
window = flag.Duration("window", 15*time.Second, "window")
listen = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address")
logPrefix = flag.String("log.prefix", "<app>", "prefix for each log line")
printVersion = flag.Bool("version", false, "print version number and exit")
window = flag.Duration("window", 15*time.Second, "window")
listen = flag.String("http.address", ":"+strconv.Itoa(xfer.AppPort), "webserver listen address")
logPrefix = flag.String("log.prefix", "<app>", "prefix for each log line")
)
flag.Parse()
if *printVersion {
fmt.Println(app.Version)
return
}
if !strings.HasSuffix(*logPrefix, " ") {
*logPrefix += " "
}
@@ -53,6 +46,7 @@ func appMain() {
rand.Seed(time.Now().UnixNano())
app.UniqueID = strconv.FormatInt(rand.Int63(), 16)
app.Version = version
log.Printf("app starting, version %s, ID %s", app.Version, app.UniqueID)
http.Handle("/", router(app.NewCollector(*window)))
go func() {

View File

@@ -5,8 +5,10 @@ import (
"os"
)
var version = "dev" // set at build time
func usage() {
fmt.Fprintf(os.Stderr, "usage: %s (app|probe) args...\n", os.Args[0])
fmt.Fprintf(os.Stderr, "usage: %s (app|probe|version) args...\n", os.Args[0])
os.Exit(1)
}
@@ -23,6 +25,8 @@ func main() {
appMain()
case "probe":
probeMain()
case "version":
fmt.Println("Weave Scope version", version)
default:
usage()
}

View File

@@ -29,8 +29,6 @@ import (
"github.com/weaveworks/scope/xfer"
)
var version = "dev" // set at build time
// Main runs the probe
func probeMain() {
var (
@@ -48,18 +46,12 @@ func probeMain() {
kubernetesInterval = flag.Duration("kubernetes.interval", 10*time.Second, "how often to do a full resync of the kubernetes data")
weaveRouterAddr = flag.String("weave.router.addr", "", "IP address or FQDN of the Weave router")
procRoot = flag.String("proc.root", "/proc", "location of the proc filesystem")
printVersion = flag.Bool("version", false, "print version number and exit")
useConntrack = flag.Bool("conntrack", true, "also use conntrack to track connections")
insecure = flag.Bool("insecure", false, "(SSL) explicitly allow \"insecure\" SSL connections and transfers")
logPrefix = flag.String("log.prefix", "<probe>", "prefix for each log line")
)
flag.Parse()
if *printVersion {
fmt.Println(version)
return
}
// Setup in memory metrics sink
inm := metrics.NewInmemSink(time.Minute, 2*time.Minute)
sig := metrics.DefaultInmemSignal(inm)

4
scope
View File

@@ -102,6 +102,10 @@ case "$COMMAND" in
launch_command "$@"
;;
version)
docker run $SCOPE_IMAGE version
;;
launch)
check_not_running $SCOPE_CONTAINER_NAME $SCOPE_IMAGE_NAME
docker rm -f $SCOPE_CONTAINER_NAME >/dev/null 2>&1 || true