Don't fail when docker confirms nothing is running

"Nothing on the host" meant two different things and the script treated
them the same. If docker answers and names no running containers, Maven
really is down and the script should say so and exit 0. Only when docker
cannot be asked is the answer unknown, and that is the case that must
fail loudly.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CGeSZxh1DCtRxmFVSYVGvJ
This commit is contained in:
kami
2026-07-31 14:32:45 +04:00
parent 02e8786695
commit 80f7322294
+12 -8
View File
@@ -76,15 +76,19 @@ host_pids() {
HOST_PIDS=$(host_pids) HOST_PIDS=$(host_pids)
if [ -z "$HOST_PIDS" ]; then if [ -z "$HOST_PIDS" ]; then
# Nothing to kill on the host and no running containers. Either Maven is # Nothing on the host. Whether that means "already down" depends on whether
# already down, or it is somewhere this script cannot see (another PID # we managed to ask docker, and the two must not read the same.
# namespace, another user, docker unreachable). We cannot tell the if [ "$DOCKER_OK" = 1 ]; then
# difference, so refuse to claim success. # Docker answered and named no running containers, and there is nothing
echo "ERROR: found no Maven processes on this host and no running containers." >&2 # on the host either. That is a real answer: Maven is already stopped.
if [ "$DOCKER_OK" != 1 ]; then echo "Nothing to stop: no Maven processes and no running containers."
echo " Could not ask docker either — if this is the container deploy," >&2 exit 0
echo " run: docker compose -f $COMPOSE_FILE stop" >&2
fi fi
# We could not ask docker, so Maven may be alive in a container we cannot
# see. Saying "stopped" here is the exact false success this script had.
echo "ERROR: no Maven processes on this host, and docker could not be asked." >&2
echo " If this is the container deploy it may still be running:" >&2
echo " docker compose -f $COMPOSE_FILE stop" >&2
echo " Nothing was stopped. Check by hand before assuming Maven is down." >&2 echo " Nothing was stopped. Check by hand before assuming Maven is down." >&2
exit 1 exit 1
fi fi