Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
derive peer name from machine id, if possible
Browse files Browse the repository at this point in the history
This provides a stable peer identity across reboots.

Fixes #901.
  • Loading branch information
rade committed Jan 11, 2016
1 parent 0b4f1b5 commit 7614a0f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions weave
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ IMAGE_VERSION=${WEAVE_VERSION:-$IMAGE_VERSION}
MIN_DOCKER_VERSION=1.6.0

# These are needed for remote execs, hence we introduce them here
MACHINE_ID1=/etc/machine-id
MACHINE_ID2=/var/lib/dbus/machine-id
DOCKERHUB_USER=${DOCKERHUB_USER:-weaveworks}
BASE_EXEC_IMAGE=$DOCKERHUB_USER/weaveexec
EXEC_IMAGE=$BASE_EXEC_IMAGE:$IMAGE_VERSION
Expand Down Expand Up @@ -111,7 +113,7 @@ docker_sock_options() {
exec_remote() {
docker $DOCKER_CLIENT_ARGS run --rm --privileged --net=host \
$(docker_sock_options) \
-v /proc:/hostproc \
-v /proc:/hostproc -v $MACHINE_ID1:$MACHINE_ID1 -v $MACHINE_ID2:$MACHINE_ID2 \
-e PROCFS=/hostproc \
-e DOCKERHUB_USER="$DOCKERHUB_USER" \
-e WEAVE_VERSION \
Expand Down Expand Up @@ -340,6 +342,8 @@ PLUGIN_IMAGE=$BASE_PLUGIN_IMAGE:$IMAGE_VERSION
PLUGIN_CONTAINER_NAME=weaveplugin

PROCFS=${PROCFS:-/proc}
[ -z "$MACHINE_ID" -a -f $MACHINE_ID1 ] && MACHINE_ID=$(cat $MACHINE_ID1 2>/dev/null) || true
[ -z "$MACHINE_ID" -a -f $MACHINE_ID2 ] && MACHINE_ID=$(cat $MACHINE_ID2 2>/dev/null) || true
DOCKER_BRIDGE=${DOCKER_BRIDGE:-docker0}
CONTAINER_NAME=${WEAVE_CONTAINER_NAME:-weave}
BRIDGE=weave
Expand Down Expand Up @@ -1508,13 +1512,16 @@ launch_router() {
enforce_docker_bridge_addr_assign_type
create_bridge
docker_bridge_ip
# We set the router name to the bridge mac since that is
# stable across re-creations of the containers.
#
# TODO use the mac of one of the physical host interfaces
# (eth0, wlan0, etc) so the name becomes stable across host
# restarts.
PEERNAME=$(cat /sys/class/net/$BRIDGE/address)
# Derive the router name from the machine id, if present, since
# that is stable across reboots. Otherwise set it to the bridge
# MAC since at least that is stable across router re-launches.
if [ -n "$MACHINE_ID" ] ; then
# first 6 bytes of $MACHINE_ID (which is 16 bytes, represented
# as a 32-digit hex string), in MAC notation
PEERNAME=$(echo "$MACHINE_ID" | sed 's/\(.\{2\}\)/\1:/g' | cut -c1-17)
else
PEERNAME=$(cat /sys/class/net/$BRIDGE/address)
fi
# backward compatibility...
if is_cidr "$1" ; then
echo "WARNING: $1 parameter ignored; 'weave launch' no longer takes a CIDR as the first parameter" >&2
Expand Down

0 comments on commit 7614a0f

Please sign in to comment.