Factor out routine to check if a container is already running

Conflicts:
	weave
This commit is contained in:
Bryan Boreham authored and Michael Bridgen committed 2014-10-29 14:20:24 +00:00
1 parent 75deacaed0
commit f56700a032
1 file changed
+14 -9
+14 -9
View File
@@ -279,25 +279,30 @@ rest_call() {
fi fi
} }
case "$COMMAND" in # Check that a container named $1 with image $2 is not running
launch) check_not_running() {
case $(docker inspect --format '{{ .State.Running }} {{ .Config.Image }}' $CONTAINER_NAME 2>/dev/null) in case $(docker inspect --format '{{ .State.Running }} {{ .Config.Image }}' $1 2>/dev/null) in
"true $IMAGE") "true $2")
echo "Weave is already running." >&2 echo "$1 is already running." >&2
exit 1 exit 1
;; ;;
"false $IMAGE") "false $2")
docker rm $CONTAINER_NAME >/dev/null docker rm $1 >/dev/null
;; ;;
true*) true*)
echo "Found another running container named '$CONTAINER_NAME'. Aborting." >&2 echo "Found another running container named '$1'. Aborting." >&2
exit 1 exit 1
;; ;;
false*) false*)
echo "Found another container named '$CONTAINER_NAME'. Aborting." >&2 echo "Found another container named '$1'. Aborting." >&2
exit 1 exit 1
;; ;;
esac esac
}
case "$COMMAND" in
launch)
check_not_running $CONTAINER_NAME $IMAGE
create_bridge create_bridge
# We set the router name to the bridge mac since that is # We set the router name to the bridge mac since that is
# stable across re-creations of the containers. # stable across re-creations of the containers.