diff --git a/weave b/weave index f08cdaad..88a88763 100755 --- a/weave +++ b/weave @@ -902,22 +902,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 } @@ -1674,7 +1674,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 \ @@ -1831,11 +1838,11 @@ 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 + # Don't check the plugin here, since we start it with `--restart=always` COMMON_ARGS=$(common_launch_args "$@") launch_router "$@" launch_proxy $COMMON_ARGS - plugin_disabled || launch_plugin $COMMON_ARGS + plugin_disabled || launch_plugin_if_not_running $COMMON_ARGS ;; launch-router) deprecation_warnings "$@" @@ -1858,8 +1865,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)