Implement new weave launch behaviour

This commit is contained in:
Adam Harrison committed 2015-06-25 12:47:14 +01:00
1 parent 409961fff3
commit fcd79a78af
1 file changed
+94 -68
+94 -68
View File
@@ -26,6 +26,8 @@ CIDR_REGEXP="$IP_REGEXP/[0-9]{1,2}"
usage() { usage() {
echo "Usage:" echo "Usage:"
echo "weave setup" echo "weave setup"
echo "weave launch [-password <password>] [-nickname <nickname>] [-nodiscovery]"
echo " [-iprange <cidr> [-ipsubnet <cidr>]] <peer> ..."
echo "weave launch-router [-password <password>] [-nickname <nickname>] [-nodiscovery]" echo "weave launch-router [-password <password>] [-nickname <nickname>] [-nodiscovery]"
echo " [-iprange <cidr> [-ipsubnet <cidr>]] <peer> ..." echo " [-iprange <cidr> [-ipsubnet <cidr>]] <peer> ..."
echo "weave launch-dns [<addr>]" echo "weave launch-dns [<addr>]"
@@ -918,67 +920,11 @@ proxy_addr() {
return 1 return 1
} }
########################################################################################## ######################################################################
# launch helpers
######################################################################
[ $(id -u) = 0 ] || { launch_router() {
echo "weave must be run as 'root' when run locally" >&2
exit 1
}
uname -s -r | sed -n -e 's|^\([^ ]*\) \([0-9][0-9]*\)\.\([0-9][0-9]*\).*|\1 \2 \3|p' | {
if ! read sys maj min ; then
echo "ERROR: Unable to parse operating system version $(uname -s -r)" >&2
exit 1
fi
if [ "$sys" != 'Linux' ] ; then
echo "ERROR: Operating systems other than Linux are not supported (you have $(uname -s -r))" >&2
exit 1
fi
if ! [ \( "$maj" -eq 3 -a "$min" -ge 8 \) -o "$maj" -gt 3 ] ; then
echo "WARNING: Linux kernel version 3.8 or newer is required (you have ${maj}.${min})" >&2
fi
}
if ! command_exists ip ; then
echo "ERROR: ip utility is missing. Please install it." >&2
exit 1
fi
if ! ip netns list >/dev/null 2>&1 ; then
echo "ERROR: $(ip -V) does not support network namespaces." >&2
echo " Please install iproute2-ss111010 or later." >&2
exit 1
fi
if ! command_exists nsenter ; then
echo "ERROR: nsenter utility missing. Please install it." >&2
exit 1
fi
check_docker_version
DOCKER_VERSION_MAJOR=$(echo "$DOCKER_VERSION" | cut -d. -f 1)
DOCKER_VERSION_MINOR=$(echo "$DOCKER_VERSION" | cut -d. -f 2)
DOCKER_VERSION_PATCH=$(echo "$DOCKER_VERSION" | cut -d. -f 3)
[ $# -gt 0 ] || usage
COMMAND=$1
shift 1
case "$COMMAND" in
setup)
for img in $IMAGE $DNS_IMAGE $EXEC_IMAGE ; do
docker pull $img
done
;;
# intentionally undocumented since it assumes knowledge of weave
# internals
create-bridge)
create_bridge --without-ethtool
;;
launch-router)
check_not_running $CONTAINER_NAME $BASE_IMAGE
create_bridge create_bridge
# We set the router name to the bridge mac since that is # We set the router name to the bridge mac since that is
# stable across re-creations of the containers. # stable across re-creations of the containers.
@@ -1045,13 +991,12 @@ case "$COMMAND" in
# Tell the newly-started weave IP allocator about existing weave IPs # Tell the newly-started weave IP allocator about existing weave IPs
with_container_addresses ipam_claim weave:expose $(docker ps -q --no-trunc) with_container_addresses ipam_claim weave:expose $(docker ps -q --no-trunc)
fi fi
echo $CONTAINER }
;;
launch-dns) launch_dns() {
collect_cidr_args "$@" collect_cidr_args "$@"
[ $CIDR_ARG_COUNT -lt 2 ] || usage [ $CIDR_ARG_COUNT -lt 2 ] || usage
shift $CIDR_ARG_COUNT shift $CIDR_ARG_COUNT
check_not_running $DNS_CONTAINER_NAME $BASE_DNS_IMAGE
create_bridge create_bridge
docker_bridge_ip docker_bridge_ip
# Set WEAVEDNS_DOCKER_ARGS in the environment in order to supply # Set WEAVEDNS_DOCKER_ARGS in the environment in order to supply
@@ -1065,10 +1010,9 @@ case "$COMMAND" in
ipam_cidrs_or_die $DNS_CONTAINER $CIDR_ARGS ipam_cidrs_or_die $DNS_CONTAINER $CIDR_ARGS
with_container_netns_or_die $DNS_CONTAINER attach $ALL_CIDRS with_container_netns_or_die $DNS_CONTAINER attach $ALL_CIDRS
populate_dns populate_dns
echo $DNS_CONTAINER }
;;
launch-proxy) launch_proxy() {
check_not_running $PROXY_CONTAINER_NAME $EXEC_IMAGE
# Set WEAVEPROXY_DOCKER_ARGS in the environment in order to supply # Set WEAVEPROXY_DOCKER_ARGS in the environment in order to supply
# additional parameters, such as resource limits, to docker # additional parameters, such as resource limits, to docker
# when launching the weaveproxy container. # when launching the weaveproxy container.
@@ -1082,6 +1026,88 @@ case "$COMMAND" in
--entrypoint=/home/weave/weaveproxy \ --entrypoint=/home/weave/weaveproxy \
$WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $PROXY_ARGS) $WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $PROXY_ARGS)
wait_for_log $PROXY_CONTAINER_NAME "proxy listening" wait_for_log $PROXY_CONTAINER_NAME "proxy listening"
}
##########################################################################################
[ $(id -u) = 0 ] || {
echo "weave must be run as 'root' when run locally" >&2
exit 1
}
uname -s -r | sed -n -e 's|^\([^ ]*\) \([0-9][0-9]*\)\.\([0-9][0-9]*\).*|\1 \2 \3|p' | {
if ! read sys maj min ; then
echo "ERROR: Unable to parse operating system version $(uname -s -r)" >&2
exit 1
fi
if [ "$sys" != 'Linux' ] ; then
echo "ERROR: Operating systems other than Linux are not supported (you have $(uname -s -r))" >&2
exit 1
fi
if ! [ \( "$maj" -eq 3 -a "$min" -ge 8 \) -o "$maj" -gt 3 ] ; then
echo "WARNING: Linux kernel version 3.8 or newer is required (you have ${maj}.${min})" >&2
fi
}
if ! command_exists ip ; then
echo "ERROR: ip utility is missing. Please install it." >&2
exit 1
fi
if ! ip netns list >/dev/null 2>&1 ; then
echo "ERROR: $(ip -V) does not support network namespaces." >&2
echo " Please install iproute2-ss111010 or later." >&2
exit 1
fi
if ! command_exists nsenter ; then
echo "ERROR: nsenter utility missing. Please install it." >&2
exit 1
fi
check_docker_version
DOCKER_VERSION_MAJOR=$(echo "$DOCKER_VERSION" | cut -d. -f 1)
DOCKER_VERSION_MINOR=$(echo "$DOCKER_VERSION" | cut -d. -f 2)
DOCKER_VERSION_PATCH=$(echo "$DOCKER_VERSION" | cut -d. -f 3)
[ $# -gt 0 ] || usage
COMMAND=$1
shift 1
case "$COMMAND" in
setup)
for img in $IMAGE $DNS_IMAGE $EXEC_IMAGE ; do
docker pull $img
done
;;
# intentionally undocumented since it assumes knowledge of weave
# internals
create-bridge)
create_bridge --without-ethtool
;;
launch)
check_not_running $CONTAINER_NAME $BASE_IMAGE
check_not_running $DNS_CONTAINER_NAME $BASE_DNS_IMAGE
check_not_running $PROXY_CONTAINER_NAME $EXEC_IMAGE
launch_router "$@"
launch_dns
launch_proxy
;;
launch-router)
check_not_running $CONTAINER_NAME $BASE_IMAGE
launch_router "$@"
echo $CONTAINER
;;
launch-dns)
check_not_running $DNS_CONTAINER_NAME $BASE_DNS_IMAGE
launch_dns "$@"
echo $DNS_CONTAINER
;;
launch-proxy)
check_not_running $PROXY_CONTAINER_NAME $EXEC_IMAGE
launch_proxy "$@"
echo $PROXY_CONTAINER echo $PROXY_CONTAINER
;; ;;
proxy-env) proxy-env)