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
|
# functions for interacting with containers
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
pertinent_match_args() {
|
# Check that a container for component $1 named $2 with image $3 is not running
|
||||||
docker inspect -f '{{.Args}}
|
check_not_running() {
|
||||||
{{.Config.Env}}
|
RUN_STATUS=$(docker inspect --format='{{.State.Running}} {{.State.Status}} {{.Config.Image}}' $2 2>/dev/null) || true
|
||||||
{{.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##* }
|
|
||||||
case ${RUN_STATUS%:*} in
|
case ${RUN_STATUS%:*} in
|
||||||
"true $IMAGE_ID "*)
|
"true restarting $3")
|
||||||
if args_match $CONTAINER_ID "$@" ; then
|
echo "$2 is restarting; you can stop it with 'weave stop-$1'." >&2
|
||||||
ALREADY_RUNNING_CONTAINER=$CONTAINER_ID
|
return 3
|
||||||
echo $CONTAINER_ID
|
|
||||||
else
|
|
||||||
echo "$name is already running with different arguments; you can stop it with 'weave stop-$component'." >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
"false $IMAGE_ID "*)
|
"true "*" $3")
|
||||||
if args_match $CONTAINER_ID "$@" ; then
|
echo "$2 is already running; you can stop it with 'weave stop-$1'." >&2
|
||||||
docker start $CONTAINER_ID
|
return 1
|
||||||
else
|
|
||||||
docker rm $name >/dev/null
|
|
||||||
docker run -d --name=$name "$@"
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
true*$image_base)
|
"false "*" $3")
|
||||||
echo "Found another version of $name running. Aborting." >&2
|
docker rm $2 >/dev/null
|
||||||
return 2
|
|
||||||
;;
|
;;
|
||||||
true*)
|
true*)
|
||||||
echo "Found another running container named '$name'. Aborting." >&2
|
echo "Found another running container named '$2'. Aborting." >&2
|
||||||
return 2
|
return 2
|
||||||
;;
|
;;
|
||||||
false*)
|
false*)
|
||||||
docker rm $name >/dev/null
|
echo "Found another container named '$2'. Aborting." >&2
|
||||||
docker run -d --name=$name "$@"
|
return 2
|
||||||
;;
|
|
||||||
"")
|
|
||||||
docker run -d --name=$name "$@"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -1189,7 +1152,6 @@ check_running() {
|
|||||||
echo "$1 container is not present. Have you launched it?" >&2
|
echo "$1 container is not present. Have you launched it?" >&2
|
||||||
return 1
|
return 1
|
||||||
elif [ "$STATUS" = "true true" ] ; then
|
elif [ "$STATUS" = "true true" ] ; then
|
||||||
[ -n "$ALREADY_RUNNING_CONTAINER" ] && return 0
|
|
||||||
echo "$1 container is restarting." >&2
|
echo "$1 container is restarting." >&2
|
||||||
return 2
|
return 2
|
||||||
elif [ "$STATUS" != "true false" ] ; then
|
elif [ "$STATUS" != "true false" ] ; then
|
||||||
@@ -1627,7 +1589,7 @@ launch_router() {
|
|||||||
# Set WEAVE_DOCKER_ARGS in the environment in order to supply
|
# Set WEAVE_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 weave container.
|
# when launching the weave container.
|
||||||
start_if_necessary router $CONTAINER_NAME $IMAGE \
|
ROUTER_CONTAINER=$(docker run -d --name=$CONTAINER_NAME \
|
||||||
$(docker_run_options) \
|
$(docker_run_options) \
|
||||||
$RESTART_POLICY \
|
$RESTART_POLICY \
|
||||||
--volumes-from $DB_CONTAINER_NAME \
|
--volumes-from $DB_CONTAINER_NAME \
|
||||||
@@ -1640,10 +1602,10 @@ launch_router() {
|
|||||||
--dns-effective-listen-address $DOCKER_BRIDGE_IP \
|
--dns-effective-listen-address $DOCKER_BRIDGE_IP \
|
||||||
$DNS_ROUTER_OPTS $NO_DNS_OPT \
|
$DNS_ROUTER_OPTS $NO_DNS_OPT \
|
||||||
--http-addr $HTTP_ADDR \
|
--http-addr $HTTP_ADDR \
|
||||||
"$@"
|
"$@")
|
||||||
setup_router_iface_$BRIDGE_TYPE
|
setup_router_iface_$BRIDGE_TYPE
|
||||||
wait_for_status $CONTAINER_NAME http_call $HTTP_ADDR
|
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
|
# 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 \
|
docker create -v /w -v /w-noop -v /w-nomcast --name=$VOLUMES_CONTAINER_NAME \
|
||||||
--label=weavevolumes --entrypoint=/bin/false $EXEC_IMAGE >/dev/null
|
--label=weavevolumes --entrypoint=/bin/false $EXEC_IMAGE >/dev/null
|
||||||
fi
|
fi
|
||||||
start_if_necessary proxy $PROXY_CONTAINER_NAME $EXEC_IMAGE \
|
PROXY_CONTAINER=$(docker run -d --name=$PROXY_CONTAINER_NAME \
|
||||||
$(docker_run_options) \
|
$(docker_run_options) \
|
||||||
$RESTART_POLICY \
|
$RESTART_POLICY \
|
||||||
--pid=host \
|
--pid=host \
|
||||||
@@ -1700,7 +1662,7 @@ launch_proxy() {
|
|||||||
-e WEAVE_HTTP_ADDR \
|
-e WEAVE_HTTP_ADDR \
|
||||||
-e EXEC_IMAGE=$EXEC_IMAGE \
|
-e EXEC_IMAGE=$EXEC_IMAGE \
|
||||||
--entrypoint=/home/weave/weaveproxy \
|
--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
|
wait_for_status $PROXY_CONTAINER_NAME http_call_unix $PROXY_CONTAINER_NAME status.sock
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1721,13 +1683,23 @@ launch_plugin_if_not_running() {
|
|||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
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) \
|
$(docker_run_options) \
|
||||||
$RESTART_POLICY \
|
$RESTART_POLICY \
|
||||||
-v /run/docker/plugins:/run/docker/plugins \
|
-v /run/docker/plugins:/run/docker/plugins \
|
||||||
-e WEAVE_HTTP_ADDR \
|
-e WEAVE_HTTP_ADDR \
|
||||||
$WEAVEPLUGIN_DOCKER_ARGS $PLUGIN_IMAGE $COVERAGE_ARGS \
|
$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
|
wait_for_status $PLUGIN_CONTAINER_NAME http_call_unix $PLUGIN_CONTAINER_NAME status.sock
|
||||||
util_op create-plugin-network weave weavemesh
|
util_op create-plugin-network weave weavemesh
|
||||||
}
|
}
|
||||||
@@ -1905,14 +1877,19 @@ EOF
|
|||||||
;;
|
;;
|
||||||
launch)
|
launch)
|
||||||
deprecation_warnings "$@"
|
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 "$@")
|
COMMON_ARGS=$(common_launch_args "$@")
|
||||||
launch_router "$@" >/dev/null
|
launch_router "$@"
|
||||||
launch_proxy $COMMON_ARGS >/dev/null
|
launch_proxy $COMMON_ARGS
|
||||||
plugin_disabled || launch_plugin_if_not_running $COMMON_ARGS >/dev/null
|
plugin_disabled || launch_plugin_if_not_running $COMMON_ARGS
|
||||||
;;
|
;;
|
||||||
launch-router)
|
launch-router)
|
||||||
deprecation_warnings "$@"
|
deprecation_warnings "$@"
|
||||||
|
check_not_running router $CONTAINER_NAME $BASE_IMAGE
|
||||||
launch_router "$@"
|
launch_router "$@"
|
||||||
|
echo $ROUTER_CONTAINER
|
||||||
;;
|
;;
|
||||||
attach-router)
|
attach-router)
|
||||||
check_running $CONTAINER_NAME
|
check_running $CONTAINER_NAME
|
||||||
@@ -1925,10 +1902,13 @@ EOF
|
|||||||
;;
|
;;
|
||||||
launch-proxy)
|
launch-proxy)
|
||||||
deprecation_warnings "$@"
|
deprecation_warnings "$@"
|
||||||
|
check_not_running proxy $PROXY_CONTAINER_NAME $BASE_EXEC_IMAGE
|
||||||
launch_proxy "$@"
|
launch_proxy "$@"
|
||||||
|
echo $PROXY_CONTAINER
|
||||||
;;
|
;;
|
||||||
launch-plugin)
|
launch-plugin)
|
||||||
launch_plugin_if_not_running "$@"
|
launch_plugin_if_not_running "$@"
|
||||||
|
echo $PLUGIN_CONTAINER
|
||||||
;;
|
;;
|
||||||
env|proxy-env)
|
env|proxy-env)
|
||||||
[ "$COMMAND" = "env" ] || deprecation_warning "$COMMAND" "'weave env'"
|
[ "$COMMAND" = "env" ] || deprecation_warning "$COMMAND" "'weave env'"
|
||||||
|
|||||||
Reference in new issue
Block a user