diff --git a/scripts/install.sh b/scripts/install.sh index dbfa38f..4155195 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -63,9 +63,45 @@ if ! "$PYTHON_BIN" -c 'import ensurepip' >/dev/null 2>&1; then exit 1 fi -if ! command -v redis-cli >/dev/null 2>&1; then - echo "Warning: 'redis-cli' not found on PATH. Install it before going live" \ - "(see docs/install.md's prerequisites section: apt install redis-server)." >&2 +# Celery (and therefore all feed fetching) is entirely dependent on Redis +# being reachable — it fails silently from the installer's point of view +# (the worker/beat processes just retry forever in the background), so this +# has to be a hard failure here, not a warning that's easy to miss while +# every later step "succeeds" at installing an app that can never fetch a +# single feed. Check the actual REDIS_URL that will end up in .env (an +# explicit EVECTION_REDIS_URL override, if set — the default local Redis +# otherwise), not just whether some redis-cli happens to be on PATH. +REDIS_URL_TO_CHECK="${EVECTION_REDIS_URL:-redis://localhost:6379/0}" +check_redis() { + "$PYTHON_BIN" -c " +import sys, socket, urllib.parse +u = urllib.parse.urlparse('$REDIS_URL_TO_CHECK') +try: + with socket.create_connection((u.hostname or 'localhost', u.port or 6379), timeout=3): + pass +except OSError as e: + print(e, file=sys.stderr) + sys.exit(1) +" +} +REDIS_HOST="$("$PYTHON_BIN" -c "import urllib.parse; print(urllib.parse.urlparse('$REDIS_URL_TO_CHECK').hostname or 'localhost')")" +if ! check_redis; then + if [[ "$REDIS_HOST" =~ ^(localhost|127\.0\.0\.1|::1)$ ]] && command -v apt-get >/dev/null 2>&1; then + echo "==> Redis isn't reachable at $REDIS_URL_TO_CHECK — installing redis-server" + apt-get install -y redis-server + systemctl enable --now redis-server + if ! check_redis; then + echo "Redis still isn't reachable after installing redis-server —" \ + "check: systemctl status redis-server" >&2 + exit 1 + fi + else + echo "Redis isn't reachable at $REDIS_URL_TO_CHECK. Evection's background" \ + "feed-fetching depends on it entirely, so this has to be fixed before" \ + "continuing — either start/install Redis there, or set" \ + "EVECTION_REDIS_URL to point at wherever it actually runs." >&2 + exit 1 + fi fi # --- 2. System user -----------------------------------------------------