From 9c00a8941f95a97e92f932966eed2742d1054577 Mon Sep 17 00:00:00 2001 From: will Farrell Date: Mon, 20 Mar 2017 12:13:03 -0600 Subject: [PATCH] add date to autoheal logs --- docker-entrypoint | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint b/docker-entrypoint index f4e3298..1b059a2 100755 --- a/docker-entrypoint +++ b/docker-entrypoint @@ -20,18 +20,20 @@ if [ "$1" = 'autoheal' ] && [ -e ${DOCKER_SOCK} ]; then echo "Monitoring containers for unhealthy status" while true; do + sleep ${AUTOHEAL_INTERVAL:=5} CONTAINERS=$(curl --no-buffer -s -XGET --unix-socket ${DOCKER_SOCK} http://localhost/containers/json | selector) for CONTAINER in $CONTAINERS; do HEALTH=$(curl --no-buffer -s -XGET --unix-socket ${DOCKER_SOCK} http://localhost/containers/${CONTAINER}/json | jq -r .State.Health.Status) if [ "unhealthy" = "$HEALTH" ]; then - echo "Container ${CONTAINER:0:12} found to be unhealthy. Restarting container ..." + DATE=$(date +%d-%m-%Y" "%H:%M:%S) + echo "$DATE Container ${CONTAINER:0:12} found to be unhealthy. Restarting container ..." # Note: kill and stop didn't honor the restart policy #curl --no-buffer -s -XPOST --data '{"signal":"SIGKILL"}' --unix-socket ${DOCKER_SOCK} http://localhost/containers/${CONTAINER}/kill curl --no-buffer -s -XPOST --unix-socket ${DOCKER_SOCK} http://localhost/containers/${CONTAINER}/restart fi done - sleep ${AUTOHEAL_INTERVAL:=5} + done else