From 0b0b1bb2d529dbaae8e49891d8d5e8019b971838 Mon Sep 17 00:00:00 2001 From: Paul Nothaft Date: Thu, 14 May 2026 20:31:25 +0200 Subject: [PATCH] fix(install): silence pg healthcheck noise + drop legacy workers container (#484) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three install-experience bugs that compounded into MrGabri's "fresh install fails" report: 1. **postgres healthcheck noise.** `pg_isready -U ` without -d defaults to probing a database whose name matches the user. Since DB_NAME defaults to picpeak_prod (not picpeak), every healthcheck interval logged FATAL: database "picpeak" does not exist into postgres logs even though the install was working correctly. Reporter saw the FATAL, assumed broken, restarted with DB_NAME=picpeak, hit a tainted-state migration error on the second try, filed a bug. Fixed in both docker-compose.production.yml and the inline compose generated by scripts/picpeak-setup.sh — pin -d to ${DB_NAME} so the probe hits the real database. 2. **backend container shows perpetually `unhealthy`.** Both compose files used `curl -f` for the backend healthcheck, but backend/Dockerfile only installs dumb-init + postgresql-client + ffmpeg — no curl. Switch to wget --no-verbose --tries=1 --spider to match what backend/Dockerfile's own HEALTHCHECK already does. Now docker ps, docker compose ps, and the backend image's built-in healthcheck all agree. 3. **stale separate `workers` container.** scripts/picpeak-setup.sh still generated a second container running `npm run workers` alongside the backend, but workers (fileWatcher, expirationChecker, emailQueueProcessor, backgroundProcessor, webhookWorker) have been started by server.js in-process for a while — see the comment at line ~895 of the same script for the systemd-side cleanup. The duplicate container caused two file watchers and two expiration checkers to compete for the same DB rows. Removed from the generated compose; install + upgrade paths now stop and rm any pre-existing picpeak-workers container. Doesn't address issue B's bigger architecture mismatch (the script generates a build-from-source compose with no frontend container, while docker-compose.production.yml uses prebuilt images with a separate frontend container). That deserves its own design pass to pick a canonical install path and align — out of scope here. --- docker-compose.production.yml | 17 ++++++++-- scripts/picpeak-setup.sh | 61 ++++++++++++++++++++++++----------- 2 files changed, 57 insertions(+), 21 deletions(-) diff --git a/docker-compose.production.yml b/docker-compose.production.yml index 1bbfe487..27fcd9e5 100644 --- a/docker-compose.production.yml +++ b/docker-compose.production.yml @@ -15,7 +15,13 @@ services: - picpeak-network restart: unless-stopped healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-picpeak}"] + # `pg_isready -U ` without -d defaults to probing a database + # whose name matches the user — postgres then logs constant + # `FATAL: database "picpeak" does not exist` even though the + # actual DB is `picpeak_prod`. Pinning -d to DB_NAME makes the + # probe hit the real database and silences the log noise that + # made #484's reporter think the install was broken. + test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-picpeak} -d ${DB_NAME:-picpeak}"] interval: 10s timeout: 5s retries: 5 @@ -64,8 +70,13 @@ services: condition: service_healthy restart: unless-stopped healthcheck: - # Backend exposes /health on internal port 3000 - test: ["CMD", "curl", "-f", "http://localhost:3000/health"] + # Backend exposes /health on internal port 3000. + # The backend image only ships wget (Alpine base) — using curl + # here makes `docker ps` show the container as `unhealthy` + # indefinitely even when /health responds. Mirrors the wget-based + # HEALTHCHECK already declared in backend/Dockerfile so docker + # compose, plain `docker run`, and `docker ps` all agree. + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/health"] interval: 30s timeout: 10s retries: 3 diff --git a/scripts/picpeak-setup.sh b/scripts/picpeak-setup.sh index 6d84131c..3b0d071c 100755 --- a/scripts/picpeak-setup.sh +++ b/scripts/picpeak-setup.sh @@ -518,6 +518,17 @@ EOF setup_ssl_docker "$app_dir" fi + # Clean up the legacy picpeak-workers container from prior installs + # (workers are now in-process — see create_docker_compose_file). + # Otherwise the leftover container keeps running its own + # fileWatcher / expirationChecker against the same DB rows the new + # backend container processes. + if docker ps -a --format '{{.Names}}' 2>/dev/null | grep -q '^picpeak-workers$'; then + log_step "Removing legacy picpeak-workers container (workers now run in-process)..." + docker stop picpeak-workers >/dev/null 2>&1 || true + docker rm picpeak-workers >/dev/null 2>&1 || true + fi + # Start services log_step "Starting services..." cd "$app_dir" @@ -583,7 +594,12 @@ services: - picpeak-network restart: unless-stopped healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${DB_USER}"] + # `pg_isready -U ` without -d defaults to probing a database + # whose name matches the user — postgres logs constant `FATAL: + # database "" does not exist` even though the actual DB + # is `${DB_NAME}`. Pinning -d to DB_NAME silences the noise + # that made #484's reporter think the install was broken. + test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"] interval: 10s timeout: 5s retries: 5 @@ -621,24 +637,23 @@ services: condition: service_healthy restart: unless-stopped healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3001/api/health"] + # backend image only ships wget (Alpine base) — using curl + # makes `docker ps` show the container as `unhealthy` + # indefinitely even when /api/health responds. Mirrors the + # wget-based HEALTHCHECK in backend/Dockerfile. + test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3001/api/health"] interval: 30s timeout: 10s retries: 3 - workers: - build: ./backend - container_name: picpeak-workers - command: npm run workers - env_file: .env - volumes: - - ./storage:/app/storage - - ./logs:/app/logs - networks: - - picpeak-network - depends_on: - - backend - restart: unless-stopped + # The legacy separate `workers` container has been removed: as of + # the in-process worker consolidation noted in the native systemd + # installer below ("Backend service includes workers — fileWatcher, + # expirationChecker are started by server.js"), running a second + # `npm run workers` container caused two file watchers + two + # expiration checkers to compete for the same DB rows. Cleaned up + # on existing installs by `picpeak-setup.sh upgrade`, which stops + # and removes the picpeak-workers container if found. volumes: postgres-data: @@ -1165,15 +1180,25 @@ update_docker_installation() { # Pull latest code git pull - + # Rebuild and restart containers docker compose down docker compose build --no-cache + + # Clean up the legacy picpeak-workers container if it exists + # (workers are now in-process — see comment in + # create_docker_compose_file). Best-effort: ignore if absent. + if docker ps -a --format '{{.Names}}' | grep -q '^picpeak-workers$'; then + log_step "Removing legacy picpeak-workers container (workers now run in-process)..." + docker stop picpeak-workers >/dev/null 2>&1 || true + docker rm picpeak-workers >/dev/null 2>&1 || true + fi + docker compose up -d - + # Run migrations docker compose exec -T backend npm run migrate - + log_success "Docker installation updated successfully!" }