Merge pull request #1941 from weaveworks/issues/1873-check-running-master
Improve visibility of startup problems Fixes #1873.
This commit is contained in:
commit
98d76e1099
4 files changed
+49
-26
No files matched your search
@@ -943,23 +943,14 @@ stop() {
|
||||
}
|
||||
|
||||
# Given a container name or short ID in $1, ensure the specified
|
||||
# container is running and then print its full ID to stdout. If
|
||||
# it's not running or doesn't exist, print an error to stderr and
|
||||
# container exists and then print its full ID to stdout. If
|
||||
# it doesn't exist, print an error to stderr and
|
||||
# return with an indicative non-zero exit code.
|
||||
container_id() {
|
||||
if ! status=$(docker inspect --format='{{.State.Running}} {{.Id}}' $1 2>/dev/null) ; then
|
||||
if ! docker inspect --format='{{.Id}}' $1 2>/dev/null ; then
|
||||
echo "Error: No such container: $1" >&2
|
||||
return 1
|
||||
fi
|
||||
case "$status" in
|
||||
true*)
|
||||
echo "${status#true }"
|
||||
;;
|
||||
*)
|
||||
echo "$1 container is not running." >&2
|
||||
return 2
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
http_call() {
|
||||
@@ -1002,7 +993,8 @@ wait_for_status() {
|
||||
shift
|
||||
while true ; do
|
||||
"$@" GET /status >/dev/null 2>&1 && return 0
|
||||
if ! container_id $container >/dev/null 2>&1 ; then
|
||||
if ! check_running $container >/dev/null 2>&1 ; then
|
||||
docker kill $container >/dev/null 2>&1 || true # stop it restarting
|
||||
echo $(death_msg $container) >&2
|
||||
return 1
|
||||
fi
|
||||
@@ -1157,10 +1149,13 @@ rewrite_etc_hosts() {
|
||||
# Print an error to stderr and return with an indicative exit status
|
||||
# if the container $1 does not exist or isn't running.
|
||||
check_running() {
|
||||
if ! STATUS=$(docker inspect --format='{{.State.Running}}' $1 2>/dev/null) ; then
|
||||
if ! STATUS=$(docker inspect --format='{{.State.Running}} {{.State.Restarting}}' $1 2>/dev/null) ; then
|
||||
echo "$1 container is not present. Have you launched it?" >&2
|
||||
return 1
|
||||
elif [ "$STATUS" != "true" ] ; then
|
||||
elif [ "$STATUS" == "true true" ] ; then
|
||||
echo "$1 container is restarting." >&2
|
||||
return 2
|
||||
elif [ "$STATUS" != "true false" ] ; then
|
||||
echo "$1 container is not running." >&2
|
||||
return 2
|
||||
fi
|
||||
@@ -1234,6 +1229,7 @@ collect_dns_add_remove_args() {
|
||||
[ $# -eq 0 -a \( -n "$C" -o \( $IP_COUNT -gt 0 -a -n "$FQDN" \) \) ] || usage
|
||||
check_running $CONTAINER_NAME
|
||||
if [ -n "$C" ] ; then
|
||||
check_running $C
|
||||
CONTAINER=$(container_id $C)
|
||||
[ $IP_COUNT -gt 0 ] || IP_ARGS=$(with_container_addresses echo_ips $CONTAINER)
|
||||
fi
|
||||
@@ -1665,6 +1661,7 @@ launch_plugin_if_not_running() {
|
||||
$PLUGIN_IMAGE "$@") ; 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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user