PRODUCTION RECIPE: one What site on a Linux server with systemd, Caddy in front.

Not run on a Linux server. These files are checked by parsing
(scripts/recipe-check.py) and the configuration by starting run-what on a
development machine. Starting the service under systemd on Linux, real
TLS and hosting are unverified.

FILES
  what.service  systemd unit, installed as /etc/systemd/system/what.service
  Caddyfile     Caddy site, installed as /etc/caddy/Caddyfile
  env.example   the form secret's file, copied to /etc/my-site/env
  what.toml     the server's what.toml: the project's own, with [server]
                set for Caddy (the public HTTPS origin, one proxy hop)

PREREQUISITES (yours to provide; nothing here creates them)
  1. A Linux server with systemd, a domain whose DNS points at it, ports 80
     and 443 open, and Caddy installed (Caddy obtains the certificate).
  2. A run-what binary built for that server. A binary built on macOS does
     not run on Linux. Build it from the What source with
     cargo build --release --bin run-what on the server, or on a Linux
     machine with the same architecture and a C library no newer than the
     server's. Install it as /usr/local/bin/run-what, owned by root, mode
     0755.
  3. A service account that cannot log in and owns only the data, with its
     own group of the same name (Group=what in the unit):
       sudo useradd --system --user-group --home-dir /srv/my-site --shell /usr/sbin/nologin what
  4. The two persistent folders, owned by the account, private, created
     before the service starts (systemd refuses a missing ReadWritePaths):
       sudo install -d -o root -g root -m 0755 /srv/my-site
       sudo install -d -o what -g what -m 0700 /srv/my-site/data /srv/my-site/uploads
     data/ holds the store (data/app.db, with -wal and -shm while running)
     and the sessions database (data/sessions.db); uploads/ holds uploaded
     files. Both folders must persist across restarts and upgrades. A
     backup (L22) holds the store and uploads/ only: sessions are never
     backed up or restored, so after a restore, sign-ins through the site's
     own accounts start again.
  5. The site files in /srv/my-site, owned by root, directories 0755 and
     files 0644, so the service reads them and cannot change them:
     this folder's what.toml as /srv/my-site/what.toml (with your domain),
     site/, static/ and components/. Put data/pages.json (read once, on the
     first start) in on its own, so data/ and uploads/ keep the owner and
     mode from step 4:
       sudo install -o root -g root -m 0644 data/pages.json /srv/my-site/data/pages.json
     Never copy a whole data/ or uploads/ folder over them, and never
     chown or chmod the project recursively. Copy no data/app.db, no
     sessions database and no .env: the server creates its own data, and a
     .env in the project would be loaded and travel with every copy of the
     project.
  6. The secret, outside the project:
       sudo install -d -o root -g root -m 0755 /etc/my-site
       sudo install -o root -g root -m 0600 env.example /etc/my-site/env
       openssl rand -hex 32
     Paste the generated value after WHAT_SERVER_FORM_SECRET= in
     /etc/my-site/env (sudoedit /etc/my-site/env). Left empty, run-what
     refuses to start.
  7. Your domain in two places, the same origin in both: the site address
     in the Caddyfile and allowed_origins in /srv/my-site/what.toml
     ("https://" plus the domain, nothing after it).

START
  The first editor account (there is no built-in one), as the service
  account so its files belong to it, before the first start:
    sudo -u what /usr/local/bin/run-what admin add editor --path /srv/my-site
  Then:
    sudo install -o root -g root -m 0644 what.service /etc/systemd/system/what.service
    sudo systemctl daemon-reload
    sudo systemctl enable --now what
    sudo install -o root -g root -m 0644 Caddyfile /etc/caddy/Caddyfile
    sudo systemctl reload caddy
  Logs: journalctl -u what. For JSON log lines, add WHAT_LOG_FORMAT=json to
  /etc/my-site/env and restart.

RECOVERY (back up and restore on the server; documented steps, not yet run
on a Linux server)
  A backup holds the store (accounts, pages, publication state) and uploads/,
  with backup.json listing the engine, the schema and every checksum. It
  holds no sessions and no site files. Keep the site files and what.toml
  that match each backup in a separate private folder beside it, never
  inside the backup folder (an extra file there, even the .DS_Store that
  Finder adds when you open it, makes verify and restore refuse the
  backup; keep backups unopened and unmodified): a restore needs both. Stop the service first: a backup refuses a server that is writing,
  but an idle server may not be noticed, so never rely on that.

  Run each command on its own and stop at the first one that fails. The new
  backup, restore, rollback and failed-attempt destinations must not exist
  yet, not even as a link; the test commands check that.

  Back up, as root, into a private folder outside the project:
    sudo systemctl stop what
    test ! -e /var/backups/my-site-2026-10-27 && test ! -L /var/backups/my-site-2026-10-27
    sudo /usr/local/bin/run-what backup --path /srv/my-site --output /var/backups/my-site-2026-10-27
    sudo /usr/local/bin/run-what backup --verify /var/backups/my-site-2026-10-27
    sudo systemctl start what
  The folder is owner-only (root). Keep a copy off the server as well.

  Restore into a new folder, with the service stopped:
    sudo systemctl stop what
    test ! -e /srv/my-site-restored && test ! -L /srv/my-site-restored
    sudo /usr/local/bin/run-what restore --from /var/backups/my-site-2026-10-27 --config /srv/my-site/what.toml --output /srv/my-site-restored
  The restored folder and its files are private to root, and an empty
  uploads folder in the backup leaves no uploads/ folder at all. Make the
  project traversable and its configuration readable, copy in the site files
  that match the backup as root (here the current ones), make sure data/ and
  uploads/ exist, and give only those two to the service account:
    sudo chmod 0755 /srv/my-site-restored
    sudo chmod 0644 /srv/my-site-restored/what.toml
    sudo cp -R --preserve=mode /srv/my-site/site /srv/my-site/static /srv/my-site/components /srv/my-site-restored/
    sudo install -d -o what -g what -m 0700 /srv/my-site-restored/data /srv/my-site-restored/uploads
    sudo chown -R what:what /srv/my-site-restored/data /srv/my-site-restored/uploads
  Never copy the old data/, uploads/, sessions database or another
  what.toml over the restored folder. The environment file in
  /etc/my-site/env stays where it is.

  Promote the restored folder, keeping the old installation for rollback.
  mv -T (GNU) renames a folder and never moves it inside another one:
    test ! -e /srv/my-site-before-restore-2026-10-27 && test ! -L /srv/my-site-before-restore-2026-10-27
    sudo mv -T /srv/my-site /srv/my-site-before-restore-2026-10-27
    sudo mv -T /srv/my-site-restored /srv/my-site
    sudo systemctl start what
    systemctl status what
  The status must say active; then open your site and check the restored
  pages and an editor sign-in. Users of the site's own accounts sign in
  again: sessions are never restored. Credentials from an external sign-in
  provider (JWTs) are not revoked by a restore.

  Only if the promoted site fails verification, roll back, keeping the
  failed restore for inspection:
    sudo systemctl stop what
    test ! -e /srv/my-site-failed-restore-2026-10-27 && test ! -L /srv/my-site-failed-restore-2026-10-27
    sudo mv -T /srv/my-site /srv/my-site-failed-restore-2026-10-27
    sudo mv -T /srv/my-site-before-restore-2026-10-27 /srv/my-site
    sudo systemctl start what
    systemctl status what

WHY EACH SETTING
  --production   no file watching, live reload, developer tools, debug
                 output or detailed error pages; session cookies keep
                 Secure, so the site needs HTTPS (Caddy).
  127.0.0.1      only Caddy, on the same machine, reaches run-what; the
                 plain HTTP port is never public. trusted_proxy_hops = 1 is
                 correct only while this holds.
  allowed_origins  state-changing requests are accepted only from the
                 public HTTPS origin.
  WHAT_SERVER_FORM_SECRET  signs the rules of <form w-validate> forms; with
                 the same secret such a form opened before a restart still
                 submits after it, with a new one it must be reloaded. Forms
                 without w-validate (the course's edit forms) do not depend
                 on it; keep it stable for the w-validate forms you add.
  KillSignal=SIGINT  run-what shuts down cleanly on SIGINT; systemd's
                 default SIGTERM stops it without the clean shutdown.
  ProtectSystem=strict, ReadWritePaths  within the project the service can
                 write only data/ and uploads/; the site files and what.toml
                 stay as you installed them. (PrivateTmp gives it its own
                 writable temporary folder outside the project.)
