Skip to content

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

Merge #5158: Server installer: one command from a fresh Ubuntu server to HTTPS on your domain

milind-soni35b6f2cda5d7
diff --cc apps/docs/content/docs/self-hosting/deploy-vps.mdx
index 747b70c630,e8007980d1..989c9f5307
--- a/apps/docs/content/docs/self-hosting/deploy-vps.mdx
+++ b/apps/docs/content/docs/self-hosting/deploy-vps.mdx
@@@ -279,168 -353,20 +354,171 @@@ 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`.
-- **Installed with the installer:** run the install command again.
-- **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
+```
+
++An install made with the installer (`deploy/install.sh`) already has `update.sh` in
++its folder: `sudo /opt/openmausbot/update.sh`.
++
+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`. 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 b55aad03d6,606fe0f380..5714a85ac8
--- a/docs/deploy-vps.md
+++ b/docs/deploy-vps.md
@@@ -259,168 -333,20 +334,171 @@@ 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`.
-- **Installed with the installer:** run the install command again.
-- **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
+```
+
++An install made with the installer (`deploy/install.sh`) already has `update.sh` in
++its folder: `sudo /opt/openmausbot/update.sh`.
++
+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`. 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 ba69f65ce0,a13f61878d..6a04362ff8
--- a/docs/self-hosting.md
+++ b/docs/self-hosting.md
@@@ -112,6 -112,22 +112,23 @@@ would answer the whole internet over pl
### Docker with your own domain
+ On a fresh Ubuntu 22.04 or 24.04 server (x86-64), one command checks the
+ server, installs MausBot under `/opt/openmausbot` and ends with HTTPS on your
+ domain:
+
+ ```sh
+ curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh | sudo sh -s -- --domain maus.example.com
+ cd /opt/openmausbot && sudo docker compose exec omb openmausbot pair # Link https://<DOMAIN>/pair#code=…
+ ```
+
-Add `--check` to only check the server. Running it again updates or repairs;
++Add `--check` to only check the server. Running it again repairs;
++`sudo /opt/openmausbot/update.sh` updates, with a copy of the data first;
+ `--uninstall` stops the server and keeps your data. The checks, the files it
+ writes and what it contacts are in
+ [Deploy on a VPS](deploy-vps.md#quick-start-one-command-on-your-own-domain).
+
+ By hand, on any system with Docker:
+
```sh
git clone https://github.com/milind-soni/OpenMausBot && cd OpenMausBot/deploy
cp .env.example .env # set DOMAIN (and ENGINES)
@@@ -1451,16 -1466,16 +1472,19 @@@ settings do not change it
## Updating
-For the npm service, [install the chosen new version](deploy-vps.md#update)
-as the service user while the server is stopped, then start it again.
-For a foreground invocation, `npx --yes [email protected] serve --tunnel`
-selects a particular published release; replace `X.Y.Z` with that version.
+Self-hosted servers follow the **stable** channel: a released version that our
+own Clouds have run for 48 hours, named by the image tag `stable` and by
+[`stable.json`](https://raw.githubusercontent.com/milind-soni/OpenMausBot/channels/stable.json).
+`latest` follows `main` and is not for a server you rely on. The update check
+(`GET /api/updates/check`, **Check for updates** in the app) compares the
+server with the stable version; `OMB_UPDATE_CHANNEL=newest` makes it follow
+every release instead.
+ A server installed with the [installer](deploy-vps.md#quick-start-one-command-on-your-own-domain)
-updates by running the install command again.
++updates with `sudo /opt/openmausbot/update.sh`, which the installer puts there.
+
```sh
-docker compose -f deploy/docker-compose.yml pull omb && docker compose -f deploy/docker-compose.yml up -d # Docker
+cd deploy && git pull && ./update.sh # Docker: copy the data, update, roll back on failure
git pull && pnpm install && sudo systemctl restart openmausbot # from source
```