Repository: yetus Updated Branches: refs/heads/master adeefcaaa -> b110b2580
YETUS-341. docker cleanup in sentinel mode doesn't know about Created Signed-off-by: Sean Busbey <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/yetus/repo Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/b110b258 Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/b110b258 Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/b110b258 Branch: refs/heads/master Commit: b110b25802652c599fdf67f74e548b0b4a248248 Parents: adeefca Author: Allen Wittenauer <[email protected]> Authored: Thu Jul 14 05:47:39 2016 -0700 Committer: Allen Wittenauer <[email protected]> Committed: Mon Aug 1 21:31:59 2016 -0700 ---------------------------------------------------------------------- precommit/core.d/docker.sh | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/yetus/blob/b110b258/precommit/core.d/docker.sh ---------------------------------------------------------------------- diff --git a/precommit/core.d/docker.sh b/precommit/core.d/docker.sh index 315dd29..2dae49d 100755 --- a/precommit/core.d/docker.sh +++ b/precommit/core.d/docker.sh @@ -31,8 +31,8 @@ declare -a DOCKER_EXTRAARGS #### If these times are updated, the documentation needs to #### be changed too! -# stopped, exited, running, for 24 hours -DOCKER_CONTAINER_PURGE=("86400" "86400" "86400") +# created, stopped, exited, running, for 24 hours +DOCKER_CONTAINER_PURGE=("86400" "86400" "86400" "86400" ) # keep images for 1 week DOCKER_IMAGE_PURGE=604800 @@ -272,6 +272,7 @@ function docker_container_maintenance declare name declare status declare tmptime + declare createtime declare starttime declare stoptime declare remove @@ -294,31 +295,39 @@ function docker_container_maintenance while read -r line; do id=$(echo "${line}" | cut -f1 -d, ) - name=$(echo "${line}" | cut -f2 -d, ) - status=$(echo "${line}" | cut -f3 -d, ) + status=$(echo "${line}" | cut -f2 -d, ) + tmptime=$(echo "${line}" | cut -f3 -d, | cut -f1 -d. ) + createtime=$(dockerdate_to_ctime "${tmptime}") tmptime=$(echo "${line}" | cut -f4 -d, | cut -f1 -d. ) starttime=$(dockerdate_to_ctime "${tmptime}") tmptime=$(echo "${line}" | cut -f5 -d, | cut -f1 -d. ) stoptime=$(dockerdate_to_ctime "${tmptime}") + name=$(echo "${line}" | cut -f6 -d, ) curtime=$(TZ=UTC date "+%s") remove=false case ${status} in + created) + ((difftime = curtime - createtime)) + if [[ ${difftime} -gt ${DOCKER_CONTAINER_PURGE[0]} ]]; then + remove=true + fi + ;; stopped) ((difftime = curtime - stoptime)) - if [[ ${difftime} -gt ${DOCKER_CONTAINER_PURGE[0]} ]]; then + if [[ ${difftime} -gt ${DOCKER_CONTAINER_PURGE[1]} ]]; then remove=true fi ;; exited) ((difftime = curtime - stoptime)) - if [[ ${difftime} -gt ${DOCKER_CONTAINER_PURGE[1]} ]]; then + if [[ ${difftime} -gt ${DOCKER_CONTAINER_PURGE[2]} ]]; then remove=true fi ;; running) ((difftime = curtime - starttime)) - if [[ ${difftime} -gt ${DOCKER_CONTAINER_PURGE[2]} + if [[ ${difftime} -gt ${DOCKER_CONTAINER_PURGE[3]} && "${SENTINEL}" = true ]]; then remove=true echo "Attempting to kill docker container ${name} [${id}]" @@ -337,7 +346,7 @@ function docker_container_maintenance done < <( # shellcheck disable=SC2086 dockercmd inspect \ - --format '{{.Id}},{{.Name}},{{.State.Status}},{{.State.StartedAt}},{{.State.FinishedAt}}' \ + --format '{{.Id}},{{.State.Status}},{{.Created}},{{.State.StartedAt}},{{.State.FinishedAt}},{{.Name}}' \ ${data}) }
