Home

/

Library

/

deploy-ubuntu.md

Ubuntu Deployment (Phase 1)

Ubuntu Deployment (Phase 1)

Overview

Run FastAPI + socket.io via Uvicorn on port 8030, fronted by Nginx for HTTPS and WebSocket proxying. Use systemd for process management and Postgres for storage.

1) App Environment

  • Create a Python venv and install backend deps (requirements.txt).
  • Create /etc/cornice.env with runtime config (POSTGRES_URL, RABBITMQ_URL, LIVEWIRE_JWT_SECRET, etc.).

Example /etc/cornice.env:

ENV=prod
LOG_LEVEL=info
POSTGRES_URL=postgresql://cornice_user:${CORNICE_DB_PWD}@127.0.0.1:5432/cornice_dev
RABBITMQ_URL=amqp://guest:guest@127.0.0.1:5672/
POLYMARKET_SLUG=bitcoin-up-or-down-january-14-2pm-et
KALSHI_EVENT_TICKER=KXBTCD-26JAN1422
DISCOVERY_INTERVAL_S=600
PRICE_INTERVAL_S=2
MAPPING_INTERVAL_S=120
LIVEWIRE_JWT_SECRET=...
LIVEWIRE_JWT_ISS=mixtape
LIVEWIRE_JWT_AUD=livewire
LIVEWIRE_JWT_ALG=HS256

2) systemd Service

Create /etc/systemd/system/cornice.service:

[Unit]
Description=Cornice FastAPI service
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/opt/cornice
EnvironmentFile=/etc/cornice.env
ExecStart=/opt/cornice/.venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8030
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Enable:

sudo systemctl daemon-reload
sudo systemctl enable --now cornice

3) Nginx Proxy (WebSocket + HTTPS)

Add a site (example /etc/nginx/sites-available/cornice):

server {
  listen 80;
  server_name your-domain.com;

  location / {
    proxy_pass http://127.0.0.1:8030;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

Enable and reload:

sudo ln -s /etc/nginx/sites-available/cornice /etc/nginx/sites-enabled/cornice
sudo nginx -t
sudo systemctl reload nginx

4) Database

  • Ensure Postgres is running.
  • Apply the migrations in migrations/ on the server database.

5) Frontend (Vercel)

  • Root: frontend/
  • Env var: NEXT_PUBLIC_LIVEWIRE_URL=https://your-domain.com
  • Optional: NEXT_PUBLIC_CORNICE_API_URL=https://your-domain.com

Health Checks

  • GET /health
  • GET /signals