mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-19 04:16:21 +00:00
Decouple Scope lifecycle from Weave lifecycle
- Run the Weave integrations regardless of if weave is detected. - Make everything backoff and not spam the logs. - Add miekg dns to vendor. - Have the app periodically register with weaveDNS, and the probe do lookups there. - Decide what the local networks are at runtime, not once at startup. - Correctly resolve app ids, fixes #825
This commit is contained in:
+4
-90
@@ -5,65 +5,6 @@ usage() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
# This script exists to modify the network settings in the scope containers
|
||||
# as docker doesn't allow it when started with --net=host
|
||||
|
||||
WEAVE_CONTAINER_NAME=weave
|
||||
DOCKER_BRIDGE=docker0
|
||||
HOSTNAME=scope
|
||||
DOMAIN=weave.local
|
||||
IP_REGEXP="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
|
||||
|
||||
container_ip() {
|
||||
if ! status=$(docker inspect --format='{{.State.Running}} {{.HostConfig.NetworkMode}}' $1 2>/dev/null); then
|
||||
echo "Container $1 not found" >&2
|
||||
return 1
|
||||
fi
|
||||
case "$status" in
|
||||
"true host")
|
||||
CONTAINER_IP="127.0.0.1"
|
||||
return 0
|
||||
;;
|
||||
"true default" | "true bridge")
|
||||
CONTAINER_IP="$(docker inspect --format='{{.NetworkSettings.IPAddress}}' $1 2>/dev/null)"
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
echo "Container $1 not running" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
is_running() {
|
||||
status=$(docker inspect --format='{{.State.Running}}' $1 2>/dev/null) && [ "$status" = "true" ]
|
||||
return $?
|
||||
}
|
||||
|
||||
docker_bridge_ip() {
|
||||
local DOCKER_BRIDGE_IP=$(ip -f inet address show dev $DOCKER_BRIDGE | grep -m1 -o 'inet \([.0-9]\)*')
|
||||
echo ${DOCKER_BRIDGE_IP#inet }
|
||||
}
|
||||
|
||||
# Run `weave` in the weave exec container
|
||||
weave() {
|
||||
WEAVEXEC_IMAGE=$(docker inspect --format='{{.Config.Image}}' weave | sed 's/\/weave/\/weaveexec/')
|
||||
docker run -t --rm --privileged --net=host \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v /proc:/hostproc \
|
||||
-e PROCFS=/hostproc \
|
||||
$WEAVEXEC_IMAGE --local "$@"
|
||||
}
|
||||
|
||||
# Run `weave expose` if it's not already exposed.
|
||||
weave_expose() {
|
||||
status=$(weave ps weave:expose | awk '{print $3}' 2>/dev/null)
|
||||
if [ "$status" = "" ]; then
|
||||
echo "Exposing host to weave network."
|
||||
weave expose
|
||||
fi
|
||||
}
|
||||
|
||||
mkdir -p /etc/weave
|
||||
APP_ARGS=""
|
||||
PROBE_ARGS=""
|
||||
@@ -88,14 +29,14 @@ while true; do
|
||||
fi
|
||||
APP_ARGS="$APP_ARGS -$ARG_NAME=$ARG_VALUE"
|
||||
;;
|
||||
--debug)
|
||||
--debug)
|
||||
APP_ARGS="$APP_ARGS -log.level=debug"
|
||||
PROBE_ARGS="$PROBE_ARGS -log.level=debug"
|
||||
PROBE_ARGS="$PROBE_ARGS -log.level=debug"
|
||||
;;
|
||||
--no-app)
|
||||
--no-app|--app-only)
|
||||
touch /etc/service/app/down
|
||||
;;
|
||||
--no-probe)
|
||||
--no-probe|--probe-only)
|
||||
touch /etc/service/probe/down
|
||||
;;
|
||||
--probe.*)
|
||||
@@ -129,31 +70,6 @@ while true; do
|
||||
shift
|
||||
done
|
||||
|
||||
if is_running $WEAVE_CONTAINER_NAME; then
|
||||
container_ip $WEAVE_CONTAINER_NAME
|
||||
PROBE_ARGS="$PROBE_ARGS -weave.router.addr=$CONTAINER_IP"
|
||||
weave_expose
|
||||
|
||||
DOCKER_BRIDGE_IP=$(docker_bridge_ip)
|
||||
echo "Weave container detected at $CONTAINER_IP, Docker bridge at $DOCKER_BRIDGE_IP"
|
||||
|
||||
echo "domain $DOMAIN" >/etc/resolv.conf
|
||||
echo "search $DOMAIN" >>/etc/resolv.conf
|
||||
echo "nameserver $DOCKER_BRIDGE_IP" >>/etc/resolv.conf
|
||||
|
||||
IP_ADDRS=$(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")
|
||||
CONTAINER=$(docker inspect --format='{{.Id}}' weavescope)
|
||||
if [ -z "$IP_ADDRS" ]; then
|
||||
echo "Could not determine local IP address; Weave DNS integration will not work correctly."
|
||||
exit 1
|
||||
else
|
||||
for ip in $IP_ADDRS; do
|
||||
weave dns-add $ip $CONTAINER -h $HOSTNAME.$DOMAIN
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$APP_ARGS" >/etc/weave/scope-app.args
|
||||
echo "$PROBE_ARGS" >/etc/weave/scope-probe.args
|
||||
|
||||
@@ -171,6 +87,4 @@ fi
|
||||
|
||||
echo "$MANUAL_APPS" >>/etc/weave/apps
|
||||
|
||||
|
||||
exec /home/weave/runsvinit
|
||||
|
||||
|
||||
Reference in New Issue
Block a user