From 5d23432a6ce4662e0eb86e9dbe0d9ce8d1b005c7 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Mon, 4 Jul 2016 17:08:49 +0000 Subject: [PATCH] Check write access to unix socket --- scope | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scope b/scope index 0b58cf632..3859e9b61 100755 --- a/scope +++ b/scope @@ -34,6 +34,27 @@ WEAVESCOPE_DOCKER_ARGS=${WEAVESCOPE_DOCKER_ARGS:-} COMMAND=$1 shift 1 +check_docker_access() { + + # Extract socket path + DOCKER_SOCK_FILE="" + if [ -z "${DOCKER_HOST+x}" ]; then + DOCKER_SOCK_FILE="/var/run/docker.sock" + else + WITHOUT_PREFIX="${DOCKER_HOST#unix://}" + if [ "$WITHOUT_PREFIX" != "$DOCKER_HOST" ]; then + DOCKER_SOCK_FILE="$WITHOUT_PREFIX" + fi + fi + + + if [ \( -n "$DOCKER_SOCK_FILE" \) -a \( ! -w "$DOCKER_SOCK_FILE" \) ]; then + echo "ERROR: cannot write to docker socket: $DOCKER_SOCK_FILE" >&2 + echo "change socket permissions or try using sudo" + exit 1 + fi +} + # - The image embeds the weave script & Docker 1.3.1 client # - Docker versions prior to 1.5.0 do not support --pid=host # - Weave needs 1.6.0 now (image pulling changes) @@ -119,6 +140,8 @@ launch_app_command() { $WEAVESCOPE_DOCKER_ARGS $SCOPE_IMAGE --no-probe "$@" } +check_docker_access + check_docker_version case "$COMMAND" in