feat(roles/coolify): added traefik watchdog
This commit is contained in:
7 files changed
+131
-1
No files matched your search
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=Recover Traefik proxies after Docker socket connection failures
|
||||
After=docker.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/sbin/coolify-proxy-watchdog
|
||||
TimeoutStartSec=45s
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Check Traefik Docker socket connections
|
||||
|
||||
[Timer]
|
||||
OnBootSec=2min
|
||||
OnUnitActiveSec=1min
|
||||
Unit=coolify-proxy-watchdog.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
@@ -1,4 +1,4 @@
|
||||
# Managed by Ansible — manual changes will be overwritten on next deployment
|
||||
# Managed by Ansible - changes will be overwritten on next deployment
|
||||
services:
|
||||
coolify:
|
||||
image: "${REGISTRY_URL:-ghcr.io}/coollabsio/coolify:${LATEST_IMAGE:-latest}"
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
set -u
|
||||
|
||||
docker info >/dev/null 2>&1 || exit 0
|
||||
containers=$(timeout 10s docker ps --format '{% raw %}{{.Names}} {{.Image}}{% endraw %}') || exit 0
|
||||
state_dir=/run/coolify-proxy-watchdog
|
||||
mkdir -p "$state_dir"
|
||||
|
||||
while read -r container image; do
|
||||
case "$container:$image" in
|
||||
coolify-proxy:*|*traefik*) ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
|
||||
now=$(date +%s)
|
||||
state_file="$state_dir/$container"
|
||||
last_restart=$(cat "$state_file" 2>/dev/null || true)
|
||||
if [[ "$last_restart" =~ ^[0-9]+$ ]] && (( now - last_restart < 300 )); then
|
||||
continue
|
||||
fi
|
||||
|
||||
started_at=$(timeout 10s docker inspect --format '{% raw %}{{.State.StartedAt}}{% endraw %}' "$container") || continue
|
||||
started_epoch=$(date -d "$started_at" +%s) || continue
|
||||
if (( started_epoch > now - 120 )); then
|
||||
since="$started_at"
|
||||
else
|
||||
since=2m
|
||||
fi
|
||||
|
||||
logs=$(timeout 15s docker logs --since "$since" --tail 500 "$container" 2>&1) || continue
|
||||
if printf '%s\n' "$logs" | grep -Ei 'docker\.sock|docker\.socket' | grep -Eiq 'connection refused|cannot connect|no such file or directory|connection reset|i/o timeout|context deadline exceeded'; then
|
||||
printf '%s\n' "$now" > "$state_file"
|
||||
if docker restart --time 10 "$container" >/dev/null; then
|
||||
echo "Restarted $container after Docker socket connection failure"
|
||||
else
|
||||
echo "Failed to restart $container after Docker socket connection failure" >&2
|
||||
fi
|
||||
fi
|
||||
done <<< "$containers"
|
||||
Reference in new issue
Block a user