From 3b6db56d14a7cf2a5ab152b909f313aa3dd34a78 Mon Sep 17 00:00:00 2001 From: Georgiy Sitnikov Date: Tue, 7 Jun 2022 18:24:42 +0200 Subject: [PATCH 1/4] Add Gotify Support https://github.com/gotify/server/ --- docker-entrypoint | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docker-entrypoint b/docker-entrypoint index eb482bf..72eb102 100755 --- a/docker-entrypoint +++ b/docker-entrypoint @@ -8,6 +8,9 @@ DOCKER_SOCK=${DOCKER_SOCK:-/var/run/docker.sock} UNIX_SOCK="" CURL_TIMEOUT=${CURL_TIMEOUT:-30} WEBHOOK_URL=${WEBHOOK_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 @@ -65,6 +68,12 @@ notify_webhook() { # execute webhook requests as background process to prevent healer from blocking curl -X POST -H "Content-type: application/json" -d "$(generate_webhook_payload $text)" $WEBHOOK_URL fi + + if [ -n "$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 From 1e853261aca1ee0a24fb5eb93267b27be2a9b4c6 Mon Sep 17 00:00:00 2001 From: Georgiy Sitnikov Date: Tue, 7 Jun 2022 18:43:23 +0200 Subject: [PATCH 2/4] Add Gotify in Readme --- README.md | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) 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 ``` From 2e064b781568fed6226d1064341cd31d1fb81513 Mon Sep 17 00:00:00 2001 From: Georgiy Sitnikov Date: Tue, 7 Jun 2022 18:45:02 +0200 Subject: [PATCH 3/4] Add Gotify to Readme --- README.md | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) 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 ``` From 00b0c4b7b8606950157f0e01ea28e3d2d17a662c Mon Sep 17 00:00:00 2001 From: Georgiy Sitnikov Date: Tue, 7 Jun 2022 18:47:34 +0200 Subject: [PATCH 4/4] Variable correction --- docker-entrypoint | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-entrypoint b/docker-entrypoint index 72eb102..01b7826 100755 --- a/docker-entrypoint +++ b/docker-entrypoint @@ -69,7 +69,7 @@ notify_webhook() { curl -X POST -H "Content-type: application/json" -d "$(generate_webhook_payload $text)" $WEBHOOK_URL fi - if [ -n "$GOTIFY_URL" ] + 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=$@"