diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2016-11-08 14:18:48 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2016-11-08 14:18:48 +0000 |
commit | 0650bee078261e00fb42985e8d0c37c58ba8fea1 (patch) | |
tree | 92e0eb089634e74e0cee683c5534e99ff793b2ff /tcwg-cleanup-stale-containers.sh | |
parent | 561a1475dacfc36314cde01d18b6208c4845ff9c (diff) |
tcwg-cleanup-stale-containers: Handle dangling volumes and "docker rm" exit code
Handling dangling volumes is straight-forward.
For unknown to me reasons "docker rm" return non-zero exit code when
successfully removing a container. Maybe it is proxying exit code from
the container's main process (sshd in our case).
In any case, we now switch to the meaning of the exit code to
zero -- nothing to do;
non-zero -- something was cleaned up.
Change-Id: I16eb5946055a828511d320dcfc28933c7af5a2d8
Diffstat (limited to 'tcwg-cleanup-stale-containers.sh')
-rwxr-xr-x | tcwg-cleanup-stale-containers.sh | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh index 523001e3..20d5272a 100755 --- a/tcwg-cleanup-stale-containers.sh +++ b/tcwg-cleanup-stale-containers.sh @@ -40,23 +40,32 @@ done status="0" if [ ${#rm_containers[@]} != 0 ]; then echo "Removing containers: ${rm_containers[@]}" + echo "Increasing exit code by 1 to indicate stale containers" + status="$(($status+1))" if ! $dry_run; then for container in "${rm_containers[@]}"; do echo "Removing container $container" - docker rm -f -v $container | true - if [ x"${PIPESTATUS[0]}" = x"0" ]; then - echo "SUCCESS" - else - echo "FAILED" - status="1" - fi + docker rm -f -v $container | cat + echo "docker rm exit status: ${PIPESTATUS[0]}" done else echo "DRY_RUN: NOT REMOVING CONTAINERS" - status="1" fi echo "Containers report after:" docker ps $docker_ps_opts fi + +if [ x"$(docker volume ls -q -f dangling=true)" != x"" ]; then + echo "Removing dangling volumes" + echo "Increasing exit code by 2 to indicate dangling volumes" + status="$(($status+2))" + if ! $dry_run; then + docker volume ls -q -f dangling=true | xargs docker volume rm | cat + echo "xargs docker volume rm exit status: ${PIPESTATUS[1]}" + else + echo "DRY_RUN: NOT REMOVING DANGLING VOLUMES" + fi +fi + exit $status |