mirror of
https://github.com/willfarrell/docker-autoheal.git
synced 2024-12-06 19:16:20 +01:00
Manually merge PR#79.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
```
|
||||
|
||||
+5
-4
@@ -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 <<EOF
|
||||
{
|
||||
"content":"$text"
|
||||
}
|
||||
"$WEBHOOK_JSON_KEY":"$text"
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ generate_apprise_payload() {
|
||||
{
|
||||
"title":"Autoheal",
|
||||
"body":"$text"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -141,7 +142,7 @@ then
|
||||
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
|
||||
else
|
||||
notify_webhook "Container ${CONTAINER_NAME:1} (${CONTAINER_SHORT_ID}) found to be unhealthy. Successfully restarted the container!" &
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user