mirror of
https://github.com/willfarrell/docker-autoheal.git
synced 2024-12-06 19:16:20 +01:00
check container state not restarting
Don't restart containers which state is restarting.
This commit is contained in:
+5
-2
@@ -76,8 +76,8 @@ if [ "$1" = "autoheal" ] && [ -e "$DOCKER_SOCK" ];then
|
||||
do
|
||||
STOP_TIMEOUT=".Labels[\"autoheal.stop.timeout\"] // $AUTOHEAL_DEFAULT_STOP_TIMEOUT"
|
||||
get_container_info | \
|
||||
jq -r "foreach .[] as \$CONTAINER([];[]; \$CONTAINER | .Id, .Names[0], ${STOP_TIMEOUT})" | \
|
||||
while read -r CONTAINER_ID && read -r CONTAINER_NAME && read -r TIMEOUT
|
||||
jq -r "foreach .[] as \$CONTAINER([];[]; \$CONTAINER | .Id, .Names[0], .State, ${STOP_TIMEOUT})" | \
|
||||
while read -r CONTAINER_ID && read -r CONTAINER_NAME && read -r CONTAINER_STATE && read -r TIMEOUT
|
||||
do
|
||||
# shellcheck disable=2039
|
||||
CONTAINER_SHORT_ID=${CONTAINER_ID:0:12}
|
||||
@@ -86,6 +86,9 @@ if [ "$1" = "autoheal" ] && [ -e "$DOCKER_SOCK" ];then
|
||||
if [ "$CONTAINER_NAME" = "null" ]
|
||||
then
|
||||
echo "$DATE Container name of (${CONTAINER_SHORT_ID}) is null, which implies container does not exist - don't restart" >&2
|
||||
elif [ "$CONTAINER_STATE" = "restarting" ]
|
||||
then
|
||||
echo "$DATE Container $CONTAINER_NAME (${CONTAINER_SHORT_ID}) found to be restarting - don't restart"
|
||||
else
|
||||
echo "$DATE Container $CONTAINER_NAME (${CONTAINER_SHORT_ID}) found to be unhealthy - Restarting container now with ${TIMEOUT}s timeout"
|
||||
if ! restart_container "$CONTAINER_ID" "$TIMEOUT"
|
||||
|
||||
Reference in New Issue
Block a user