#!/usr/bin/env bash # External uptime watchdog for gendesign (#75 B6-1, lightweight fallback). # # WHY THIS EXISTS alongside Uptime Kuma (docker-compose.uptime.yml): Kuma runs # ON the prod VM, so if the whole VM dies it can't alert. This script is meant to # run from cron on a DIFFERENT host (your laptop, a tiny free-tier box, Beget # shared-host cron) and hit the PUBLIC URLs over the internet — last-resort # "весь хост лёг" detection. Kuma covers rich per-endpoint/SSL/latency monitoring; # this covers the case Kuma structurally can't. # # Self-contained: only needs `curl` + `bash`. No docker, no repo checkout. # State (last-known status per check) lives in a file so we alert on TRANSITIONS # (up→down, down→up) — not every run — to avoid Telegram spam. # # Usage (cron — note `bash`, not a bare path, so a missing +x bit can't break it): # * * * * * bash /path/to/uptime-healthcheck.sh >> /var/log/gendesign-uptime.log 2>&1 # # Telegram alerting — set these in an env file (NOT in git, chmod 600): # TELEGRAM_BOT_TOKEN=123456:ABC... # TELEGRAM_CHAT_ID=123456789 # Default env path: /etc/default/gendesign-uptime (override via UPTIME_ENV_FILE). # A redacted template lives at ops/gendesign-uptime.default.example. # Without a token set, the script still logs up/down but sends no alert. set -euo pipefail # --- config (env-overridable) --- UPTIME_ENV_FILE="${UPTIME_ENV_FILE:-/etc/default/gendesign-uptime}" # shellcheck source=/dev/null [[ -f "$UPTIME_ENV_FILE" ]] && source "$UPTIME_ENV_FILE" BASE_URL="${BASE_URL:-https://gendsgn.ru}" STATE_FILE="${STATE_FILE:-/var/tmp/gendesign-uptime-state}" CURL_TIMEOUT="${CURL_TIMEOUT:-15}" # seconds per request (connect+read) RETRIES="${RETRIES:-2}" # extra attempts before declaring DOWN RETRY_SLEEP="${RETRY_SLEEP:-5}" # seconds between attempts TELEGRAM_BOT_TOKEN="${TELEGRAM_BOT_TOKEN:-}" TELEGRAM_CHAT_ID="${TELEGRAM_CHAT_ID:-}" # Checks to probe. Format per line: "