Revert #1967 (container reuse)
This commit is contained in:
1 parent
166d4afad8
commit
5e03c0fe25
2 files changed
+42
-92
No files matched your search
@@ -1,30 +0,0 @@
|
||||
#! /bin/bash
|
||||
|
||||
. ./config.sh
|
||||
|
||||
start_suite "Check restart re-uses same container when possible"
|
||||
|
||||
ID=$(weave_on $HOST1 launch-router)
|
||||
weave_on $HOST1 stop-router
|
||||
assert "weave_on $HOST1 launch-router" "$ID"
|
||||
# Can't start if already running with different args
|
||||
assert_raises "weave_on $HOST1 launch-router --log-level=debug" 1
|
||||
# Stop then start with different arg
|
||||
weave_on $HOST1 stop-router
|
||||
ID2=$(weave_on $HOST1 launch-router --log-level=debug)
|
||||
assert "[ $ID != $ID2 ]"
|
||||
|
||||
# Stop then start with different password
|
||||
weave_on $HOST1 stop-router
|
||||
ID3=$(weave_on $HOST1 launch-router --password=xyzzy)
|
||||
assert "[ $ID2 != $ID3 ]"
|
||||
# Stop then start with same password
|
||||
weave_on $HOST1 stop-router
|
||||
assert "weave_on $HOST1 launch-router --password=xyzzy" "$ID3"
|
||||
|
||||
# Fails on bad argument
|
||||
assert_raises "weave_on $HOST1 launch-plugin --foo" 1
|
||||
# Fails again on bad argument, although there is a dead container
|
||||
assert_raises "weave_on $HOST1 launch-plugin --foo" 1
|
||||
|
||||
end_suite
|
||||
@@ -893,65 +893,28 @@ attach() {
|
||||
# functions for interacting with containers
|
||||
######################################################################
|
||||
|
||||
pertinent_match_args() {
|
||||
docker inspect -f '{{.Args}}
|
||||
{{.Config.Env}}
|
||||
{{.HostConfig.RestartPolicy.Name}}
|
||||
{{.HostConfig.RestartPolicy.MaximumRetryCount}}' $1
|
||||
}
|
||||
|
||||
args_match() {
|
||||
prev_args="$(pertinent_match_args $1)" || return 1
|
||||
shift
|
||||
dummy_container=$(docker create "$@" 2>/dev/null) || return 1
|
||||
dummy_args="$(pertinent_match_args $dummy_container)" || return 1
|
||||
docker rm $dummy_container >/dev/null
|
||||
[ "$prev_args" = "$dummy_args" ]
|
||||
}
|
||||
|
||||
# Check if a container for component $1 named $2 with image $3 and args $4... is running,
|
||||
# and start it if necessary
|
||||
start_if_necessary() {
|
||||
component=$1
|
||||
name=$2
|
||||
image=$3
|
||||
shift 3
|
||||
image_base=${image%:*}
|
||||
IMAGE_ID=$(docker inspect --format='{{.Id}}' $image 2>/dev/null) || true
|
||||
RUN_STATUS=$(docker inspect --format='{{.State.Running}} {{.Image}} {{.Config.Image}} {{.Id}}' $name 2>/dev/null) || true
|
||||
CONTAINER_ID=${RUN_STATUS##* }
|
||||
# Check that a container for component $1 named $2 with image $3 is not running
|
||||
check_not_running() {
|
||||
RUN_STATUS=$(docker inspect --format='{{.State.Running}} {{.State.Status}} {{.Config.Image}}' $2 2>/dev/null) || true
|
||||
case ${RUN_STATUS%:*} in
|
||||
"true $IMAGE_ID "*)
|
||||
if args_match $CONTAINER_ID "$@" ; then
|
||||
ALREADY_RUNNING_CONTAINER=$CONTAINER_ID
|
||||
echo $CONTAINER_ID
|
||||
else
|
||||
echo "$name is already running with different arguments; you can stop it with 'weave stop-$component'." >&2
|
||||
return 1
|
||||
fi
|
||||
"true restarting $3")
|
||||
echo "$2 is restarting; you can stop it with 'weave stop-$1'." >&2
|
||||
return 3
|
||||
;;
|
||||
"false $IMAGE_ID "*)
|
||||
if args_match $CONTAINER_ID "$@" ; then
|
||||
docker start $CONTAINER_ID
|
||||
else
|
||||
docker rm $name >/dev/null
|
||||
docker run -d --name=$name "$@"
|
||||
fi
|
||||
"true "*" $3")
|
||||
echo "$2 is already running; you can stop it with 'weave stop-$1'." >&2
|
||||
return 1
|
||||
;;
|
||||
true*$image_base)
|
||||
echo "Found another version of $name running. Aborting." >&2
|
||||
return 2
|
||||
"false "*" $3")
|
||||
docker rm $2 >/dev/null
|
||||
;;
|
||||
true*)
|
||||
echo "Found another running container named '$name'. Aborting." >&2
|
||||
echo "Found another running container named '$2'. Aborting." >&2
|
||||
return 2
|
||||
;;
|
||||
false*)
|
||||
docker rm $name >/dev/null
|
||||
docker run -d --name=$name "$@"
|
||||
;;
|
||||
"")
|
||||
docker run -d --name=$name "$@"
|
||||
echo "Found another container named '$2'. Aborting." >&2
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -1189,7 +1152,6 @@ check_running() {
|
||||
echo "$1 container is not present. Have you launched it?" >&2
|
||||
return 1
|
||||
elif [ "$STATUS" = "true true" ] ; then
|
||||
[ -n "$ALREADY_RUNNING_CONTAINER" ] && return 0
|
||||
echo "$1 container is restarting." >&2
|
||||
return 2
|
||||
elif [ "$STATUS" != "true false" ] ; then
|
||||
@@ -1627,7 +1589,7 @@ launch_router() {
|
||||
# Set WEAVE_DOCKER_ARGS in the environment in order to supply
|
||||
# additional parameters, such as resource limits, to docker
|
||||
# when launching the weave container.
|
||||
start_if_necessary router $CONTAINER_NAME $IMAGE \
|
||||
ROUTER_CONTAINER=$(docker run -d --name=$CONTAINER_NAME \
|
||||
$(docker_run_options) \
|
||||
$RESTART_POLICY \
|
||||
--volumes-from $DB_CONTAINER_NAME \
|
||||
@@ -1640,10 +1602,10 @@ launch_router() {
|
||||
--dns-effective-listen-address $DOCKER_BRIDGE_IP \
|
||||
$DNS_ROUTER_OPTS $NO_DNS_OPT \
|
||||
--http-addr $HTTP_ADDR \
|
||||
"$@"
|
||||
"$@")
|
||||
setup_router_iface_$BRIDGE_TYPE
|
||||
wait_for_status $CONTAINER_NAME http_call $HTTP_ADDR
|
||||
[ -n "$ALREADY_RUNNING_CONTAINER" ] || populate_router
|
||||
populate_router
|
||||
}
|
||||
|
||||
# Recreate the parameter values that are set when the router is first launched
|
||||
@@ -1687,7 +1649,7 @@ launch_proxy() {
|
||||
docker create -v /w -v /w-noop -v /w-nomcast --name=$VOLUMES_CONTAINER_NAME \
|
||||
--label=weavevolumes --entrypoint=/bin/false $EXEC_IMAGE >/dev/null
|
||||
fi
|
||||
start_if_necessary proxy $PROXY_CONTAINER_NAME $EXEC_IMAGE \
|
||||
PROXY_CONTAINER=$(docker run -d --name=$PROXY_CONTAINER_NAME \
|
||||
$(docker_run_options) \
|
||||
$RESTART_POLICY \
|
||||
--pid=host \
|
||||
@@ -1700,7 +1662,7 @@ launch_proxy() {
|
||||
-e WEAVE_HTTP_ADDR \
|
||||
-e EXEC_IMAGE=$EXEC_IMAGE \
|
||||
--entrypoint=/home/weave/weaveproxy \
|
||||
$WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $COVERAGE_ARGS $PROXY_ARGS
|
||||
$WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $COVERAGE_ARGS $PROXY_ARGS)
|
||||
wait_for_status $PROXY_CONTAINER_NAME http_call_unix $PROXY_CONTAINER_NAME status.sock
|
||||
}
|
||||
|
||||
@@ -1721,13 +1683,23 @@ launch_plugin_if_not_running() {
|
||||
esac
|
||||
shift
|
||||
done
|
||||
start_if_necessary plugin $PLUGIN_CONTAINER_NAME $PLUGIN_IMAGE \
|
||||
|
||||
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
|
||||
|
||||
if ! PLUGIN_CONTAINER=$(docker run -d --name=$PLUGIN_CONTAINER_NAME \
|
||||
$(docker_run_options) \
|
||||
$RESTART_POLICY \
|
||||
-v /run/docker/plugins:/run/docker/plugins \
|
||||
-e WEAVE_HTTP_ADDR \
|
||||
$WEAVEPLUGIN_DOCKER_ARGS $PLUGIN_IMAGE $COVERAGE_ARGS \
|
||||
"$@"
|
||||
"$@") ; then
|
||||
return 1
|
||||
fi
|
||||
wait_for_status $PLUGIN_CONTAINER_NAME http_call_unix $PLUGIN_CONTAINER_NAME status.sock
|
||||
util_op create-plugin-network weave weavemesh
|
||||
}
|
||||
@@ -1905,14 +1877,19 @@ 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 $PLUGIN_CONTAINER_NAME $BASE_PLUGIN_IMAGE
|
||||
COMMON_ARGS=$(common_launch_args "$@")
|
||||
launch_router "$@" >/dev/null
|
||||
launch_proxy $COMMON_ARGS >/dev/null
|
||||
plugin_disabled || launch_plugin_if_not_running $COMMON_ARGS >/dev/null
|
||||
launch_router "$@"
|
||||
launch_proxy $COMMON_ARGS
|
||||
plugin_disabled || launch_plugin_if_not_running $COMMON_ARGS
|
||||
;;
|
||||
launch-router)
|
||||
deprecation_warnings "$@"
|
||||
check_not_running router $CONTAINER_NAME $BASE_IMAGE
|
||||
launch_router "$@"
|
||||
echo $ROUTER_CONTAINER
|
||||
;;
|
||||
attach-router)
|
||||
check_running $CONTAINER_NAME
|
||||
@@ -1925,10 +1902,13 @@ EOF
|
||||
;;
|
||||
launch-proxy)
|
||||
deprecation_warnings "$@"
|
||||
check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE
|
||||
launch_proxy "$@"
|
||||
echo $PROXY_CONTAINER
|
||||
;;
|
||||
launch-plugin)
|
||||
launch_plugin_if_not_running "$@"
|
||||
echo $PLUGIN_CONTAINER
|
||||
;;
|
||||
env|proxy-env)
|
||||
[ "$COMMAND" = "env" ] || deprecation_warning "$COMMAND" "'weave env'"
|
||||
|
||||
Reference in new issue
Block a user