Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 36FFB200B67 for ; Tue, 2 Aug 2016 06:32:39 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 35A8C160AA7; Tue, 2 Aug 2016 04:32:39 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7B4E3160A6C for ; Tue, 2 Aug 2016 06:32:38 +0200 (CEST) Received: (qmail 52354 invoked by uid 500); 2 Aug 2016 04:32:37 -0000 Mailing-List: contact commits-help@yetus.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@yetus.apache.org Delivered-To: mailing list commits@yetus.apache.org Received: (qmail 52345 invoked by uid 99); 2 Aug 2016 04:32:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 02 Aug 2016 04:32:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 577CFE058E; Tue, 2 Aug 2016 04:32:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aw@apache.org To: commits@yetus.apache.org Message-Id: <54f6ee02408e437e8a4f7183c9827a99@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: yetus git commit: YETUS-341. docker cleanup in sentinel mode doesn't know about Created Date: Tue, 2 Aug 2016 04:32:37 +0000 (UTC) archived-at: Tue, 02 Aug 2016 04:32:39 -0000 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 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 Authored: Thu Jul 14 05:47:39 2016 -0700 Committer: Allen Wittenauer 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}) }