diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2017-04-25 10:52:49 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2017-04-26 06:38:42 +0000 |
commit | 35fc1d6a0a7fdbda33df9472cf3efe9b0fbcde05 (patch) | |
tree | cf2d8a84f2941aa187e2df49542ed04cf0c5ce6a /tcwg-cleanup-stale-containers.sh | |
parent | c66e43c40dde389252c0129951b90632b14ad76e (diff) |
tcwg-cleanup-stale-containers: Indent.
Change-Id: I18aecdf987ab3a479e26ab7f7c812a17751bdfd7
Diffstat (limited to 'tcwg-cleanup-stale-containers.sh')
-rwxr-xr-x | tcwg-cleanup-stale-containers.sh | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh index e03c00fa..be4064eb 100755 --- a/tcwg-cleanup-stale-containers.sh +++ b/tcwg-cleanup-stale-containers.sh @@ -42,42 +42,42 @@ do_cleanup_containers () cleanup_containers=false fi -echo "Container report before:" -$DOCKER ps $docker_ps_opts - -rm_containers=() -for container in $($DOCKER ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "hour\|day" | cut -d" " -f 1); do - container_days="$($DOCKER ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "$container [0-9]\+ day" | cut -d" " -f 2)" - if [ x"$container_days" = x"" ]; then container_days="0"; fi - - container_hours="$($DOCKER ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "$container [0-9]\+ hour" | cut -d" " -f 2)" - if [ x"$container_hours" = x"" ]; then container_hours="0"; fi - - container_hours=$(($container_days*24 + $container_hours)) - if [ "$container_hours" -gt "$hours" ]; then - rm_containers=("${rm_containers[@]}" $container) - fi -done + echo "Container report before:" + $DOCKER ps $docker_ps_opts -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 $cleanup_containers; then - for container in "${rm_containers[@]}"; do - echo "Removing container $container" - $DOCKER $action $container | cat - echo "$DOCKER $action exit status: ${PIPESTATUS[0]}" - done - else - echo "DRY_RUN: NOT REMOVING CONTAINERS" + rm_containers=() + for container in $($DOCKER ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "hour\|day" | cut -d" " -f 1); do + container_days="$($DOCKER ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "$container [0-9]\+ day" | cut -d" " -f 2)" + if [ x"$container_days" = x"" ]; then container_days="0"; fi + + container_hours="$($DOCKER ps --format "{{.ID}} {{.RunningFor}}" $docker_ps_opts | grep "$container [0-9]\+ hour" | cut -d" " -f 2)" + if [ x"$container_hours" = x"" ]; then container_hours="0"; fi + + container_hours=$(($container_days*24 + $container_hours)) + if [ "$container_hours" -gt "$hours" ]; then + rm_containers=("${rm_containers[@]}" $container) + fi + 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 $cleanup_containers; then + for container in "${rm_containers[@]}"; do + echo "Removing container $container" + $DOCKER $action $container | cat + echo "$DOCKER $action exit status: ${PIPESTATUS[0]}" + done + else + echo "DRY_RUN: NOT REMOVING CONTAINERS" + fi + + echo "Containers report after:" + $DOCKER ps $docker_ps_opts fi - echo "Containers report after:" - $DOCKER ps $docker_ps_opts -fi - exit $status } |