Skip to content

Commit

Permalink
Add 'weave restart' command
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Jul 21, 2015
1 parent 32d6422 commit 3a2f9a0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
20 changes: 20 additions & 0 deletions site/features.md
Expand Up @@ -14,6 +14,7 @@ example](https://github.com/weaveworks/weave#example):
* [Naming and discovery](#naming-and-discovery)
* [Application isolation](#application-isolation)
* [Dynamic network attachment](#dynamic-network-attachment)
* [Restarting containers](#restarting-containers)
* [Security](#security)
* [Host network integration](#host-network-integration)
* [Service export](#service-export)
Expand Down Expand Up @@ -118,6 +119,25 @@ IP addresses of external services the hosts or containers need to
connect to. The same IP range must be used everywhere, and the
individual IP addresses must, of course, be unique.

If you restart a container, it will retain the same IP addresses on
the weave network:

host1$ docker run --name a1 -tdi ubuntu
f76b09a9fcfee04551dbb8d951d9a83e7e7d55126b02fd9f44f9f8a5f07d7c96
host1$ weave ps a1
a1 1e:dc:2a:db:ef:ff 10.32.0.3/12
host1$ docker restart a1
host1$ weave ps a1
a1 16:c0:6f:5d:c5:73 10.32.0.3/12

There is also a `weave restart` command, if you are not using the
Docker API proxy:

host1$ weave restart b1

Note that if Docker restarts a container under a restart policy it
will not be re-attached to the weave network.

### <a name="naming-and-discovery"></a>Naming and discovery

Named containers are automatically registered in
Expand Down
4 changes: 4 additions & 0 deletions test/100_cross_hosts_test.sh
Expand Up @@ -27,6 +27,10 @@ start_container $HOST2 net:$SUBNET_2 --name=c6
C6=$(container_ip $HOST2 c6)
assert_raises "exec_on $HOST1 c5 $PING $C6"

# check that restart retains the same IP
weave_on $HOST2 restart c6
assert_raises "exec_on $HOST1 c5 $PING $C6"

# check large packets get through. The first attempt typically fails,
# since the PMTU hasn't been discovered yet. The 2nd attempt should
# succeed.
Expand Down
9 changes: 4 additions & 5 deletions test/640_proxy_restart_reattaches_test.sh
Expand Up @@ -2,17 +2,16 @@

. ./config.sh

C1=10.2.0.78
C2=10.2.0.34
NAME=seetwo.weave.local

start_suite "Proxy restart reattaches networking to containers"

weave_on $HOST1 launch
proxy docker_on $HOST1 run -e WEAVE_CIDR=$C2/24 -dt --name=c2 -h $NAME $SMALL_IMAGE /bin/sh
proxy docker_on $HOST1 run -e WEAVE_CIDR=$C1/24 -dt --name=c1 $DNS_IMAGE /bin/sh
proxy docker_on $HOST1 run -dt --name=c2 -h $NAME $SMALL_IMAGE /bin/sh
proxy docker_on $HOST1 run -dt --name=c1 $DNS_IMAGE /bin/sh

proxy docker_on $HOST1 restart c2
C2=$(container_ip $HOST1 c2)
proxy docker_on $HOST1 restart --time=1 c2
assert_raises "proxy exec_on $HOST1 c2 $CHECK_ETHWE_UP"
assert_dns_record $HOST1 c1 $NAME $C2

Expand Down
15 changes: 15 additions & 0 deletions weave
Expand Up @@ -45,6 +45,7 @@ weave forget <peer> ...
weave run [--with-dns | --without-dns] [<addr> ...]
<docker run args> ...
weave start [<addr> ...] <container_id>
weave restart <container_id>
weave attach [<addr> ...] <container_id>
weave detach [<addr> ...] <container_id>
weave dns-add <ip_address> [<ip_address> ...] <container_id> [-h <fqdn>]
Expand Down Expand Up @@ -652,6 +653,10 @@ echo_addresses() {
echo $1 $2 $3
}

echo_just_ips() {
echo $3
}

peer_args() {
res=''
sep=''
Expand Down Expand Up @@ -1334,6 +1339,16 @@ case "$COMMAND" in
when_weave_running with_container_fqdn $CONTAINER put_dns_fqdn $ALL_CIDRS
echo $RES
;;
restart)
[ $# -ge 1 ] || usage
CONTAINER=$(container_id $1)
ALL_CIDRS=$(with_container_addresses echo_just_ips $CONTAINER)
call_weave POST /ip/restarting/$CONTAINER 2>/dev/null || true
RES=$(docker restart "$@")
with_container_netns_or_die $CONTAINER attach $ALL_CIDRS
when_weave_running with_container_fqdn $CONTAINER put_dns_fqdn $ALL_CIDRS
echo $RES
;;
attach)
collect_cidr_args "$@"
shift $CIDR_ARG_COUNT
Expand Down

0 comments on commit 3a2f9a0

Please sign in to comment.