Skip to main content

First deployment

1

Clone the repo

cd /opt/dbhost
git clone <repo-url> agent
cd agent
2

Set up Python environment

The agent uses uv for dependency management:
uv sync
This creates a .venv and installs all dependencies from pyproject.toml.
3

Create environment file

nano /opt/dbhost/agent/.env
API_KEY=your-generated-api-key
POSTGRES_SUPERUSER_PASSWORD=your-postgres-password
BACKUP_DIR=/var/backups/postgresql
The agent uses sensible defaults for other settings (localhost, port 5432, etc.). See environment variables for the full list.
4

Install systemd service

sudo cp /opt/dbhost/agent/systemd/db-agent.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable db-agent
sudo systemctl start db-agent
5

Verify

sudo systemctl status db-agent
curl https://agent.dbhost.app/health

systemd unit

The agent runs as a systemd service:
[Unit]
Description=DBHost Agent
After=network.target postgresql.service

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/opt/dbhost/agent
Environment=PATH=/home/ubuntu/.local/bin:/usr/bin:/bin
ExecStart=/home/ubuntu/.local/bin/uv run uvicorn db_agent.main:app --host 127.0.0.1 --port 8420
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
Key points:
  • Runs as ubuntu user with uv run to manage the virtual environment
  • Listens on localhost only (Caddy handles TLS and public access)
  • Auto-restarts on failure