Skip to content

Commit

Permalink
Removed notify only option
Browse files Browse the repository at this point in the history
  • Loading branch information
floushee committed Jul 11, 2021
1 parent 5b5d43e commit 7f8ed3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ AUTOHEAL_DEFAULT_STOP_TIMEOUT=10 # Docker waits max 10 seconds (the Docker def
DOCKER_SOCK=/var/run/docker.sock # Unix socket for curl requests to Docker API
CURL_TIMEOUT=30 # --max-time seconds for curl requests to Docker API
WEBHOOK_URL="" # post message to the webhook if a container was restarted (or restart failed)
NOTIFY_ONLY="" # set this to true if you want to disable the automated restart
```

### Optional Container Labels
Expand Down
19 changes: 6 additions & 13 deletions docker-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ DOCKER_SOCK=${DOCKER_SOCK:-/var/run/docker.sock}
UNIX_SOCK=""
CURL_TIMEOUT=${CURL_TIMEOUT:-30}
WEBHOOK_URL=${WEBHOOK_URL:-""}
NOTIFY_ONLY=${NOTIFY_ONLY:-""}

# only use unix domain socket if no TCP endpoint is defined
case "${DOCKER_SOCK}" in
Expand Down Expand Up @@ -112,19 +111,13 @@ if [ "$1" = "autoheal" ] && [ -e "$DOCKER_SOCK" ];then
then
echo "$DATE Container $CONTAINER_NAME (${CONTAINER_SHORT_ID}) found to be restarting - don't restart"
else

if [ -n "$NOTIFY_ONLY" ]
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"
then
notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Automated container restard is disabled by NOTIFY_ONLY env variable." &
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"
then
echo "$DATE Restarting container $CONTAINER_SHORT_ID failed" >&2
notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Failed to restart the container!" &
else
notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Successfully restarted the container!" &
fi
echo "$DATE Restarting container $CONTAINER_SHORT_ID failed" >&2
notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Failed to restart the container!" &
else
notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Successfully restarted the container!" &
fi
fi
done
Expand Down

0 comments on commit 7f8ed3a

Please sign in to comment.