Files
loki/scripts/db/SETUP_HETZNER.md
T
Mao NakamotoandClaude Opus 4.8 4b7ee8d63a fix(control+brand): purge dead Vercel refs, real favicon, honest badges/counts
Thorough cleanup after a full investigation of "so many things are wrong".

DEPLOYMENT — the "This deployment is temporarily paused" ghost. The canonical
host already moved to fleetcrown.orangecat.ch (Hetzner); the message came from
leftover references to the paused fleetcrown.vercel.app deployment:
- vercel.json: drop the `alias: ["fleetcrown.vercel.app"]` (the paused domain).
- scripts/fleet: install-cli POSTs to fleetcrown.orangecat.ch, not the dead URL.
- package.json: `ship` just pushes (the pre-push hook deploys to Hetzner);
  replace `wait:vercel` with `deploy` → scripts/deploy-hetzner.sh.
- delete scripts/wait-for-vercel.sh and orphaned desktop/.vercel/.
- repoint stale Vercel URLs in scripts/db/*.md and the local VAPID_SUBJECT.
(Fleet Runner already targets orangecat.ch in source — the user's "paused"
view is a stale installed build; the current v0.8.0 build/.deb is in desktop/dist.)

ICON — the browser-tab icon was blank/wrong:
- public/icon.svg drew the spiral at ~23% of the canvas with 0.7/0.95 opacity,
  so it vanished at 16px. Rescaled to fill ~62% at full contrast (shape
  unchanged, matches BrandMark.tsx).
- delete the stale src/app/favicon.ico (still the Next.js starter triangle);
  metadata already declares /icon.svg, so browsers now show the brand mark.

CONTROL honesty:
- Autopilot badge no longer shows a pulsing "Building" on every autopilot-on
  project (the default), which made idle projects look actively worked. It's now
  a static "Auto"/"Paused" policy chip; the pulse is reserved for real `working`.
- /activity stats (promptsSent/runsStarted) now come from real count(*)
  aggregates instead of the 200-capped row arrays (showed "200" when the true
  30-day count was 277).
- "Previous automated run" shows a crashed `running` row (no terminal write,
  >30min old) as "interrupted" instead of a live-looking "running" tag.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 14:21:26 +02:00

5.1 KiB

Hetzner CX22 — FleetCrown Postgres host setup

A ~€4.5/mo Hetzner CX22 (2 vCPU, 4 GB RAM, 40 GB SSD, Helsinki/Falkenstein/Nuremberg/Ashburn/Hillsboro/Singapore) is more than enough headroom for FleetCrown's traffic and has no egress fees inside the EU. This runbook gets you from "open Hetzner Cloud account" to "Vercel pointed at the new DB" in ~30 min.

0. Prereqs

  • Hetzner Cloud account
  • SSH key uploaded to Hetzner (Console → Security → SSH Keys)
  • pg_dump available locally (this repo has it via Postgres 17 client tools)

1. Provision the box

Console → New project → "FleetCrown DB" → New server:

  • Location: closest to your Vercel region (typically Falkenstein for EU, or Ashburn for US East)
  • Image: Ubuntu 24.04
  • Type: CX22 (or larger if you expect growth — CX32 doubles RAM for ~€8)
  • Networking: default IPv4 + IPv6
  • SSH keys: select your uploaded key
  • Firewall: skip for now (we'll add one in step 4)
  • Name: fleetcrown-db

Hit Create. Note the public IPv4.

2. SSH and install Postgres 17

ssh root@<server-ip>

# Add the PGDG repo (Ubuntu 24.04's default postgres is 16; we want 17 for parity)
apt update && apt install -y curl ca-certificates gnupg lsb-release
install -d /usr/share/postgresql-common/pgdg
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc \
  | gpg --dearmor -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.gpg
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.gpg] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" \
  > /etc/apt/sources.list.d/pgdg.list
apt update
apt install -y postgresql-17 postgresql-client-17 ufw fail2ban

3. Create the FleetCrown role + database

sudo -u postgres psql <<'SQL'
CREATE ROLE fleetcrown WITH LOGIN PASSWORD 'CHANGE_ME_BEFORE_USE';
CREATE DATABASE fleetcrown OWNER fleetcrown;
SQL

Replace CHANGE_ME_BEFORE_USE with a strong random password — use it once below and forget it (store in Vercel env, not in any local file).

4. Open Postgres to Vercel (firewall + listen address)

# Listen on all interfaces (Postgres defaults to localhost only)
sed -i "s/^#listen_addresses.*/listen_addresses = '*'/" /etc/postgresql/17/main/postgresql.conf

# Require SSL for incoming connections (Vercel speaks SSL by default)
sed -i "s/^#ssl = on/ssl = on/" /etc/postgresql/17/main/postgresql.conf

# pg_hba: allow the fleetcrown user from anywhere over SSL with password
echo "hostssl all fleetcrown 0.0.0.0/0 scram-sha-256" >> /etc/postgresql/17/main/pg_hba.conf
echo "hostssl all fleetcrown ::/0      scram-sha-256" >> /etc/postgresql/17/main/pg_hba.conf

systemctl restart postgresql

# UFW: SSH + Postgres only
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 5432/tcp
ufw --force enable

Security note: opening 5432 to 0.0.0.0/0 means anyone on the internet can attempt password auth. For prod, replace 0.0.0.0/0 with Vercel's egress IP ranges (or use Hetzner's cloud firewall to allowlist Vercel's subnet). Until then, ensure the password is genuinely random and fail2ban is active.

5. Verify from your laptop

psql "postgresql://fleetcrown:CHANGE_ME_BEFORE_USE@<server-ip>:5432/fleetcrown?sslmode=require" -c "SELECT version();"

Should print Postgres 17.x.

6. Restore the dump

# Locally — assumes you ran scripts/db/dump-from-neon.sh first
TARGET_DATABASE_URL="postgresql://fleetcrown:CHANGE_ME_BEFORE_USE@<server-ip>:5432/fleetcrown?sslmode=require" \
DUMP_FILE="neon-dump-<timestamp>.sql" \
scripts/db/restore-to-target.sh

The script verifies row counts against the manifest. If anything mismatches, it halts before you flip Vercel.

7. Flip Vercel

vercel env rm DATABASE_URL production
vercel env add DATABASE_URL production
# paste: postgresql://fleetcrown:CHANGE_ME_BEFORE_USE@<server-ip>:5432/fleetcrown?sslmode=require

# Also DATABASE_POOL_URL if you have it (PgBouncer URL — same content for now,
# Vercel doesn't pool by default).
vercel env rm DATABASE_POOL_URL production || true
vercel env add DATABASE_POOL_URL production

vercel --prod --yes

8. Smoke test

curl -s https://fleetcrown.orangecat.ch/api/health
# expect: {"ok":true,"runtime":false,"version":null}

curl -s -o /dev/null -w "%{http_code}\n" -X POST https://fleetcrown.orangecat.ch/api/control/runtime-state \
  -H "Authorization: Bearer ock_..."  # an agent token
# expect: 401 (no body) or 200 (with body)

Browse /control, /settings, /system — should load without "Something went wrong."

9. Daily care

  • apt update && apt upgrade -y weekly (or set up unattended-upgrades)
  • pg_dump fleetcrown | gzip > /backups/fleetcrown-$(date +%F).sql.gz daily via cron
  • Snapshot the Hetzner volume via their UI before major schema migrations

Decommissioning Neon

After 24h of clean operation on Hetzner, you can:

  • Pause the Neon project (free tier doesn't charge for paused projects)
  • Or delete it entirely if you'd rather not keep the old data around

Either way, keep one full pg_dump of Neon in cold storage for at least 30 days before deleting the source — recovering from a botched migration is much harder without it.