mirror of
https://github.com/willfarrell/docker-autoheal.git
synced 2024-12-06 19:16:20 +01:00
add date to autoheal logs
This commit is contained in:
+4
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user