From 8e1a6b3667215fa3a825769ffd6b8a2796e0fbb0 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Mon, 27 Jun 2016 10:13:55 +0100 Subject: [PATCH] Add dry run flag to scope, so when launched we can check the args are valid. (#1609) * Add dry run flag to scope, so when launched we can check the args are valid. * Try and parse listen address and error early. * Specify that -dry-run is for internal use only. --- docker/entrypoint.sh | 5 ----- prog/main.go | 19 +++++++++++++++++++ scope | 11 +++++++++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 0e459ea61..ea4356e83 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -2,11 +2,6 @@ mkdir -p /var/run/weave -if [ "$1" = "version" -o "$1" = "help" ]; then - exec -a scope /home/weave/scope --mode $1 - exit 0 -fi - for arg in $@; do case "$arg" in --no-app|--probe-only|--service-token*|--probe.token*) diff --git a/prog/main.go b/prog/main.go index 41859f009..8e6c0bd6b 100644 --- a/prog/main.go +++ b/prog/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "net" "os" "strconv" "strings" @@ -116,11 +117,13 @@ func main() { mode string debug bool weaveHostname string + dryRun bool ) // Flags that apply to both probe and app flag.StringVar(&mode, "mode", "help", "For internal use.") flag.BoolVar(&debug, "debug", false, "Force debug logging.") + flag.BoolVar(&dryRun, "dry-run", false, "Don't start scope, just parse the arguments. For internal use only.") flag.StringVar(&weaveHostname, "weave.hostname", "", "Hostname to advertise/lookup in WeaveDNS") // We need to know how to parse them, but they are mainly interpreted by the entrypoint script. @@ -202,6 +205,22 @@ func main() { } flags.probe.noApp = *noApp || *probeOnly + // Special case for #1191, check listen address is well formed + _, _, err := net.SplitHostPort(flags.app.listen) + if err != nil { + log.Errorf("Invalid value for -app.http.address: %v", err) + } + if flags.probe.httpListen != "" { + _, _, err := net.SplitHostPort(flags.probe.httpListen) + if err != nil { + log.Errorf("Invalid value for -app.http.address: %v", err) + } + } + + if dryRun { + return + } + switch mode { case "app": appMain(flags.app) diff --git a/scope b/scope index 0b58cf632..d42969ad1 100755 --- a/scope +++ b/scope @@ -127,7 +127,8 @@ case "$COMMAND" in ;; version) - docker run --rm -e CHECKPOINT_DISABLE $SCOPE_IMAGE version + docker run --rm -e CHECKPOINT_DISABLE --entrypoint=/home/weave/scope \ + $WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --mode=version ;; help) @@ -138,7 +139,8 @@ scope help - Print this scope launch - Launch Scope EOF - docker run --rm -e CHECKPOINT_DISABLE $SCOPE_IMAGE help + docker run --rm -e CHECKPOINT_DISABLE --entrypoint=/home/weave/scope \ + $WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE -h cat >&2 </dev/null 2>&1 || true