Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dry run flag to scope, so when launched we can check the args are valid. #1609

Merged
merged 3 commits into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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*)
Expand Down
19 changes: 19 additions & 0 deletions prog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"net"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions scope
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 <<EOF

Expand All @@ -150,6 +152,11 @@ EOF
;;

launch)
# Do a dry run of scope in the foreground, so it can parse args etc
# avoiding the entrypoint script in the process.
docker run --rm -e CHECKPOINT_DISABLE --entrypoint=/home/weave/scope \
$WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --dry-run $@

if ! check_docker_for_mac || check_probe_only ; then
check_not_running $SCOPE_CONTAINER_NAME $SCOPE_IMAGE_NAME
docker rm -f $SCOPE_CONTAINER_NAME >/dev/null 2>&1 || true
Expand Down