From bb8c7c599cdb2f4d8d2410772ba5b3ea68b1eb2f Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 12 Jan 2016 16:41:26 +0000 Subject: [PATCH 1/4] Revert "don't launch anything when plugin is running" This reverts commit 3ade796e8d18a9d4253ce464463dd94114300052. --- weave | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/weave b/weave index c37f332d..19f826e8 100755 --- a/weave +++ b/weave @@ -1846,11 +1846,14 @@ EOF deprecation_warnings "$@" check_not_running router $CONTAINER_NAME $BASE_IMAGE check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE - check_not_running plugin $PLUGIN_CONTAINER_NAME $BASE_PLUGIN_IMAGE COMMON_ARGS=$(common_launch_args "$@") launch_router "$@" launch_proxy $COMMON_ARGS - plugin_disabled || launch_plugin $COMMON_ARGS + # Allow an existing plugin to keep running, because we run it with restart=always + if ! plugin_disabled ; then + check_not_running plugin $PLUGIN_CONTAINER_NAME $BASE_PLUGIN_IMAGE + launch_plugin $COMMON_ARGS + fi ;; launch-router) deprecation_warnings "$@" From 517a2e0e0a0bdc7495af3c1b90fb78170e5c6328 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 12 Jan 2016 16:49:57 +0000 Subject: [PATCH 2/4] Fix nonzero exit code for a pre-existing plugin on launch; do this purely for the 'plugin running' case, not 'restarting' etc. --- weave | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/weave b/weave index 19f826e8..786f8999 100755 --- a/weave +++ b/weave @@ -909,22 +909,22 @@ check_not_running() { case ${RUN_STATUS%:*} in "true restarting $3") echo "$2 is restarting; you can stop it with 'weave stop-$1'." >&2 - exit 1 + return 3 ;; "true "*" $3") echo "$2 is already running; you can stop it with 'weave stop-$1'." >&2 - exit 1 + return 1 ;; "false "*" $3") docker rm $2 >/dev/null ;; true*) echo "Found another running container named '$2'. Aborting." >&2 - exit 1 + return 2 ;; false*) echo "Found another container named '$2'. Aborting." >&2 - exit 1 + return 2 ;; esac } @@ -1851,8 +1851,11 @@ EOF launch_proxy $COMMON_ARGS # Allow an existing plugin to keep running, because we run it with restart=always if ! plugin_disabled ; then - check_not_running plugin $PLUGIN_CONTAINER_NAME $BASE_PLUGIN_IMAGE - launch_plugin $COMMON_ARGS + if check_not_running plugin $PLUGIN_CONTAINER_NAME $BASE_PLUGIN_IMAGE ; then + launch_plugin $COMMON_ARGS + else + [ $? -lt 2 ] || exit 1 + fi fi ;; launch-router) From 3daceac668ff3955b9dea9482b6441dc7f365963 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 13 Jan 2016 10:03:43 +0000 Subject: [PATCH 3/4] Allow pre-existing plugin on 'weave launch-plugin' --- weave | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/weave b/weave index 786f8999..a96e2787 100755 --- a/weave +++ b/weave @@ -1689,7 +1689,14 @@ stop_proxy() { stop $PROXY_CONTAINER_NAME "Proxy" } -launch_plugin() { +launch_plugin_if_not_running() { + retval=0 + check_not_running plugin $PLUGIN_CONTAINER_NAME $BASE_PLUGIN_IMAGE || retval=$? + # If an existing plugin is running (we start it with restart=always), return its ID + [ $retval = 1 ] && PLUGIN_CONTAINER=$(container_id $PLUGIN_CONTAINER_NAME) && return 0 + # Any other kind of error code from check_not_running is a failure. + [ $retval -gt 0 ] && return $retval + PLUGIN_CONTAINER=$(docker run --privileged -d --name=$PLUGIN_CONTAINER_NAME \ --restart=always \ --net=host \ @@ -1849,14 +1856,7 @@ EOF COMMON_ARGS=$(common_launch_args "$@") launch_router "$@" launch_proxy $COMMON_ARGS - # Allow an existing plugin to keep running, because we run it with restart=always - if ! plugin_disabled ; then - if check_not_running plugin $PLUGIN_CONTAINER_NAME $BASE_PLUGIN_IMAGE ; then - launch_plugin $COMMON_ARGS - else - [ $? -lt 2 ] || exit 1 - fi - fi + plugin_disabled || launch_plugin_if_not_running $COMMON_ARGS ;; launch-router) deprecation_warnings "$@" @@ -1879,8 +1879,7 @@ EOF echo $PROXY_CONTAINER ;; launch-plugin) - check_not_running plugin $PLUGIN_CONTAINER_NAME $BASE_PLUGIN_IMAGE - launch_plugin "$@" + launch_plugin_if_not_running "$@" echo $PLUGIN_CONTAINER ;; env|proxy-env) From b055c9a4a2341f7333276af3b2b412f5870f41c7 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 13 Jan 2016 10:33:49 +0000 Subject: [PATCH 4/4] Fool-proofing --- weave | 1 + 1 file changed, 1 insertion(+) diff --git a/weave b/weave index a96e2787..7e98cb51 100755 --- a/weave +++ b/weave @@ -1853,6 +1853,7 @@ EOF deprecation_warnings "$@" check_not_running router $CONTAINER_NAME $BASE_IMAGE check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE + # Don't check the plugin here, since we start it with `--restart=always` COMMON_ARGS=$(common_launch_args "$@") launch_router "$@" launch_proxy $COMMON_ARGS