diff --git a/README.md b/README.md index f9bcdcb..24fff79 100644 --- a/README.md +++ b/README.md @@ -47,13 +47,41 @@ The certificates, and keys need these names: ### Change Timezone If you need the timezone to match the local machine, you can map the `/etc/localtime` into the container. -``` +```bash docker run ... -v /etc/localtime:/etc/localtime:ro ``` +### Enable Gotify Notifications +If you need to recieve [Gotify](https://github.com/gotify/server/) Notifications, simply add following variables to your deployment: +```yaml +docker run -d \ + -e AUTOHEAL_CONTAINER_LABEL=all \ + -e AUTOHEAL_NOTIFICATION_GOTIFY_URL="http://gotify" \ + -e AUTOHEAL_NOTIFICATION_GOTIFY_TOKEN="xxxxxxxxxxxx" + -v /var/run/docker.sock:/var/run/docker.sock \ + autoheal +``` + +### Docker-compose +This is an example for docker compose file. +```yaml +version: "3.4" +services: + autoheal: + container_name: autoheal + restart: always + image: willfarrell/autoheal:latest + volumes: + - /var/run/docker.sock:/var/run/docker.sock + environment: + - AUTOHEAL_CONTAINER_LABEL=autoheal + - AUTOHEAL_INTERVAL=5 + - AUTOHEAL_NOTIFICATION_GOTIFY_URL=http://gotify + - AUTOHEAL_NOTIFICATION_GOTIFY_TOKEN=xxxxxxxxxxxxx +``` ## ENV Defaults -``` +```yaml AUTOHEAL_CONTAINER_LABEL=autoheal AUTOHEAL_INTERVAL=5 # check every 5 seconds AUTOHEAL_START_PERIOD=0 # wait 0 seconds before first health check @@ -61,10 +89,13 @@ 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) +AUTOHEAL_NOTIFICATION_GOTIFY_URL="" # Gotify URL with protocol and Port if needed, e.g. http://gotify:8080 or https://gotify +AUTOHEAL_NOTIFICATION_GOTIFY_TOKEN="" # Gotify Token +AUTOHEAL_NOTIFICATION_GOTIFY_TITLE="Docker Autoheal" # Gotify Notification Title ``` ### Optional Container Labels -``` +```yaml autoheal.stop.timeout=20 # Per containers override for stop timeout seconds during restart ``` diff --git a/docker-entrypoint b/docker-entrypoint index e171e52..ff453ea 100755 --- a/docker-entrypoint +++ b/docker-entrypoint @@ -7,9 +7,11 @@ set -o pipefail 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:-""} +AUTOHEAL_NOTIFICATION_GOTIFY_URL=${AUTOHEAL_NOTIFICATION_GOTIFY_URL:-""} +AUTOHEAL_NOTIFICATION_GOTIFY_TOKEN=${AUTOHEAL_NOTIFICATION_GOTIFY_TOKEN:-""} +AUTOHEAL_NOTIFICATION_GOTIFY_TITLE=${AUTOHEAL_NOTIFICATION_GOTIFY_TITLE:-"Docker Autoheal"} # only use unix domain socket if no TCP endpoint is defined case "${DOCKER_SOCK}" in @@ -83,6 +85,12 @@ notify_post_restart_script() { # execute post restart script as background process to prevent healer from blocking $POST_RESTART_SCRIPT "$@" & fi + + if [ -n "$AUTOHEAL_NOTIFICATION_GOTIFY_URL" ] + then + # execute gotify request as background process to prevent healer from blocking + curl -fsS -m 5 --retry 3 -o /dev/null "$AUTOHEAL_NOTIFICATION_GOTIFY_URL/message?token=$AUTOHEAL_NOTIFICATION_GOTIFY_TOKEN" -F "title=$AUTOHEAL_NOTIFICATION_GOTIFY_TITLE" -F "message=$@" + fi } # https://towardsdatascience.com/proper-ways-to-pass-environment-variables-in-json-for-curl-post-f797d2698bf3