add date to autoheal logs

This commit is contained in:
will Farrell
2017-03-20 12:13:03 -06:00
parent 2d8847f362
commit 9c00a8941f
+4 -2
View File
@@ -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