|
|
81fafb |
From 5949405d0031a4aba91c81cb28c24821ad2d439a Mon Sep 17 00:00:00 2001
|
|
|
81fafb |
From: Reid Wahl <nwahl@redhat.com>
|
|
|
81fafb |
Date: Thu, 3 Jan 2019 15:05:20 -0800
|
|
|
81fafb |
Subject: [PATCH] docker: Fix issues with stop operation
|
|
|
81fafb |
|
|
|
81fafb |
The docker RA's stop operation doesn't behave properly in some cases.
|
|
|
81fafb |
1. It returns a false success code in case of an error response from
|
|
|
81fafb |
the daemon.
|
|
|
81fafb |
2. It fails at `remove_container()` if the container does not exist
|
|
|
81fafb |
but another docker object of the same name does exist.
|
|
|
81fafb |
|
|
|
81fafb |
In case #1, the `container_exists()` function returns the same exit code
|
|
|
81fafb |
(1) if the container is not found (an expected error) or if there is an
|
|
|
81fafb |
error response from the docker daemon (an unexpected error). These types
|
|
|
81fafb |
of errors should be handled differently.
|
|
|
81fafb |
|
|
|
81fafb |
In case #2, the `docker inspect` calls do not limit their search to
|
|
|
81fafb |
containers. So if a non-container object is found with a matching name,
|
|
|
81fafb |
the RA attempts to remove a container by that name. Such a container may
|
|
|
81fafb |
not exist.
|
|
|
81fafb |
|
|
|
81fafb |
This patch fixes these issues as follows:
|
|
|
81fafb |
1. Match an error response in `container_exists()` against the string
|
|
|
81fafb |
"No such container".
|
|
|
81fafb |
2. Add `--type=container` to the `docker inspect` calls to restrict
|
|
|
81fafb |
the match.
|
|
|
81fafb |
---
|
|
|
81fafb |
heartbeat/docker | 26 ++++++++++++++++++++++----
|
|
|
81fafb |
1 file changed, 22 insertions(+), 4 deletions(-)
|
|
|
81fafb |
|
|
|
81fafb |
diff --git a/heartbeat/docker b/heartbeat/docker
|
|
|
81fafb |
index f5ba83ff2..c206344ad 100755
|
|
|
81fafb |
--- a/heartbeat/docker
|
|
|
81fafb |
+++ b/heartbeat/docker
|
|
|
81fafb |
@@ -215,7 +215,7 @@ monitor_cmd_exec()
|
|
|
81fafb |
out=$(docker exec ${CONTAINER} $OCF_RESKEY_monitor_cmd 2>&1)
|
|
|
81fafb |
rc=$?
|
|
|
81fafb |
else
|
|
|
81fafb |
- out=$(echo "$OCF_RESKEY_monitor_cmd" | nsenter --target $(docker inspect --format {{.State.Pid}} ${CONTAINER}) --mount --uts --ipc --net --pid 2>&1)
|
|
|
81fafb |
+ out=$(echo "$OCF_RESKEY_monitor_cmd" | nsenter --target $(docker inspect --type=container --format {{.State.Pid}} ${CONTAINER}) --mount --uts --ipc --net --pid 2>&1)
|
|
|
81fafb |
rc=$?
|
|
|
81fafb |
fi
|
|
|
81fafb |
|
|
|
81fafb |
@@ -236,7 +236,25 @@ monitor_cmd_exec()
|
|
|
81fafb |
|
|
|
81fafb |
container_exists()
|
|
|
81fafb |
{
|
|
|
81fafb |
- docker inspect --format {{.State.Running}} $CONTAINER | egrep '(true|false)' >/dev/null 2>&1
|
|
|
81fafb |
+ local err
|
|
|
81fafb |
+
|
|
|
81fafb |
+ err=$(docker inspect --type=container $CONTAINER 2>&1 >/dev/null)
|
|
|
81fafb |
+
|
|
|
81fafb |
+ if [ $? -ne $OCF_SUCCESS ]; then
|
|
|
81fafb |
+ case $err in
|
|
|
81fafb |
+ *"No such container"*)
|
|
|
81fafb |
+ # Return failure instead of exiting if container does not exist
|
|
|
81fafb |
+ return 1
|
|
|
81fafb |
+ ;;
|
|
|
81fafb |
+ *)
|
|
|
81fafb |
+ # Exit if error running command
|
|
|
81fafb |
+ ocf_exit_reason "$err"
|
|
|
81fafb |
+ exit $OCF_ERR_GENERIC
|
|
|
81fafb |
+ ;;
|
|
|
81fafb |
+ esac
|
|
|
81fafb |
+ fi
|
|
|
81fafb |
+
|
|
|
81fafb |
+ return $OCF_SUCCESS
|
|
|
81fafb |
}
|
|
|
81fafb |
|
|
|
81fafb |
remove_container()
|
|
|
81fafb |
@@ -265,7 +283,7 @@ docker_simple_status()
|
|
|
81fafb |
fi
|
|
|
81fafb |
|
|
|
81fafb |
# retrieve the 'Running' attribute for the container
|
|
|
81fafb |
- val=$(docker inspect --format {{.State.Running}} $CONTAINER 2>/dev/null)
|
|
|
81fafb |
+ val=$(docker inspect --type=container --format {{.State.Running}} $CONTAINER 2>/dev/null)
|
|
|
81fafb |
if [ $? -ne 0 ]; then
|
|
|
81fafb |
#not running as a result of container not being found
|
|
|
81fafb |
return $OCF_NOT_RUNNING
|
|
|
81fafb |
@@ -295,7 +313,7 @@ docker_health_status()
|
|
|
81fafb |
# if starting takes longer than monitor timeout then upstream will make this fail.
|
|
|
81fafb |
while
|
|
|
81fafb |
|
|
|
81fafb |
- val=$(docker inspect --format {{.State.Health.Status}} $CONTAINER 2>/dev/null)
|
|
|
81fafb |
+ val=$(docker inspect --type=container --format {{.State.Health.Status}} $CONTAINER 2>/dev/null)
|
|
|
81fafb |
if [ $? -ne 0 ]; then
|
|
|
81fafb |
#not healthy as a result of container not being found
|
|
|
81fafb |
return $OCF_NOT_RUNNING
|