Add registration toggle and password change; genericise deploy
Two things the running instance needed. **Registration toggle.** Admin -> General, backed by a new settings table group rather than the environment. LEMBAS_ALLOW_SIGNUP now seeds only the initial value: once an administrator saves the setting, the stored value wins. The alternative -- environment always winning -- means a toggle in the UI silently reverts on the next restart, which is worse than not offering one. Closing registration also removes the "Create one" link from the sign-in page, so the link never leads somewhere that refuses. **Password change**, on the user settings page. Changing a password revokes every other session and immediately re-issues a cookie for the current one: if the reason for the change is that somebody else knows the password, leaving their session alive defeats the point, but signing the user out of the tab they are standing in is merely rude. **deploy/ is now host-agnostic.** This repository is public, so the unit and vhost became templates with __PREFIX__ / __SITE_HOST__ / __APP_PORT__ substituted at install time, and every path, hostname and port moved to environment variables. REPO_URL defaults to the checkout's own origin so a fork deploys itself. Machine-specific values belong in private notes, not here -- CLAUDE.md now says so. 83 tests, ruff clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+43
-33
@@ -1,51 +1,63 @@
|
||||
# Deployment
|
||||
|
||||
Installs LLeMbas as a **system** service behind nginx at `https://chat.lan`.
|
||||
Installs LLeMbas as a **system** service behind nginx with a self-signed
|
||||
certificate. Written for a systemd + nginx host; tested on Arch.
|
||||
|
||||
Written for `gamebox` (Arch), and follows the conventions already used there
|
||||
for llama-swap and comfyui:
|
||||
|
||||
| | |
|
||||
| | Default |
|
||||
|---|---|
|
||||
| Service user | `lembas` (system account, `nologin`) |
|
||||
| Home | `/home/lembas`, bind-mounted to `/srv/lembas` |
|
||||
| Checkout | `/srv/lembas/app` (git clone of the Gitea remote) |
|
||||
| Virtualenv | `/srv/lembas/venv` |
|
||||
| Database | `/srv/lembas/data/lembas.db` |
|
||||
| Environment | `/srv/lembas/lembas.env` (mode 600) |
|
||||
| Home | `/home/lembas` |
|
||||
| Install prefix | `/srv/lembas` (bind mount of the home) |
|
||||
| Checkout | `$PREFIX/app` |
|
||||
| Virtualenv | `$PREFIX/venv` |
|
||||
| Database | `$PREFIX/data/lembas.db` |
|
||||
| Environment | `$PREFIX/lembas.env` (mode 600) |
|
||||
| Unit | `/etc/systemd/system/lembas.service` |
|
||||
| Vhost | `/etc/nginx/conf.d/chat.lan.conf`, self-signed cert |
|
||||
| Listens | `127.0.0.1:8080` — reachable only through nginx |
|
||||
| Vhost | `/etc/nginx/conf.d/<host>.conf` |
|
||||
| Listens on | `127.0.0.1:8080` — reachable only through nginx |
|
||||
|
||||
The home lives on `/home` rather than `/var/lib` because the root LV on that
|
||||
box is only 50 GB; `/srv/lembas` is the same bind-mount trick as `/srv/llama`
|
||||
and `/srv/comfyui`.
|
||||
The prefix defaults to a bind mount of the service user's home because on many
|
||||
machines the root filesystem is small while `/home` is not, and the virtualenv
|
||||
plus database belong on the larger volume. Set `PREFIX=$HOME_DIR` to skip it.
|
||||
|
||||
## First install
|
||||
|
||||
```bash
|
||||
./deploy/install.sh
|
||||
SITE_HOST=chat.example ./deploy/install.sh
|
||||
```
|
||||
|
||||
Idempotent — safe to re-run. It creates the user and bind mount, clones the
|
||||
repo, builds the venv, generates `lembas.env` with a fresh
|
||||
`LEMBAS_SECRET_KEY`, installs the unit and vhost, issues a self-signed cert,
|
||||
adds a `/etc/hosts` entry, and enables the service.
|
||||
repo, builds the venv, generates `lembas.env` with a fresh `LEMBAS_SECRET_KEY`,
|
||||
installs the unit and vhost, issues a self-signed certificate, adds a
|
||||
`/etc/hosts` entry if the name does not already resolve, and enables the
|
||||
service.
|
||||
|
||||
Then open <https://chat.lan>, accept the self-signed certificate warning, and
|
||||
create the first account — it becomes the administrator.
|
||||
Then open `https://<SITE_HOST>`, accept the certificate warning, and create the
|
||||
first account — it becomes the administrator.
|
||||
|
||||
Everything is overridable from the environment:
|
||||
|
||||
| Variable | Default | |
|
||||
|---|---|---|
|
||||
| `SITE_HOST` | `lembas.local` | nginx `server_name` and certificate CN |
|
||||
| `APP_PORT` | `8080` | loopback port the service binds |
|
||||
| `SERVICE_USER` | `lembas` | system account to run as |
|
||||
| `HOME_DIR` | `/home/lembas` | that account's home |
|
||||
| `PREFIX` | `/srv/lembas` | install root (bind mount of `HOME_DIR`) |
|
||||
| `REPO_URL` | this checkout's `origin` | so a fork deploys itself |
|
||||
| `LEMBAS_BRANCH` | `main` | branch to deploy |
|
||||
|
||||
## Deploying a change
|
||||
|
||||
```bash
|
||||
git push # from the working copy
|
||||
git push
|
||||
./deploy/update.sh
|
||||
```
|
||||
|
||||
`update.sh` fetches, hard-resets `/srv/lembas/app` to `origin/main`, reinstalls
|
||||
dependencies and restarts the service, then prints what changed. The hard reset
|
||||
is deliberate: nothing is ever edited in place there, so there is no local work
|
||||
to preserve and no merge conflicts to resolve.
|
||||
`update.sh` fetches, hard-resets the deployment checkout to `origin/main`,
|
||||
reinstalls dependencies and restarts, printing the commits it pulled. The hard
|
||||
reset is deliberate: nothing is ever edited in place there, so there is no local
|
||||
work to preserve and no conflicts to resolve.
|
||||
|
||||
## Operating it
|
||||
|
||||
@@ -53,10 +65,9 @@ to preserve and no merge conflicts to resolve.
|
||||
systemctl status lembas
|
||||
journalctl -u lembas -f
|
||||
sudo -u lembas /srv/lembas/venv/bin/lembas info # paths and counts
|
||||
sudo systemctl restart lembas
|
||||
```
|
||||
|
||||
Configuration lives in `/srv/lembas/lembas.env`. Edit it and restart.
|
||||
Configuration lives in `$PREFIX/lembas.env`. Edit it and restart.
|
||||
|
||||
## Notes
|
||||
|
||||
@@ -70,11 +81,10 @@ delivers it in one lump at the end, which is indistinguishable from streaming
|
||||
being broken. `proxy_read_timeout` is raised to an hour because a model can
|
||||
think for minutes before the first token.
|
||||
|
||||
**Name resolution.** `chat.lan` is in Pi-hole, but this box queries the router
|
||||
first and the router's dnsmasq is authoritative for `.lan` without forwarding
|
||||
those queries on — the same reason `comfy.lan` needs one. `install.sh` adds a
|
||||
`/etc/hosts` entry, which is harmless if DNS already answers.
|
||||
|
||||
**Hardening is deliberately moderate.** `ProtectSystem=full`, not `strict`: the
|
||||
agentic features planned for later need to run commands, and a lockdown that
|
||||
has to be torn out again is worse than one that was never applied.
|
||||
|
||||
**Use a real certificate if this is exposed beyond a trusted LAN.** The
|
||||
self-signed cert exists so the install works with no external dependencies;
|
||||
point `ssl_certificate` at a real one and nothing else needs to change.
|
||||
|
||||
Reference in New Issue
Block a user