Skip to content

Commit

Permalink
Make getting the docker run command easier (in fewer lines).
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Oct 19, 2015
1 parent 36188a4 commit 8fecfa0
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions scope
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ 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 @@ -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
Expand All @@ -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
;;
Expand Down

0 comments on commit 8fecfa0

Please sign in to comment.