Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Merge #5303: Self-hosted: Caddy in its own container over Unix sockets, so HTTPS survives a server restart

milind-soni7928571d9d29
diff --cc apps/docs/content/docs/self-hosting/deploy-vps.mdx
index 9fd0e02787,05c85cdda5..747b70c630
--- a/apps/docs/content/docs/self-hosting/deploy-vps.mdx
+++ b/apps/docs/content/docs/self-hosting/deploy-vps.mdx
@@@ -279,167 -278,19 +279,168 @@@ same release without an npm install pro
## Update
-- **Paths A and C with the service above:** choose the new published version,
- then run these commands from the administrator shell, replacing `X.Y.Z`:
+A self-hosted server follows the **stable** channel: a released version that
+MausBot's own Clouds have run for 48 hours first. The image tag `stable` and
+[`stable.json`](https://raw.githubusercontent.com/milind-soni/OpenMausBot/channels/stable.json)
+name it. The tag `latest` follows every change on `main`; it is for trying
+things out, not for a server you rely on. **Check for updates** in the app
+compares your server with the stable version. To hear of every release as soon
+as it is published instead, set `OMB_UPDATE_CHANNEL=newest` in the server's
+environment.
- ```sh
- sudo systemctl stop openmausbot
- sudo -iu maus npm install --global --prefix /home/maus/.local [email protected]
- sudo systemctl start openmausbot
- ```
+### Path B (Docker): one command, with a way back
- Check that installation succeeded before starting. A service restart by itself
- does not update the installed package. For foreground `npx` usage, specify the
- desired release as `npx --yes [email protected] serve --tunnel`.
-- **Path B:** `cd OpenMausBot/deploy && git pull && docker compose pull omb && docker compose up -d`. The `git pull` brings the current `docker-compose.yml` and `Caddyfile`. Building from source instead (`docker compose up -d --build`) needs about 6 GB of memory: on a smaller server, add swap first or use the published image.
+From `OpenMausBot/deploy`:
+
+```sh
+git pull && ./update.sh
+```
+
+`git pull` brings the current `update.sh` and `docker-compose.yml`; the server
+image comes from the stable channel, not from your checkout. An install that
+has no checkout, with its `compose.yaml`, `.env` and `data/` in one folder such
+as `/opt/openmausbot`, runs the same script on that folder:
+
+```sh
+curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/update.sh -o update.sh
+sudo bash update.sh --dir /opt/openmausbot
+```
+
+Until a first version has been made stable, `./update.sh` takes the newest
+release instead, as **Check for updates** does then.
+
+The data may be a Docker volume or a folder on the server; the copy keeps
+every file's owner and mode either way. The script then:
+
+1. Downloads the stable image, by its digest. If that fails it stops, and
+ nothing has changed. It also stops, changing nothing, when that version is
+ older than the one your server says it runs (see "From `latest` to stable"
+ below).
+2. Checks there is room for a copy of your data where Docker keeps its
+ volumes, stops the server, checks that it has stopped, and copies
+ everything under `/data` into a new Docker volume named for the update
+ (`deploy_data-before-update-20261110T120000Z`;
+ `openmausbot_data-before-update-…` for `/opt/openmausbot`). It then
+ compares the copy with the data, every file by checksum; a copy that does
+ not match is thrown away, the server is started again, and nothing has
+ changed. The copy from the update before is removed only after this one
+ has matched. The server is down from here until step 4; how long depends
+ on how much data there is.
+3. Writes the image into `.env` (`OMB_IMAGE=ghcr.io/milind-soni/openmausbot@sha256:…`)
+ and starts it. An install the installer made while Caddy still shared the
+ server's network gets the installer's current `compose.yaml` and
+ `Caddyfile` here, as a run of the installer would write them (the rollback
+ puts the old ones back). For this repository's `docker-compose.yml`,
+ `git pull` brings the current one; `--check` says when it is needed.
+4. Waits, up to two minutes (`OMB_UPDATE_WAIT_S` for longer), until the new server answers `/api/health`
+ steadily, says it is the new version, can still start a bot if it could
+ before (the server's own count of ready engines, `GET /api/health/engines`,
+ which a hardened server answers too; `openmausbot doctor` on a version
+ without it), and Caddy runs again.
+5. If any of that fails: puts back the data from the copy, `.env` and the old
+ image, starts the old version, and tells you what went wrong. Your server
+ is as it was before step 1, except that `.env` now names the old version by
+ its digest: a tag such as the installer's `stable` may have moved since,
+ and a later run of the installer would otherwise follow it. `--rollback`
+ does the same. The copy is put into a new folder inside the
+ data and checked there before it takes the data's place, so a restore that
+ fails (a full disk, say) leaves both the data and the copy as they were:
+ the server stays stopped, the update's journal is kept, and
+ `./update.sh --rollback` tries again once the cause is fixed.
+
+A closed terminal or a dropped SSH session does not stop an update: it carries
+on, and `deploy/.update/update.log` says how it ended. Each step is written to
+`deploy/.update/journal` before it starts. Ctrl-C undoes the update at once:
+before the new version starts, nothing has changed; after, the old version and
+its data are put back. When an update was cut short some other way (a reboot,
+a killed process), the next `./update.sh` keeps the new version if that is up
+and healthy. If it is not, it says which version and data going back would put
+back, and that everything made on the server since that update would be lost,
+and asks: `yes` goes back, `keep` leaves the server as it is (the copy stays
+for `--rollback`), and anything else, or no answer at all, changes nothing.
+Run again after a finished update, it says there is nothing to do. Two runs at
+once are refused.
+
+```sh
+./update.sh --check # what would change; changes nothing
+./update.sh --version 0.1.151 # one released version instead of the stable one
+./update.sh --rollback # the version and the data from before the last update
+./update.sh --allow-older # go ahead although that version is not newer than the one running
+```
+
+`--rollback` is for an update that passed its checks and still turned out
+wrong. It asks first, because everything made since the update (chats, files,
+settings) is replaced by the copy; `--yes` answers for you. The copy is kept
+until the next update has made and checked its own. The script's own log is
+`deploy/.update/update.log`.
+
+| The script ends with | Meaning |
+| --- | --- |
+| `0` | Updated, or already on that version |
+| `1` | The update failed; the old version and its data are back |
+| `2` | The old version or its data could not be brought back; read the last lines it printed, then `./update.sh --rollback` |
+| `3` | Another update is running |
+| `4` | Nothing was changed (could not download, not enough disk, the folder cannot be written, a question not answered `yes`, refused) |
+| `5` | Nothing was changed: the version asked for is older than the one running, or one of the two versions cannot be told; `--allow-older` goes ahead |
+| `130` | Interrupted with Ctrl-C before the new version started: nothing was changed, and the server was started again |
+
+### From `latest` to stable
+
+A server started from the `latest` image runs a build of `main`. Its image is
+labelled with the branch, not a version, so `update.sh` goes by the version the
+server itself reports, which is that of the release it was built after, or of
+the next one. Such a build may already hold changes made after that release,
+and may have written data in ways the release does not read. So `update.sh`
+moves it to stable only once the stable version is newer than the version the
+server reports; until then it says so and changes nothing (exit `5`). Nothing
+else is needed: the first `./update.sh` after a newer version is made stable
+moves the server onto it and pins it by digest. To move now anyway, run
+`./update.sh --allow-older`; the data is copied first, and `--rollback` puts
+the `latest` build and its data back.
+
+If you built the image yourself (`docker compose up -d --build`, with
+`ENGINES` baked in), `update.sh` refuses to replace it without being told to:
+keep updating with `git pull && docker compose up -d --build`, or move to the
- published image with `./update.sh --replace-local-build`. Engines you install
++published image with `./update.sh --replace-local-build`. Building needs about 6 GB of memory:
++on a smaller server, add swap first or use the published image. Engines you install
+from **Settings → Engines** live on the data volume and survive either way.
+
+### Paths A and C (npm with the service above): the same steps by hand
+
+There is no one-command updater for an npm install yet. Do what the script
+does: copy the data first, install one named version, check it, and keep the
+way back. Take the stable version number from
+[`stable.json`](https://raw.githubusercontent.com/milind-soni/OpenMausBot/channels/stable.json)
+(`"version"`), and note the one you run now (`openmausbot --version`). From
+the administrator shell, replacing `X.Y.Z`:
+
+```sh
+sudo systemctl stop openmausbot
+sudo -iu maus sh -c 'umask 077; tar czf ~/openmausbot-before-update.tgz -C ~ .openmausbot'
+sudo -iu maus npm install --global --prefix /home/maus/.local [email protected]
+sudo systemctl start openmausbot
+curl -sf http://127.0.0.1:8799/api/health && sudo -iu maus openmausbot doctor
+```
+
+If the install fails, or the last line does not end with the server answering
+and an engine ready, go back (replace `OLD` with the version you noted):
+
+```sh
+sudo systemctl stop openmausbot
+sudo -iu maus npm install --global --prefix /home/maus/.local openmausbot@OLD
+sudo -iu maus sh -c 'mv ~/.openmausbot ~/.openmausbot-failed-update && tar xzf ~/openmausbot-before-update.tgz -C ~'
+sudo systemctl start openmausbot
+```
+
+A service restart by itself does not update the installed package. For
+foreground `npx` usage, name the release: `npx --yes [email protected] serve --tunnel`.
+
+### How far behind a server may fall
+
+The desktop and phone apps are built to work with any server version that was
+the stable one within the last 90 days. An older server keeps running, but the
+app tells you it is behind, and newer features may not work until you update
+it. Update at least every 90 days.
Routines and queued work survive a restart; a turn running at that moment does not, so update between runs.
diff --cc docs/deploy-vps.md
index 9603c5d475,1452d470e8..b55aad03d6
--- a/docs/deploy-vps.md
+++ b/docs/deploy-vps.md
@@@ -259,167 -258,19 +259,168 @@@ same release without an npm install pro
## Update
-- **Paths A and C with the service above:** choose the new published version,
- then run these commands from the administrator shell, replacing `X.Y.Z`:
+A self-hosted server follows the **stable** channel: a released version that
+MausBot's own Clouds have run for 48 hours first. The image tag `stable` and
+[`stable.json`](https://raw.githubusercontent.com/milind-soni/OpenMausBot/channels/stable.json)
+name it. The tag `latest` follows every change on `main`; it is for trying
+things out, not for a server you rely on. **Check for updates** in the app
+compares your server with the stable version. To hear of every release as soon
+as it is published instead, set `OMB_UPDATE_CHANNEL=newest` in the server's
+environment.
- ```sh
- sudo systemctl stop openmausbot
- sudo -iu maus npm install --global --prefix /home/maus/.local [email protected]
- sudo systemctl start openmausbot
- ```
+### Path B (Docker): one command, with a way back
- Check that installation succeeded before starting. A service restart by itself
- does not update the installed package. For foreground `npx` usage, specify the
- desired release as `npx --yes [email protected] serve --tunnel`.
-- **Path B:** `cd OpenMausBot/deploy && git pull && docker compose pull omb && docker compose up -d`. The `git pull` brings the current `docker-compose.yml` and `Caddyfile`. Building from source instead (`docker compose up -d --build`) needs about 6 GB of memory: on a smaller server, add swap first or use the published image.
+From `OpenMausBot/deploy`:
+
+```sh
+git pull && ./update.sh
+```
+
+`git pull` brings the current `update.sh` and `docker-compose.yml`; the server
+image comes from the stable channel, not from your checkout. An install that
+has no checkout, with its `compose.yaml`, `.env` and `data/` in one folder such
+as `/opt/openmausbot`, runs the same script on that folder:
+
+```sh
+curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/update.sh -o update.sh
+sudo bash update.sh --dir /opt/openmausbot
+```
+
+Until a first version has been made stable, `./update.sh` takes the newest
+release instead, as **Check for updates** does then.
+
+The data may be a Docker volume or a folder on the server; the copy keeps
+every file's owner and mode either way. The script then:
+
+1. Downloads the stable image, by its digest. If that fails it stops, and
+ nothing has changed. It also stops, changing nothing, when that version is
+ older than the one your server says it runs (see "From `latest` to stable"
+ below).
+2. Checks there is room for a copy of your data where Docker keeps its
+ volumes, stops the server, checks that it has stopped, and copies
+ everything under `/data` into a new Docker volume named for the update
+ (`deploy_data-before-update-20261110T120000Z`;
+ `openmausbot_data-before-update-…` for `/opt/openmausbot`). It then
+ compares the copy with the data, every file by checksum; a copy that does
+ not match is thrown away, the server is started again, and nothing has
+ changed. The copy from the update before is removed only after this one
+ has matched. The server is down from here until step 4; how long depends
+ on how much data there is.
+3. Writes the image into `.env` (`OMB_IMAGE=ghcr.io/milind-soni/openmausbot@sha256:…`)
+ and starts it. An install the installer made while Caddy still shared the
+ server's network gets the installer's current `compose.yaml` and
+ `Caddyfile` here, as a run of the installer would write them (the rollback
+ puts the old ones back). For this repository's `docker-compose.yml`,
+ `git pull` brings the current one; `--check` says when it is needed.
+4. Waits, up to two minutes (`OMB_UPDATE_WAIT_S` for longer), until the new server answers `/api/health`
+ steadily, says it is the new version, can still start a bot if it could
+ before (the server's own count of ready engines, `GET /api/health/engines`,
+ which a hardened server answers too; `openmausbot doctor` on a version
+ without it), and Caddy runs again.
+5. If any of that fails: puts back the data from the copy, `.env` and the old
+ image, starts the old version, and tells you what went wrong. Your server
+ is as it was before step 1, except that `.env` now names the old version by
+ its digest: a tag such as the installer's `stable` may have moved since,
+ and a later run of the installer would otherwise follow it. `--rollback`
+ does the same. The copy is put into a new folder inside the
+ data and checked there before it takes the data's place, so a restore that
+ fails (a full disk, say) leaves both the data and the copy as they were:
+ the server stays stopped, the update's journal is kept, and
+ `./update.sh --rollback` tries again once the cause is fixed.
+
+A closed terminal or a dropped SSH session does not stop an update: it carries
+on, and `deploy/.update/update.log` says how it ended. Each step is written to
+`deploy/.update/journal` before it starts. Ctrl-C undoes the update at once:
+before the new version starts, nothing has changed; after, the old version and
+its data are put back. When an update was cut short some other way (a reboot,
+a killed process), the next `./update.sh` keeps the new version if that is up
+and healthy. If it is not, it says which version and data going back would put
+back, and that everything made on the server since that update would be lost,
+and asks: `yes` goes back, `keep` leaves the server as it is (the copy stays
+for `--rollback`), and anything else, or no answer at all, changes nothing.
+Run again after a finished update, it says there is nothing to do. Two runs at
+once are refused.
+
+```sh
+./update.sh --check # what would change; changes nothing
+./update.sh --version 0.1.151 # one released version instead of the stable one
+./update.sh --rollback # the version and the data from before the last update
+./update.sh --allow-older # go ahead although that version is not newer than the one running
+```
+
+`--rollback` is for an update that passed its checks and still turned out
+wrong. It asks first, because everything made since the update (chats, files,
+settings) is replaced by the copy; `--yes` answers for you. The copy is kept
+until the next update has made and checked its own. The script's own log is
+`deploy/.update/update.log`.
+
+| The script ends with | Meaning |
+| --- | --- |
+| `0` | Updated, or already on that version |
+| `1` | The update failed; the old version and its data are back |
+| `2` | The old version or its data could not be brought back; read the last lines it printed, then `./update.sh --rollback` |
+| `3` | Another update is running |
+| `4` | Nothing was changed (could not download, not enough disk, the folder cannot be written, a question not answered `yes`, refused) |
+| `5` | Nothing was changed: the version asked for is older than the one running, or one of the two versions cannot be told; `--allow-older` goes ahead |
+| `130` | Interrupted with Ctrl-C before the new version started: nothing was changed, and the server was started again |
+
+### From `latest` to stable
+
+A server started from the `latest` image runs a build of `main`. Its image is
+labelled with the branch, not a version, so `update.sh` goes by the version the
+server itself reports, which is that of the release it was built after, or of
+the next one. Such a build may already hold changes made after that release,
+and may have written data in ways the release does not read. So `update.sh`
+moves it to stable only once the stable version is newer than the version the
+server reports; until then it says so and changes nothing (exit `5`). Nothing
+else is needed: the first `./update.sh` after a newer version is made stable
+moves the server onto it and pins it by digest. To move now anyway, run
+`./update.sh --allow-older`; the data is copied first, and `--rollback` puts
+the `latest` build and its data back.
+
+If you built the image yourself (`docker compose up -d --build`, with
+`ENGINES` baked in), `update.sh` refuses to replace it without being told to:
+keep updating with `git pull && docker compose up -d --build`, or move to the
- published image with `./update.sh --replace-local-build`. Engines you install
++published image with `./update.sh --replace-local-build`. Building needs about 6 GB of memory:
++on a smaller server, add swap first or use the published image. Engines you install
+from **Settings → Engines** live on the data volume and survive either way.
+
+### Paths A and C (npm with the service above): the same steps by hand
+
+There is no one-command updater for an npm install yet. Do what the script
+does: copy the data first, install one named version, check it, and keep the
+way back. Take the stable version number from
+[`stable.json`](https://raw.githubusercontent.com/milind-soni/OpenMausBot/channels/stable.json)
+(`"version"`), and note the one you run now (`openmausbot --version`). From
+the administrator shell, replacing `X.Y.Z`:
+
+```sh
+sudo systemctl stop openmausbot
+sudo -iu maus sh -c 'umask 077; tar czf ~/openmausbot-before-update.tgz -C ~ .openmausbot'
+sudo -iu maus npm install --global --prefix /home/maus/.local [email protected]
+sudo systemctl start openmausbot
+curl -sf http://127.0.0.1:8799/api/health && sudo -iu maus openmausbot doctor
+```
+
+If the install fails, or the last line does not end with the server answering
+and an engine ready, go back (replace `OLD` with the version you noted):
+
+```sh
+sudo systemctl stop openmausbot
+sudo -iu maus npm install --global --prefix /home/maus/.local openmausbot@OLD
+sudo -iu maus sh -c 'mv ~/.openmausbot ~/.openmausbot-failed-update && tar xzf ~/openmausbot-before-update.tgz -C ~'
+sudo systemctl start openmausbot
+```
+
+A service restart by itself does not update the installed package. For
+foreground `npx` usage, name the release: `npx --yes [email protected] serve --tunnel`.
+
+### How far behind a server may fall
+
+The desktop and phone apps are built to work with any server version that was
+the stable one within the last 90 days. An older server keeps running, but the
+app tells you it is behind, and newer features may not work until you update
+it. Update at least every 90 days.
Routines and queued work survive a restart. A teammate turn running at that moment runs again once at the next start, told to check what it already did, and the bot that asked for it is told. A person's own turn and a running routine are not run again: the conversation says it was interrupted. Update between runs where you can.
diff --cc docs/self-hosting.md
index 66749ac437,90d50045d9..a917cc711c
--- a/docs/self-hosting.md
+++ b/docs/self-hosting.md
@@@ -340,11 -340,11 +340,13 @@@ cp .env.example .env # set D
docker compose pull omb && docker compose up -d
```
-That uses the image CI publishes on every `main` push
-(`ghcr.io/milind-soni/openmausbot`, tagged `latest`, `sha-…` and `v…`).
-To build from your checkout instead: `docker compose up -d --build`. The
+That starts the image CI publishes on every `main` push
+(`ghcr.io/milind-soni/openmausbot:latest`; each release is also tagged `v…`,
+and the one our own Clouds have run for 48 hours is `stable`). Move to the
+stable version right away with `./update.sh`, which pins it by digest in
- `.env`. To build from your checkout instead: `docker compose up -d --build`.
++`.env`. To build from your checkout instead: `docker compose up -d --build`. The
+ build needs about 6 GB of memory: on a smaller server, add swap first or use
+ the published image.
Then sign the engine CLIs in **inside the container** (their logins live on
the `data` volume, so they survive restarts and image upgrades) and mint a