Skip to content

Commit

Permalink
Make getting the docker run comment easier.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie committed Oct 12, 2015
1 parent 5e817e4 commit 36188a4
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions scope
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ usage() {
echo "Usage:"
echo "scope launch [<peer> ...]"
echo "scope stop"
echo "scope command"
echo
echo "scope <peer> is of the form <ip_address_or_fqdn>[:<port>]"
exit 1
Expand All @@ -24,14 +25,18 @@ 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
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
Expand All @@ -58,18 +63,25 @@ check_not_running() {
}

case "$COMMAND" in
command)
DRY_RUN=true $0 launch
;;

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 \

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 "$@")
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
Expand All @@ -79,7 +91,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
;;
Expand Down

0 comments on commit 36188a4

Please sign in to comment.