YETUS-94. docker cleanup invalid date
Project: http://git-wip-us.apache.org/repos/asf/yetus/repo Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/6319a18a Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/6319a18a Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/6319a18a Branch: refs/heads/YETUS-83 Commit: 6319a18a0582c2091fe9ab39648214e22e74dfb4 Parents: e59a76b Author: Allen Wittenauer <[email protected]> Authored: Tue Oct 20 16:55:02 2015 -0700 Committer: Allen Wittenauer <[email protected]> Committed: Fri Oct 23 20:39:49 2015 -0700 ---------------------------------------------------------------------- .../test-patch-docker/test-patch-docker.sh | 34 +++++++++++--------- 1 file changed, 19 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/yetus/blob/6319a18a/dev-support/test-patch-docker/test-patch-docker.sh ---------------------------------------------------------------------- diff --git a/dev-support/test-patch-docker/test-patch-docker.sh b/dev-support/test-patch-docker/test-patch-docker.sh index 8b19502..ca910ff 100755 --- a/dev-support/test-patch-docker/test-patch-docker.sh +++ b/dev-support/test-patch-docker/test-patch-docker.sh @@ -94,7 +94,7 @@ function stop_exited_containers # stop *all* containers that are in exit state for # more than > 8 hours - while read line; do + while read -r line; do id=$(echo "${line}" | cut -f1 -d' ') value=$(echo "${line}" | cut -f2 -d' ') size=$(echo "${line}" | cut -f3 -d' ') @@ -127,16 +127,22 @@ function stop_exited_containers ## @param args function rm_old_containers { - local line - local id - local value - local size + declare line + declare id + declare value + declare size + declare running - while read line; do + while read -r line; do id=$(echo "${line}" | cut -f1 -d, ) - state=$(echo "${line}" | cut -f2 -d, ) + running=$(echo "${line}" | cut -f2 -d, ) stoptime=$(echo "${line}" | cut -f3 -d, | cut -f1 -d. ) + if [[ ${running} = true ]]; then + yetus_debug "${id} is still running, skipping." + continue + fi + # believe it or not, date is not even close to standardized... if [[ $(uname -s) == Linux ]]; then @@ -148,13 +154,11 @@ function rm_old_containers stoptime=$(date -j -f "%Y-%m-%dT%H:%M:%S" "${stoptime}" "+%s") fi - if [[ ${state} == false ]]; then - curtime=$(date "+%s") - ((difftime = curtime - stoptime)) - if [[ ${difftime} -gt 86400 ]]; then - echo "Removing docker ${id}" - dockercmd rm "${id}" - fi + curtime=$(date "+%s") + ((difftime = curtime - stoptime)) + if [[ ${difftime} -gt 86400 ]]; then + echo "Removing docker ${id}" + dockercmd rm "${id}" fi done < <( # see https://github.com/koalaman/shellcheck/issues/375 @@ -187,7 +191,7 @@ function remove_old_tagged_images local id local created - while read line; do + while read -r line; do id=$(echo "${line}" | awk '{print $1}') created=$(echo "${line}" | awk '{print $5}')
