Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple Gotify Support #86

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,55 @@ 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
AUTOHEAL_DEFAULT_STOP_TIMEOUT=10 # Docker waits max 10 seconds (the Docker default) for a container to stop before killing during restarts (container overridable via label, see below)
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
```

Expand Down
10 changes: 9 additions & 1 deletion docker-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down