Description
The docker-compose agent fails to correctly recognize that a service is running when there are multiple services running on the same machine.
The docker_compose_status function:
https://github.com/ClusterLabs/resource-agents/blob/main/heartbeat/docker-compose#L137
uses the output of docker ps
and calculates the offset of the STATUS column, and counts the number of Up
containers. This number needs to match the number of containers returned by docker-compose ps
.
The code at line 143:
https://github.com/ClusterLabs/resource-agents/blob/main/heartbeat/docker-compose#L143
replaces '\n' with '|' so that grep matches on multiple container IDs returned by docker-compose ps
(stored as $DKPS). However, since there is a '\n' at the end of docker ps --no-trunc
output, which makes the grep run with an regex of the form: "ID1|ID2|...|IDX|". Since this expression ends with '|' it matches the entire input.
This causes the value of $UPNU to be larger than the number of expected containers, making the status check fail by entering the else clause.
The fix I have used is to replace the code at line 143 with the following:
STAT_MSG=$(docker ps --no-trunc | grep -E $(echo "$DKPS" | tr '\n' '|' | sed 's/|$/|STATUS/') | expand)
this should capture only the container IDs in $DKPS and the header line, which is used for calculating the offset of the Up
column. This fix would clearly not work if the image name of a container included 'STATUS'.
Activity