File 0009-Medium-docker-Use-docker-exec-for-monitor_cmd-if-sup.patch of Package resource-agents.8843
From 0b995c1afe64796cc6c9bc9f32a8eef521e8d34e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristoffer=20Gr=C3=B6nlund?= <krig@koru.se>
Date: Tue, 18 Oct 2016 20:13:10 +0200
Subject: [PATCH 09/12] Medium: docker: Use docker exec for monitor_cmd if
supported
---
heartbeat/docker | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/heartbeat/docker b/heartbeat/docker
index 5af1782..d173e90 100755
--- a/heartbeat/docker
+++ b/heartbeat/docker
@@ -113,8 +113,8 @@ the health of the container. This command must return 0 to indicate that
the container is healthy. A non-zero return code will indicate that the
container has failed and should be recovered.
-The command is executed using nsenter. In the future 'docker exec' will
-be used once it is more widely supported.
+If 'docker exec' is supported, it is used to execute the command. If not,
+nsenter is used.
</longdesc>
<shortdesc lang="en">monitor command</shortdesc>
<content type="string"/>
@@ -174,8 +174,14 @@ monitor_cmd_exec()
return $rc
fi
- out=$(echo "$OCF_RESKEY_monitor_cmd" | nsenter --target $(docker inspect --format {{.State.Pid}} ${CONTAINER}) --mount --uts --ipc --net --pid 2>&1)
- rc=$?
+ if docker exec --help >/dev/null 2>&1; then
+ out=$(docker exec ${CONTAINER} $OCF_RESKEY_monitor_cmd 2>&1)
+ rc=$?
+ else
+ out=$(echo "$OCF_RESKEY_monitor_cmd" | nsenter --target $(docker inspect --format {{.State.Pid}} ${CONTAINER}) --mount --uts --ipc --net --pid 2>&1)
+ rc=$?
+ fi
+
if [ $rc -ne 0 ]; then
ocf_log info "monitor cmd exit code = $rc"
ocf_log info "stdout/stderr: $out"
@@ -390,8 +396,11 @@ docker_validate()
fi
if [ -n "$OCF_RESKEY_monitor_cmd" ]; then
- ocf_log info "checking for nsenter, which is required when 'monitor_cmd' is specified"
- check_binary nsenter
+ docker exec --help >/dev/null 2>&1
+ if [ ! $? ]; then
+ ocf_log info "checking for nsenter, which is required when 'monitor_cmd' is specified"
+ check_binary nsenter
+ fi
fi
image_exists
--
2.10.1