diff --git a/Makefile b/Makefile index 65fde9f0..95c6f0d0 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,6 @@ WEAVE_VERSION?=git-$(shell git rev-parse --short=12 HEAD) # Paths to all relevant binaries that should be compiled WEAVER_EXE=prog/weaver/weaver -WEAVEPROXY_EXE=prog/weaveproxy/weaveproxy SIGPROXY_EXE=prog/sigproxy/sigproxy KUBEPEERS_EXE=prog/kube-peers/kube-peers WEAVENPC_EXE=prog/weave-npc/weave-npc @@ -99,7 +98,7 @@ MANIFEST_TOOL_EXE=$(MANIFEST_TOOL_DIR)/manifest-tool TEST_TLS_EXE=test/tls/tls # All binaries together in a list -EXES=$(WEAVER_EXE) $(SIGPROXY_EXE) $(KUBEPEERS_EXE) $(WEAVENPC_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(RUNNER_EXE) $(TEST_TLS_EXE) $(MANIFEST_TOOL_EXE) +EXES=$(WEAVER_EXE) $(SIGPROXY_EXE) $(KUBEPEERS_EXE) $(WEAVENPC_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) $(RUNNER_EXE) $(TEST_TLS_EXE) $(MANIFEST_TOOL_EXE) # These stamp files are used to mark the current state of the build; whether an image has been built or not BUILD_UPTODATE=.build.uptodate @@ -152,10 +151,10 @@ PACKAGE_BASE=$(shell go list -e ./) all: $(WEAVE_EXPORT) testrunner: $(RUNNER_EXE) $(TEST_TLS_EXE) -$(WEAVER_EXE) $(WEAVEPROXY_EXE) $(WEAVEUTIL_EXE): common/*.go common/*/*.go net/*.go net/*/*.go +$(WEAVER_EXE) $(WEAVEUTIL_EXE): common/*.go common/*/*.go net/*.go net/*/*.go $(WEAVER_EXE): router/*.go ipam/*.go ipam/*/*.go db/*.go nameserver/*.go prog/weaver/*.go $(WEAVER_EXE): api/*.go plugin/*.go plugin/*/* -$(WEAVEPROXY_EXE): proxy/*.go prog/weaveproxy/*.go +$(WEAVER_EXE): proxy/*.go $(WEAVEUTIL_EXE): prog/weaveutil/*.go net/*.go plugin/net/*.go plugin/ipam/*.go db/*.go $(SIGPROXY_EXE): prog/sigproxy/*.go $(KUBEPEERS_EXE): prog/kube-peers/*.go @@ -189,7 +188,7 @@ else exes: $(EXES) -$(WEAVER_EXE) $(WEAVEPROXY_EXE): +$(WEAVER_EXE): ifeq ($(COVERAGE),true) $(eval COVERAGE_MODULES := $(shell (go list ./$(@D); go list -f '{{join .Deps "\n"}}' ./$(@D) | grep "^$(PACKAGE_BASE)/") | grep -v "^$(PACKAGE_BASE)/vendor/" | paste -s -d,)) go test -c -o ./$@ $(BUILD_FLAGS) -v -covermode=atomic -coverpkg $(COVERAGE_MODULES) ./$(@D)/ @@ -253,10 +252,9 @@ $(WEAVER_UPTODATE): prog/weaver/Dockerfile.$(DOCKERHUB_USER) $(WEAVER_EXE) $(WEA $(SUDO) DOCKER_HOST=$(DOCKER_HOST) docker build -f prog/weaver/Dockerfile.$(DOCKERHUB_USER) -t $(WEAVER_IMAGE) prog/weaver touch $@ -$(WEAVEEXEC_UPTODATE): prog/weaveexec/Dockerfile.$(DOCKERHUB_USER) prog/weaveexec/symlink $(DOCKER_DISTRIB) weave $(SIGPROXY_EXE) $(WEAVEPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) +$(WEAVEEXEC_UPTODATE): prog/weaveexec/Dockerfile.$(DOCKERHUB_USER) prog/weaveexec/symlink $(DOCKER_DISTRIB) weave $(SIGPROXY_EXE) $(WEAVEWAIT_EXE) $(WEAVEWAIT_NOOP_EXE) $(WEAVEWAIT_NOMCAST_EXE) $(WEAVEUTIL_EXE) cp weave prog/weaveexec/weave cp $(SIGPROXY_EXE) prog/weaveexec/sigproxy - cp $(WEAVEPROXY_EXE) prog/weaveexec/weaveproxy cp $(WEAVEWAIT_EXE) prog/weaveexec/weavewait cp $(WEAVEWAIT_NOOP_EXE) prog/weaveexec/weavewait_noop cp $(WEAVEWAIT_NOMCAST_EXE) prog/weaveexec/weavewait_nomcast @@ -275,7 +273,7 @@ $(PLUGIN_UPTODATE): prog/net-plugin/launch.sh prog/net-plugin/config.json $(WEAV $(SUDO) docker export $(PLUGIN_BUILD_IMG) | tar -x -C $(PLUGIN_WORK_DIR) $(SUDO) docker rm -f $(PLUGIN_BUILD_IMG) # get rid of a few bulky things we don't need in the v2 plugin image - rm $(PLUGIN_WORK_DIR)/home/weave/weaveproxy $(PLUGIN_WORK_DIR)/home/weave/sigproxy $(PLUGIN_WORK_DIR)/usr/bin/docker + rm $(PLUGIN_WORK_DIR)/home/weave/sigproxy $(PLUGIN_WORK_DIR)/usr/bin/docker cp prog/net-plugin/launch.sh $(PLUGIN_WORK_DIR)/home/weave/launch.sh -$(SUDO) docker plugin disable $(PLUGIN_IMAGE):$(WEAVE_VERSION) 2>/dev/null -$(SUDO) docker plugin rm $(PLUGIN_IMAGE):$(WEAVE_VERSION) 2>/dev/null diff --git a/prog/weaveexec/Dockerfile.template b/prog/weaveexec/Dockerfile.template index 3e1b41e9..716dda01 100644 --- a/prog/weaveexec/Dockerfile.template +++ b/prog/weaveexec/Dockerfile.template @@ -25,7 +25,7 @@ RUN apk add --update \ bind-tools \ && rm -rf /var/cache/apk/* -ADD ./weave ./sigproxy ./weaveproxy ./symlink /home/weave/ +ADD ./weave ./sigproxy ./symlink /home/weave/ ADD ./weaveutil ./docker /usr/bin/ ADD ./weavewait /w/w ADD ./weavewait_noop /w-noop/w diff --git a/prog/weaveproxy/main.go b/prog/weaveproxy/main.go deleted file mode 100644 index f6094e87..00000000 --- a/prog/weaveproxy/main.go +++ /dev/null @@ -1,78 +0,0 @@ -package main - -import ( - "fmt" - "os" - "strings" - - "github.com/weaveworks/common/mflag" - "github.com/weaveworks/common/mflagext" - "github.com/weaveworks/common/signals" - "github.com/weaveworks/weave/common" - "github.com/weaveworks/weave/proxy" -) - -var version = "unreleased" - -var Log = common.Log - -func getenvOrDefault(key, defaultVal string) string { - if v := os.Getenv(key); v != "" { - return v - } - return defaultVal -} - -func main() { - var ( - justVersion bool - logLevel = "info" - c proxy.Config - ) - - c.Version = version - - mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit") - mflag.StringVar(&logLevel, []string{"-log-level"}, "info", "logging level (debug, info, warning, error)") - mflagext.ListVar(&c.ListenAddrs, []string{"H"}, nil, "addresses on which to listen") - mflag.StringVar(&c.HostnameFromLabel, []string{"-hostname-from-label"}, "", "Key of container label from which to obtain the container's hostname") - mflag.StringVar(&c.HostnameMatch, []string{"-hostname-match"}, "(.*)", "Regexp pattern to apply on container names (e.g. '^aws-[0-9]+-(.*)$')") - mflag.StringVar(&c.HostnameReplacement, []string{"-hostname-replacement"}, "$1", "Expression to generate hostnames based on matches from --hostname-match (e.g. 'my-app-$1')") - mflag.BoolVar(&c.RewriteInspect, []string{"-rewrite-inspect"}, false, "Rewrite 'inspect' calls to return the weave network settings (if attached)") - mflag.BoolVar(&c.NoDefaultIPAM, []string{"#-no-default-ipam", "-no-default-ipalloc"}, false, "do not automatically allocate addresses for containers without a WEAVE_CIDR") - mflag.BoolVar(&c.NoRewriteHosts, []string{"-no-rewrite-hosts"}, false, "do not automatically rewrite /etc/hosts. Use if you need the docker IP to remain in /etc/hosts") - mflag.StringVar(&c.TLSConfig.CACert, []string{"#tlscacert", "-tlscacert"}, "", "Trust certs signed only by this CA") - mflag.StringVar(&c.TLSConfig.Cert, []string{"#tlscert", "-tlscert"}, "", "Path to TLS certificate file") - mflag.BoolVar(&c.TLSConfig.Enabled, []string{"#tls", "-tls"}, false, "Use TLS; implied by --tlsverify") - mflag.StringVar(&c.TLSConfig.Key, []string{"#tlskey", "-tlskey"}, "", "Path to TLS key file") - mflag.BoolVar(&c.TLSConfig.Verify, []string{"#tlsverify", "-tlsverify"}, false, "Use TLS and verify the remote") - mflag.BoolVar(&c.WithoutDNS, []string{"-without-dns"}, false, "instruct created containers to never use weaveDNS as their nameserver") - mflag.BoolVar(&c.NoMulticastRoute, []string{"-no-multicast-route"}, false, "do not add a multicast route via the weave interface when attaching containers") - mflag.Parse() - - if justVersion { - fmt.Printf("weave proxy %s\n", version) - os.Exit(0) - } - - common.SetLogLevel(logLevel) - - Log.Infoln("weave proxy", version) - Log.Infoln("Command line arguments:", strings.Join(os.Args[1:], " ")) - - c.Image = getenvOrDefault("EXEC_IMAGE", "weaveworks/weaveexec") - c.DockerBridge = getenvOrDefault("DOCKER_BRIDGE", "docker0") - c.DockerHost = getenvOrDefault("DOCKER_HOST", "unix:///var/run/docker.sock") - - p, err := proxy.NewProxy(c) - if err != nil { - Log.Fatalf("Could not start proxy: %s", err) - } - defer p.Stop() - - listeners := p.Listen() - p.AttachExistingContainers() - go p.Serve(listeners) - go p.ListenAndServeStatus("/home/weave/status.sock") - signals.SignalHandlerLoop(common.Log) -} diff --git a/prog/weaveproxy/main_test.go b/prog/weaveproxy/main_test.go deleted file mode 100644 index 1873f4a3..00000000 --- a/prog/weaveproxy/main_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package main - -import ( - "testing" - - weavetest "github.com/weaveworks/weave/testing" -) - -func TestMain(t *testing.T) { - weavetest.TrimTestArgs() - main() -} diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 9a4898fe..3f3c7bd1 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -14,6 +14,7 @@ import ( "github.com/gorilla/mux" "github.com/pkg/profile" "github.com/weaveworks/common/mflag" + "github.com/weaveworks/common/mflagext" "github.com/weaveworks/common/signals" "github.com/weaveworks/mesh" @@ -26,6 +27,7 @@ import ( weavenet "github.com/weaveworks/weave/net" "github.com/weaveworks/weave/net/address" "github.com/weaveworks/weave/plugin" + weaveproxy "github.com/weaveworks/weave/proxy" weave "github.com/weaveworks/weave/router" ) @@ -113,6 +115,13 @@ func (c *ipamConfig) parseMode() error { return nil } +func getenvOrDefault(key, defaultVal string) string { + if v := os.Getenv(key); v != "" { + return v + } + return defaultVal +} + func main() { procs := runtime.NumCPU() // packet sniffing can block an OS thread, so we need one thread @@ -133,7 +142,7 @@ func main() { nickName string password string pktdebug bool - logLevel string + logLevel = "info" prof string bufSzMB int noDiscovery bool @@ -156,14 +165,9 @@ func main() { enablePlugin bool enablePluginV2 bool enablePluginV2Multicast bool - - defaultDockerHost = "unix:///var/run/docker.sock" + defaultDockerHost = getenvOrDefault("DOCKER_HOST", "unix:///var/run/docker.sock") ) - if val := os.Getenv("DOCKER_HOST"); val != "" { - defaultDockerHost = val - } - mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit") mflag.StringVar(&config.Host, []string{"-host"}, "", "router host") mflag.IntVar(&config.Port, []string{"#port", "-port"}, mesh.Port, "router port") @@ -213,6 +217,8 @@ func main() { mflag.StringVar(&pluginSocket, []string{"-plugin-socket"}, "/run/docker/plugins/weave.sock", "plugin socket on which to listen") mflag.StringVar(&pluginMeshSocket, []string{"-plugin-mesh-socket"}, "/run/docker/plugins/weavemesh.sock", "plugin socket on which to listen in mesh mode") + proxyConfig := configureProxy(version, defaultDockerHost) + // crude way of detecting that we probably have been started in a // container, with `weave launch` --> suppress misleading paths in // mflags error messages. @@ -223,19 +229,19 @@ func main() { mflag.Parse() + if justVersion { + fmt.Printf("weave %s\n", version) + os.Exit(0) + } + peers = mflag.Args() if resume && len(peers) > 0 { Log.Fatalf("You must not specify an initial peer list in conjunction with --resume") } common.SetLogLevel(logLevel) - - if justVersion { - fmt.Printf("weave router %s\n", version) - os.Exit(0) - } - Log.Println("Command line options:", options()) + Log.Infoln("weave ", version) if prof != "" { defer profile.Start(profile.CPUProfile, profile.ProfilePath(prof), profile.NoShutdownHook).Stop() @@ -246,6 +252,17 @@ func main() { } config.ProtocolMinVersion = byte(protocolMinVersion) + // Start Weave Proxy: + proxy, err := weaveproxy.NewProxy(*proxyConfig) + if err != nil { + Log.Fatalf("Could not start proxy: %s", err) + } + defer proxy.Stop() + listeners := proxy.Listen() + proxy.AttachExistingContainers() + go proxy.Serve(listeners) + go proxy.ListenAndServeStatus("/home/weave/status.sock") + if pktdebug { networkConfig.PacketLogging = packetLogging{} } else { @@ -497,6 +514,30 @@ func (nopPacketLogging) LogPacket(string, weave.PacketKey) { func (nopPacketLogging) LogForwardPacket(string, weave.ForwardPacketKey) { } +func configureProxy(version string, defaultDockerHost string) *weaveproxy.Config { + proxyConfig := weaveproxy.Config{ + Version: version, + Image: getenvOrDefault("EXEC_IMAGE", "weaveworks/weaveexec"), + DockerBridge: getenvOrDefault("DOCKER_BRIDGE", "docker0"), + DockerHost: defaultDockerHost, + } + mflagext.ListVar(&proxyConfig.ListenAddrs, []string{"H"}, nil, "addresses on which to listen") + mflag.StringVar(&proxyConfig.HostnameFromLabel, []string{"-hostname-from-label"}, "", "Key of container label from which to obtain the container's hostname") + mflag.StringVar(&proxyConfig.HostnameMatch, []string{"-hostname-match"}, "(.*)", "Regexp pattern to apply on container names (e.g. '^aws-[0-9]+-(.*)$')") + mflag.StringVar(&proxyConfig.HostnameReplacement, []string{"-hostname-replacement"}, "$1", "Expression to generate hostnames based on matches from --hostname-match (e.g. 'my-app-$1')") + mflag.BoolVar(&proxyConfig.RewriteInspect, []string{"-rewrite-inspect"}, false, "Rewrite 'inspect' calls to return the weave network settings (if attached)") + mflag.BoolVar(&proxyConfig.NoDefaultIPAM, []string{"#-no-default-ipam", "-no-default-ipalloc"}, false, "do not automatically allocate addresses for containers without a WEAVE_CIDR") + mflag.BoolVar(&proxyConfig.NoRewriteHosts, []string{"-no-rewrite-hosts"}, false, "do not automatically rewrite /etc/hosts. Use if you need the docker IP to remain in /etc/hosts") + mflag.StringVar(&proxyConfig.TLSConfig.CACert, []string{"#tlscacert", "-tlscacert"}, "", "Trust certs signed only by this CA") + mflag.StringVar(&proxyConfig.TLSConfig.Cert, []string{"#tlscert", "-tlscert"}, "", "Path to TLS certificate file") + mflag.BoolVar(&proxyConfig.TLSConfig.Enabled, []string{"#tls", "-tls"}, false, "Use TLS; implied by --tlsverify") + mflag.StringVar(&proxyConfig.TLSConfig.Key, []string{"#tlskey", "-tlskey"}, "", "Path to TLS key file") + mflag.BoolVar(&proxyConfig.TLSConfig.Verify, []string{"#tlsverify", "-tlsverify"}, false, "Use TLS and verify the remote") + mflag.BoolVar(&proxyConfig.WithoutDNS, []string{"-without-dns"}, false, "instruct created containers to never use weaveDNS as their nameserver") + mflag.BoolVar(&proxyConfig.NoMulticastRoute, []string{"-no-multicast-route"}, false, "do not add a multicast route via the weave interface when attaching containers") + return &proxyConfig +} + func createOverlay(bridgeType weavenet.Bridge, config weavenet.BridgeConfig, host string, port int, bufSzMB int, enableEncryption bool) (weave.NetworkOverlay, weave.InjectorConsumer) { overlay := weave.NewOverlaySwitch() var injectorConsumer weave.InjectorConsumer diff --git a/proxy/proxy.go b/proxy/proxy.go index 40e00968..dae1c4ce 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -204,7 +204,7 @@ func (proxy *Proxy) findWeaveWaitVolumes() error { } func (proxy *Proxy) findVolume(v string) (string, error) { - container, err := proxy.client.InspectContainer("weaveproxy") + container, err := proxy.client.InspectContainer("weave") if err != nil { return "", fmt.Errorf("Could not find the weavewait volume: %s", err) } diff --git a/test/config.sh b/test/config.sh index 38c59b54..d25c9152 100644 --- a/test/config.sh +++ b/test/config.sh @@ -136,7 +136,7 @@ stop_weave_on() { host=$1 weave_on $host stop 1>/dev/null 2>&1 || true if [ -n "$COVERAGE" ]; then - for C in weaveplugin weaveproxy weave ; do + for C in weaveplugin weave ; do collect_coverage $host $C done fi diff --git a/weave b/weave index 6dfe0f90..fce1dc43 100755 --- a/weave +++ b/weave @@ -42,23 +42,21 @@ weave --help | help setup version -weave launch - launch-router [--password ] [--trusted-subnets ,...] - [--host ] - [--name ] [--nickname ] - [--no-restart] [--resume] [--no-discovery] [--no-dns] - [--ipalloc-init ] - [--ipalloc-range [--ipalloc-default-subnet ]] - [--plugin] - [--log-level=debug|info|warning|error] - ... - launch-proxy [-H ] [--without-dns] [--no-multicast-route] - [--no-rewrite-hosts] [--no-default-ipalloc] [--no-restart] - [--hostname-from-label ] - [--hostname-match ] - [--hostname-replacement ] - [--rewrite-inspect] - [--log-level=debug|info|warning|error] +weave launch [--password ] [--trusted-subnets ,...] + [--host ] + [--name ] [--nickname ] + [--no-restart] [--resume] [--no-discovery] [--no-dns] + [--ipalloc-init ] + [--ipalloc-range [--ipalloc-default-subnet ]] + [--plugin] + [-H ] [--without-dns] [--no-multicast-route] + [--no-rewrite-hosts] [--no-default-ipalloc] + [--hostname-from-label ] + [--hostname-match ] + [--hostname-replacement ] + [--rewrite-inspect] + [--log-level=debug|info|warning|error] + ... weave prime @@ -87,13 +85,10 @@ weave status [targets | connections | peers | dns | ipam] ps [ ...] weave stop - stop-router - stop-proxy weave reset [--force] rmpeer ... - where = [:] = / = [ip:] | net: | net:default @@ -151,7 +146,6 @@ exec_remote() { -e WEAVE_VERSION \ -e WEAVE_DEBUG \ -e WEAVE_DOCKER_ARGS \ - -e WEAVEPROXY_DOCKER_ARGS \ -e WEAVEPLUGIN_DOCKER_ARGS \ -e WEAVE_PASSWORD \ -e WEAVE_PORT \ @@ -285,7 +279,7 @@ PORT=${WEAVE_PORT:-6783} HTTP_ADDR=${WEAVE_HTTP_ADDR:-127.0.0.1:6784} STATUS_ADDR=${WEAVE_STATUS_ADDR:-127.0.0.1:6782} PROXY_PORT=12375 -PROXY_CONTAINER_NAME=weaveproxy +OLD_PROXY_CONTAINER_NAME=weaveproxy PROC_PATH="/proc" COVERAGE_ARGS="" [ -n "$COVERAGE" ] && COVERAGE_ARGS="-test.coverprofile=/home/weave/cover.prof --" @@ -634,10 +628,6 @@ check_not_running() { esac } -stop() { - docker stop $1 >/dev/null 2>&1 || echo "$2 is not running." >&2 -} - # Given a container name or short ID in $1, ensure the specified # container exists and then print its full ID to stdout. If # it doesn't exist, print an error to stderr and @@ -1133,10 +1123,11 @@ host_arg() { fi PROXY_VOLUMES="$PROXY_VOLUMES -v /var/run/weave:/var/run/weave" fi - PROXY_ARGS="$PROXY_ARGS -H $1" + PROXY_ARGS="-H $1 $PROXY_ARGS" } proxy_parse_args() { + args="" while [ $# -gt 0 ]; do case "$1" in -H) @@ -1178,11 +1169,13 @@ proxy_parse_args() { RESTART_POLICY= ;; *) - PROXY_ARGS="$PROXY_ARGS $1" + args="$args $1" ;; esac shift done + # Merge proxy options and other args, keeping $args at the end, as these could contain peers: + PROXY_ARGS="$PROXY_ARGS $args" } proxy_args() { @@ -1196,7 +1189,7 @@ proxy_args() { if [ -z "$PROXY_TLS_ENABLED" -a -z "$PROXY_TLS_DETECTION_DISABLED" ] ; then if ! DOCKER_TLS_ARGS=$(util_op docker-tls-args) ; then echo -n "Warning: unable to detect proxy TLS configuration. To enable TLS, " >&2 - echo -n "launch the proxy with 'weave launch-proxy' and supply TLS options. " >&2 + echo -n "launch the proxy with 'weave launch' and supply TLS options. " >&2 echo "To suppress this warning, supply the '--no-detect-tls' option." >&2 else proxy_parse_args $DOCKER_TLS_ARGS @@ -1216,11 +1209,10 @@ proxy_args() { } proxy_addrs() { - if addr="$(http_call_unix $PROXY_CONTAINER_NAME status.sock GET /status 2>/dev/null)" ; then + if addr="$(http_call_unix $CONTAINER_NAME status.sock GET /status 2>/dev/null)" ; then echo "$addr" | sed "s/0.0.0.0/$PROXY_HOST/g" - else - echo "$PROXY_CONTAINER_NAME container is not present. Have you launched it?" >&2 + echo "$CONTAINER_NAME container is not present. Have you launched it?" >&2 return 1 fi } @@ -1240,28 +1232,7 @@ warn_if_stopping_proxy_in_env() { # launch helpers ###################################################################### -common_launch_args() { - args="" - while [ $# -gt 0 ] ; do - case "$1" in - --no-restart) - args="$args $1" - ;; - --log-level) - [ $# -gt 1 ] || usage - args="$args $1 $2" - shift - ;; - --log-level=*) - args="$args $1" - ;; - esac - shift - done - echo "$args" -} - -launch_router() { +launch() { LAUNCHING_ROUTER=1 check_forwarding_rules @@ -1368,20 +1339,41 @@ launch_router() { RESOLV_CONF_DIR=$(dirname "$RESOLV_CONF") RESOLV_CONF_BASE=$(basename "$RESOLV_CONF") + docker_client_args $DOCKER_CLIENT_ARGS + proxy_args "$@" + mkdir -p /var/run/weave + # Create a data-only container to mount the weavewait files from + if ! docker inspect -f ' ' $VOLUMES_CONTAINER_NAME > /dev/null 2>&1 ; then + protect_against_docker_hang + docker create -v /w -v /w-noop -v /w-nomcast --name=$VOLUMES_CONTAINER_NAME \ + --label=weavevolumes --entrypoint=/bin/false $EXEC_IMAGE >/dev/null + fi + [ -n "$AWSVPC" ] && PROXY_ARGS="$PROXY_ARGS --no-multicast-route" + # Set WEAVE_DOCKER_ARGS in the environment in order to supply # additional parameters, such as resource limits, to docker # when launching the weave container. - ROUTER_CONTAINER=$(docker run -d --name=$CONTAINER_NAME \ + WEAVE_CONTAINER=$(docker run -d --name=$CONTAINER_NAME \ $(docker_run_options) \ $RESTART_POLICY \ --pid=host \ --volumes-from $DB_CONTAINER_NAME \ + --volumes-from $VOLUMES_CONTAINER_NAME \ + $PROXY_VOLUMES \ + -v /var/run/weave:/var/run/weave \ -v $RESOLV_CONF_DIR:/var/run/weave/etc \ -v /run/docker/plugins:/run/docker/plugins \ -v /etc:/host/etc -v /var/lib/dbus:/host/var/lib/dbus \ + -e DOCKER_BRIDGE \ + -e WEAVE_DEBUG \ + -e COVERAGE \ + -e WEAVE_HTTP_ADDR \ + -e EXEC_IMAGE=$EXEC_IMAGE \ -e WEAVE_PASSWORD \ -e CHECKPOINT_DISABLE \ - $WEAVE_DOCKER_ARGS $IMAGE $COVERAGE_ARGS \ + $WEAVE_DOCKER_ARGS \ + $IMAGE \ + $COVERAGE_ARGS \ --port $CONTAINER_PORT --nickname "$(hostname)" \ --host-root=/host \ $(router_bridge_opts) \ @@ -1393,51 +1385,15 @@ launch_router() { --http-addr $HTTP_ADDR \ --status-addr $STATUS_ADDR \ --resolv-conf "/var/run/weave/etc/$RESOLV_CONF_BASE" \ - "$@") + $PROXY_ARGS) wait_for_status $CONTAINER_NAME http_call $HTTP_ADDR } -stop_router() { +stop() { ! is_plugin_v1_enabled || util_op remove-plugin-network weave || true - stop $CONTAINER_NAME "Weave" - conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true -} - -launch_proxy() { - # Set WEAVEPROXY_DOCKER_ARGS in the environment in order to supply - # additional parameters, such as resource limits, to docker - # when launching the weaveproxy container. - docker_client_args $DOCKER_CLIENT_ARGS - proxy_args "$@" - mkdir -p /var/run/weave - # Create a data-only container to mount the weavewait files from - if ! docker inspect -f ' ' $VOLUMES_CONTAINER_NAME > /dev/null 2>&1 ; then - protect_against_docker_hang - docker create -v /w -v /w-noop -v /w-nomcast --name=$VOLUMES_CONTAINER_NAME \ - --label=weavevolumes --entrypoint=/bin/false $EXEC_IMAGE >/dev/null - fi - detect_awsvpc - [ -n "$AWSVPC" ] && PROXY_ARGS="$PROXY_ARGS --no-multicast-route" - PROXY_CONTAINER=$(docker run -d --name=$PROXY_CONTAINER_NAME \ - $(docker_run_options) \ - $RESTART_POLICY \ - --pid=host \ - $PROXY_VOLUMES \ - --volumes-from $VOLUMES_CONTAINER_NAME \ - -v /var/run/weave:/var/run/weave \ - -e DOCKER_BRIDGE \ - -e WEAVE_DEBUG \ - -e COVERAGE \ - -e WEAVE_HTTP_ADDR \ - -e EXEC_IMAGE=$EXEC_IMAGE \ - --entrypoint=/home/weave/weaveproxy \ - $WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $COVERAGE_ARGS $PROXY_ARGS) - wait_for_status $PROXY_CONTAINER_NAME http_call_unix $PROXY_CONTAINER_NAME status.sock -} - -stop_proxy() { warn_if_stopping_proxy_in_env - stop $PROXY_CONTAINER_NAME "Proxy" + docker stop $CONTAINER_NAME >/dev/null 2>&1 || echo "Weave is not running." >&2 + conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true } protect_against_docker_hang() { @@ -1521,7 +1477,6 @@ case "$COMMAND" in version) [ $# -eq 0 ] || usage ask_version $CONTAINER_NAME $IMAGE || true - ask_version $PROXY_CONTAINER_NAME $EXEC_IMAGE --entrypoint=/home/weave/weaveproxy || true ;; # intentionally undocumented since it assumes knowledge of weave # internals @@ -1553,25 +1508,9 @@ EOF launch) deprecation_warnings "$@" check_not_running router $CONTAINER_NAME $BASE_IMAGE - check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE check_not_running_plugin_v2 - COMMON_ARGS=$(common_launch_args "$@") - launch_router --plugin "$@" - launch_proxy $COMMON_ARGS - ;; - launch-router) - deprecation_warnings "$@" - check_not_running router $CONTAINER_NAME $BASE_IMAGE - check_not_running_plugin_v2 - launch_router "$@" - echo $ROUTER_CONTAINER - ;; - launch-proxy) - deprecation_warnings "$@" - check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE - check_not_running_plugin_v2 - launch_proxy "$@" - echo $PROXY_CONTAINER + launch --plugin "$@" + echo "$WEAVE_CONTAINER" ;; env) if PROXY_ADDR=$(proxy_addr) ; then @@ -1607,7 +1546,7 @@ EOF echo "Invalid 'weave status' sub-command: $SUB_COMMAND" >&2 usage fi - if [ -z "$SUB_STATUS" ] && check_running $PROXY_CONTAINER_NAME 2>/dev/null && PROXY_ADDRS=$(proxy_addrs) ; then + if [ -z "$SUB_STATUS" ] && PROXY_ADDRS=$(proxy_addrs) ; then echo echo " Service: proxy" echo " Address: $PROXY_ADDRS" @@ -1632,7 +1571,7 @@ EOF call_weave GET /report -H 'Accept: application/json' fi ;; - run|start|restart|launch-plugin|stop-plugin) + run|start|restart|launch-plugin|stop-plugin|launch-proxy|stop-proxy|launch-router|stop-router) echo "The 'weave $COMMAND' command has been removed as of Weave Net version 2.0" >&2 echo "Please see release notes for further information" >&2 exit 1 @@ -1759,18 +1698,10 @@ EOF ;; stop) [ $# -eq 0 ] || usage - stop_router - stop_proxy - # In case user has upgraded from /dev/null 2>&1 || true - ;; - stop-router) - [ $# -eq 0 ] || usage - stop_router - ;; - stop-proxy) - [ $# -eq 0 ] || usage - stop_proxy + docker stop $OLD_PROXY_CONTAINER_NAME >/dev/null 2>&1 || true ;; reset) [ $# -eq 0 ] || [ $# -eq 1 -a "$1" = "--force" ] || usage @@ -1792,7 +1723,7 @@ EOF exit 1 ;; esac - for NAME in $CONTAINER_NAME $PROXY_CONTAINER_NAME $OLD_PLUGIN_CONTAINER_NAME ; do + for NAME in $CONTAINER_NAME $OLD_PROXY_CONTAINER_NAME $OLD_PLUGIN_CONTAINER_NAME ; do docker stop $NAME >/dev/null 2>&1 || true docker rm -f $NAME >/dev/null 2>&1 || true done