# Deploying lore-forge This sets up lore-forge and an unmodified `loreserver` on one Linux machine with systemd, behind Caddy, under one public hostname with a Let's Encrypt certificate. Design notes are in [../.ai/designs/deployment.md](../.ai/designs/deployment.md). ``` browsers, Lore CLI ──443/tcp──▶ Caddy ──h2c──▶ lore-forge 127.0.0.1:8080 (lores://host:41337) ▲ keys, registry, names Lore CLI, desktop ──41337 udp+tcp, TLS──▶ loreserver ┘ (via https://host) └ 127.0.0.1:41339 (file content, for lore-forge) ``` Status: the units and `install.sh` are written to this design but **not yet run on a Linux machine**. What they wire together is tested on macOS by `scripts/e2e-lore.sh`: QUIC and gRPC over TLS with an EC key in the form Caddy writes, `lores://` clients, the browser reading over TLS, and a backup and restore. ## Before you start - A Linux server (x86_64 or aarch64) with systemd 247 or later: Debian 12, Ubuntu 22.04 or newer. - A DNS name pointing at it, for example `lore.example.com`. The server must be able to reach itself at that name, since loreserver fetches lore-forge's keys through Caddy. Where the network does not loop back, add `127.0.0.1 lore.example.com` to `/etc/hosts`. - Ports 80/tcp and 443/tcp (Caddy, including certificate issuance) and 41337/tcp and 41337/udp (loreserver) open to your users. - Caddy from its package (), rsync, and to build: Rust, `protoc`, curl and tar. ## Install As your own user, in a checkout of this repository on the server: ```bash cargo build --release -p lore-forge scripts/fetch-lore.sh ``` Then as root: ```bash sudo deploy/install.sh lore.example.com you@example.com ``` It installs: | Path | What | | --- | --- | | `/opt/lore-forge/bin/` | `lore-forge`, the pinned `loreserver` and `lore`, `lore-forge-certs` | | `/opt/lore-forge/scripts/` | `backup.sh`, `restore.sh` | | `/etc/lore-forge/lore-forge.env` | Settings for both services, written once from [lore-forge.env](lore-forge.env) | | `/etc/lore-forge/secret.key` | The key that encrypts the token signing keys (root only, handed to lore-forge as a systemd credential) | | `/etc/loreserver/tls/` | loreserver's copy of Caddy's certificate | | `/etc/caddy/lore-forge.caddy` | The Caddy site, imported from `/etc/caddy/Caddyfile` | | `/var/lib/lore-forge/` | lore-forge's database | | `/var/lib/loreserver/store/` | Every repository's data | | `/var/backups/lore-forge/` | Nightly backups | **Copy `/etc/lore-forge/secret.key` somewhere safe and separate now.** Without it a backup cannot be restored, and with it and the database anyone can mint access to every repository. Then open `https://lore.example.com` to create the owner account, and sign the CLI in: ```bash lore auth login lores://lore.example.com:41337 ``` Clone URLs on the forge's pages use the `lores://` remote. Never give people a `lore://` remote: it accepts any certificate and sends tokens over unencrypted gRPC. ## How the pieces start - `lore-forge.service` runs `lore-forge serve` as the `lore-forge` user. - `loreserver.service` runs as `loreserver`. Before each start it copies Caddy's certificate (`lore-forge-certs`) and writes its configuration with `lore-forge loreserver-config`, so the TLS, store and trust settings come from one tested place. Until Caddy has obtained the first certificate, the start fails and systemd retries every 10 seconds. - `lore-forge-certs.path` notices Caddy renewing the certificate and restarts loreserver. - `lore-forge-backup.timer` runs the backup at 04:30. Restarting lore-forge leaves loreserver running. Restarting loreserver, for an upgrade, a certificate renewal or a backup, **releases every file lock**: Lore keeps locks in memory. ## Backups `scripts/backup.sh` copies loreserver's store while it runs, stops loreserver for a second copy of what changed and for a snapshot of the database, and starts it again; the outage is usually seconds. Each backup is a directory under `/var/backups/lore-forge/`, with unchanged store files hard-linked to the previous one. It keeps 14 (`KEEP`). - Copy `/var/backups/lore-forge` off the machine (rsync, restic, rclone). A backup on the same disk does not survive the disk. - The secret key is not in the backups, on purpose; keep it apart. - Run one by hand with `systemctl start lore-forge-backup`, and see past runs with `journalctl -u lore-forge-backup`. ### Restoring ```bash sudo systemctl stop loreserver lore-forge sudo /opt/lore-forge/scripts/restore.sh /var/backups/lore-forge/latest sudo systemctl start lore-forge loreserver ``` The current database and store are moved aside (`*.before-restore-