Setu

Your binaries. Your servers. One control panel.

Setu 0.1.7 design: resilience, site aliases, per-site noindex

Status: draft (web-s2, 2026-11-22). Scope is the owner-approved list in krishiv-internal/ops/web-plan-2026-11.md section 3. Setu 0.2 is a later phase.

1. Resilience (issues #14, #15, #16) — PR #26

  • #16: the control plane rebuilds its database pool after a Postgres crash instead of keeping dead connections.
  • #14: the self-backup loop survives a database error and records it as last_error.
  • #15: manual and scheduled self-backups take one exclusive lock (<data_dir>/backups/setu/.lock), so no 0-byte dump.

2. Site aliases (issue #18)

A site has one canonical domain. Aliases are extra hostnames:

modeCaddy routeeffect
redirectstatic_response 308 to https://<domain>{uri}, host matcher [alias]the alias sends visitors to the canonical name
servethe alias is added to the site route's host matcherthe site answers on the alias too

Naming the host in a matcher is what makes Caddy obtain a certificate (same as the www. route of 0.1.7 #25).

Data

  • New table site_aliases(site_id → sites ON DELETE CASCADE, host text, mode text CHECK in ('redirect','serve'), PRIMARY KEY (site_id, host)), migration 0007_site_aliases.sql. A separate table, not a column on sites, so no existing query! macro or .sqlx entry changes; the new repo functions use runtime-checked sqlx::query.
  • host: validated like domain (valid_domain), lower-cased, not equal to the site's own domain, unique across all sites' domains and aliases (409 on a clash), at most 10 per site.
  • An alias that equals the site's www. name replaces the automatic www_redirect for that name (the explicit alias wins; www_host returns None when an alias names it).

API

  • PUT /api/v1/sites/{id}/aliases body {"aliases":[{"host","mode"}]} replaces the list, stores it and queues the route_update job in one transaction (same shape as PUT .../www-redirect: operator role, 409 with an active job or a status other than running/stopped, audit site.aliases_set).
  • GET /sites/{id}/aliases returns the list (GET /sites/{id} and the list do not carry it). openapi.json regenerates here; ui/src/lib/api-types.d.ts is regenerated with the UI part (web-o1), the only user of the types.
  • A hostname belongs to one site: a site's domain, its aliases and its automatic www. name (www_redirect on) never overlap. Checked in the control plane, in the same transaction and under one advisory lock, in all directions: an alias PUT, a site create and turning www_redirect on each answer 409 on a clash. The agent also counts other sites' aliases as taken and re-applies the neighbours' routes when a host changes hands.
  • Both PUTs (aliases, noindex) answer 409 when the server's agent is older than 0.1.7, and the route_update job fails unless the agent's set_route answer echoes the number of aliases and the noindex setting it applied.

Control plane to agent

  • Command::SetRoute gains #[serde(default)] aliases: Vec<Alias>; an older control plane sends none: no aliases.
  • The agent records aliases in SiteRecord (default empty, so an old state file changes nothing), reconcile rebuilds the routes from state.
  • Route ids: redirect alias setu-site-<short>-alias-<n>; serve aliases live in the site route itself. valid_route_id accepts the -alias-<n> suffix. Routes of removed aliases are deleted on the next SetRoute; RemoveRoute removes all of them. Golden files under crates/agent/tests/golden/ for both modes.
  • A serve alias or a redirect alias must not shadow another site's domain (checked in the control plane and again by the agent, like www_host).

UI

An "Aliases" field on the site page (list of host + mode, add/remove), shown on the sites list detail. Front-end part goes to web-o1 after the API is merged.

3. Per-site noindex (staging sites)

  • Column sites.noindex boolean NOT NULL DEFAULT false is avoided for the same .sqlx reason: stored in the new table site_options(site_id PK, noindex bool) with runtime queries.
  • PUT /api/v1/sites/{id}/noindex {"enabled": bool} queues a route_update job.
  • SetRoute gains #[serde(default)] noindex: bool. When on, the agent adds to the site route a headers handler setting X-Robots-Tag: noindex, nofollow on every response, and a /robots.txt handler answering User-agent: *\nDisallow: / (a route placed before the reverse proxy, so the app cannot override it).
  • Default off: an upgrade changes no existing site.

4. Release 0.1.7

CHANGELOG entry (API-only: aliases and noindex have no UI in 0.1.7 unless web-o1 lands it), version bump, docs/OPERATIONS.md section for aliases and noindex, upgrade of the krishiv.ai host arranged by the coordinator.

5. Tests

  • db: repo tests for aliases (cascade, uniqueness, clash).
  • agent: route golden files, reconcile from state, shadowing refusal, noindex route; a state file without the new fields.
  • proto: a set_route without aliases/noindex means none.
  • api: PUT aliases 202/400/409, role check (a viewer gets 403), every clash direction, noindex PUT, an agent older than 0.1.7 (409), an agent that does not echo (job fails).
  • jobs: provision sends the stored aliases and noindex.
  • The DB suite needs Docker (scripts/test.sh); the VPS lane has none, so CI is the first run.