Skip to content

Commit 9b6144e

Browse files
committed
Refactor cleanup function to bubble up failures
1 parent 69b94f6 commit 9b6144e

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

lib/run.bash

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
#!/bin/bash
22

33
compose_cleanup() {
4+
local FAILURES=0
5+
46
if [[ "$(plugin_read_config GRACEFUL_SHUTDOWN 'false')" == "false" ]]; then
5-
# Send all containers a SIGKILL
6-
run_docker_compose kill || true
7+
SIGNAL="kill"
78
else
8-
# Send all containers a friendly SIGTERM, followed by a SIGKILL after exceeding the stop_grace_period
9-
run_docker_compose stop || true
9+
SIGNAL="stop"
10+
fi
11+
12+
# Send all containers the corresponding signal
13+
if ! run_docker_compose "${SIGNAL}"; then
14+
FAILURES=$((FAILURES + 1))
1015
fi
1116

1217
# `compose down` doesn't support force removing images
18+
RM_PARAMS=(rm --force)
1319
if [[ "$(plugin_read_config LEAVE_VOLUMES 'false')" == "false" ]]; then
14-
run_docker_compose rm --force -v || true
15-
else
16-
run_docker_compose rm --force || true
20+
RM_PARAMS+=(-v)
21+
fi
22+
23+
if ! run_docker_compose "${RM_PARAMS[@]}"; then
24+
FAILURES=$((FAILURES + 1))
1725
fi
1826

1927
# Stop and remove all the linked services and network
28+
DOWN_PARAMS=(down --remove-orphans)
2029
if [[ "$(plugin_read_config LEAVE_VOLUMES 'false')" == "false" ]]; then
21-
run_docker_compose down --remove-orphans --volumes || true
22-
else
23-
run_docker_compose down --remove-orphans || true
30+
DOWN_PARAMS+=(--volumes)
2431
fi
32+
33+
if ! run_docker_compose "${DOWN_PARAMS[@]}"; then
34+
FAILURES=$((FAILURES + 1))
35+
fi
36+
37+
return "${FAILURES}"
2538
}
2639

2740
# Checks for failed containers and writes logs for them the the provided dir

0 commit comments

Comments
 (0)