From 3ef82dc99297533341bb6831bdb47de83c5b282c Mon Sep 17 00:00:00 2001 From: Tyler Pace Date: Tue, 18 Apr 2023 18:21:18 -0700 Subject: [PATCH] Manually merge PR#79. --- Dockerfile | 1 + README.md | 9 +++++---- docker-entrypoint | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6202e9d..9ded7f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ ENV AUTOHEAL_CONTAINER_LABEL=autoheal \ DOCKER_SOCK=/var/run/docker.sock \ CURL_TIMEOUT=30 \ WEBHOOK_URL="" \ + WEBHOOK_JSON_KEY="content" \ APPRISE_URL="" HEALTHCHECK --interval=5s CMD pgrep -f autoheal || exit 1 diff --git a/README.md b/README.md index 71a18b1..9d40d7d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Docker Autoheal -Monitor and restart unhealthy docker containers. +Monitor and restart unhealthy docker containers. This functionality was proposed to be included with the addition of `HEALTHCHECK`, however didn't make the cut. This container is a stand-in till there is native support for `--exit-on-unhealthy` https://github.com/docker/docker/pull/22719. @@ -33,7 +33,7 @@ docker run -d \ ``` a) Apply the label `autoheal=true` to your container to have it watched. -b) Set ENV `AUTOHEAL_CONTAINER_LABEL=all` to watch all running containers. +b) Set ENV `AUTOHEAL_CONTAINER_LABEL=all` to watch all running containers. c) Set ENV `AUTOHEAL_CONTAINER_LABEL` to existing label name that has the value `true`. @@ -60,7 +60,7 @@ http://localhost:8000/cfg/autoheal See the Apprise wiki for configuration details: https://github.com/caronc/apprise/wiki -c) Set the `APPRISE_URL` environment variable to use the Apprise configuration: +c) Set the `APPRISE_URL` environment variable to use the Apprise configuration: `APPRISE_URL="http://localhost:8000/notify/autoheal"` ## ENV Defaults @@ -72,6 +72,7 @@ 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) +WEBHOOK_JSON_KEY="content" # the key to use for the message in the json body of the request to the webhook url APPRISE_URL="" # post message to Apprise if a container was restarted (or restart failed) ``` @@ -87,5 +88,5 @@ docker build -t autoheal . docker run -d \ -e AUTOHEAL_CONTAINER_LABEL=all \ -v /var/run/docker.sock:/var/run/docker.sock \ - autoheal + autoheal ``` diff --git a/docker-entrypoint b/docker-entrypoint index e0fa433..88c125d 100755 --- a/docker-entrypoint +++ b/docker-entrypoint @@ -8,6 +8,7 @@ DOCKER_SOCK=${DOCKER_SOCK:-/var/run/docker.sock} UNIX_SOCK="" CURL_TIMEOUT=${CURL_TIMEOUT:-30} WEBHOOK_URL=${WEBHOOK_URL:-""} +WEBHOOK_JSON_KEY=${WEBHOOK_JSON_KEY:-"text"} APPRISE_URL=${APPRISE_URL:-""} # only use unix domain socket if no TCP endpoint is defined @@ -81,8 +82,8 @@ generate_webhook_payload() { local text="$@" cat <&2 notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Failed to restart the container!" & - else + else notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Successfully restarted the container!" & fi fi