diff --git a/scope b/scope index 0d31881fc6..7b1a8e531c 100755 --- a/scope +++ b/scope @@ -25,10 +25,6 @@ IP_REGEXP="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" IP_ADDR_CMD="find /sys/class/net -type l | xargs -n1 basename | grep -vE 'docker|veth|lo' | \ xargs -n1 ip addr show | grep inet | awk '{ print \$2 }' | grep -oE '$IP_REGEXP'" WEAVESCOPE_DOCKER_ARGS=${WEAVESCOPE_DOCKER_ARGS:-} -DOCKER=docker -if [ -n "${DRY_RUN+x}" ]; then - DOCKER="echo docker" -fi [ $# -gt 0 ] || usage COMMAND=$1 @@ -36,7 +32,7 @@ shift 1 # Check that a container named $1 with image $2 is not running check_not_running() { - case $($DOCKER inspect --format='{{.State.Running}} {{.Config.Image}}' $1 2>/dev/null) in + case $(docker inspect --format='{{.State.Running}} {{.Config.Image}}' $1 2>/dev/null) in "true $2") echo "$1 is already running." >&2 exit 1 @@ -62,26 +58,26 @@ check_not_running() { esac } +launch_command() { + echo docker run --privileged -d --name=$SCOPE_CONTAINER_NAME --net=host --pid=host \ + -v /var/run/docker.sock:/var/run/docker.sock \ + $WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --probe.docker true "$@" +} + case "$COMMAND" in command) - DRY_RUN=true $0 launch + launch_command "$@" ;; launch) check_not_running $SCOPE_CONTAINER_NAME $SCOPE_IMAGE - DOCKER rm -f $SCOPE_CONTAINER_NAME >/dev/null 2>&1 || true + docker rm -f $SCOPE_CONTAINER_NAME >/dev/null 2>&1 || true - - CONTAINER=$($DOCKER run --privileged -d --name=$SCOPE_CONTAINER_NAME --net=host --pid=host \ - -v /var/run/docker.sock:/var/run/docker.sock \ - $WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --probe.docker true "$@") + CONTAINER=$($(launch_command "$@")) echo $CONTAINER - if [ -n "${DRY_RUN+x}" ]; then - exit 0 - fi if ! echo "$@" | grep -E "\-\-no\-app|\-\-service\-token" 1>/dev/null; then - IP_ADDRS=$($DOCKER run --rm --net=host --entrypoint /bin/sh $SCOPE_IMAGE -c "$IP_ADDR_CMD") + IP_ADDRS=$(docker run --rm --net=host --entrypoint /bin/sh $SCOPE_IMAGE -c "$IP_ADDR_CMD") echo "Weave Scope is reachable at the following URL(s):" >&2 for ip in $IP_ADDRS; do echo " * http://$ip:4040/" >&2 @@ -91,7 +87,7 @@ case "$COMMAND" in stop) [ $# -eq 0 ] || usage - if ! $DOCKER stop $SCOPE_CONTAINER_NAME >/dev/null 2>&1 ; then + if ! docker stop $SCOPE_CONTAINER_NAME >/dev/null 2>&1 ; then echo "Weave Scope is not running." >&2 fi ;;