/ self-hosting / upgrade ← self-hosting

Upgrades and rollback

Two routes: rebuild from source, or let the box follow GitHub releases with a verified binary. Both end with the same health check, and both deserve a backup first.

Back up before upgrading. Migrations are append-only and applied at startup, so a downgrade means restoring the database from before the upgrade, not undoing a step. Backups and restore is the page that makes the rest of this one safe.

What an upgrade does to the database

On boot the server runs every migration it has not seen yet, in order, before it accepts a request. Migrations are numbered and never edited once applied, so an upgrade is additive: columns and tables appear. Nothing is dropped. A failed migration stops the boot rather than serving a half-migrated database, which is why /api/v1/health is the only check you need.

There is no down-migration. Rolling back the binary against a newer schema is not supported; restore the file.

From source

cd Yap
git pull
cd deploy
YAP_DOMAIN=chat.example.com docker compose up -d --build

The image is rebuilt first and the container is replaced after, so a build failure leaves the running server alone. Downtime is the restart, a couple of seconds; the first build after a big change takes minutes on a small ARM box.

Following releases automatically

deploy/autoupdate.sh plus yap-autoupdate.timer was laid down by the first push.ps1 deploy. The timer runs two minutes after boot and then once every 24 hours, and each run:

  1. asks GitHub for the latest release tag and compares it with /opt/yap/deployed-tag;
  2. downloads yap-server-linux-aarch64 and the release's SHA256SUMS, and refuses to install a binary whose hash is not listed;
  3. builds a runtime image from that binary through Dockerfile.binary and docker-compose.prebuilt.yml, so nothing compiles;
  4. polls /api/v1/health for up to a minute, restores deploy/bin/yap-server.prev and restarts if it never answers, and only records the tag once the server is serving.

Useful commands:

sudo /opt/yap/src/deploy/autoupdate.sh --check   # what is deployed vs what is published
sudo /opt/yap/src/deploy/autoupdate.sh --force   # rebuild the same tag anyway
systemctl list-timers yap-autoupdate.timer       # when it runs next
systemctl disable --now yap-autoupdate.timer     # stop checking

Two things worth knowing: the check tells GitHub this box's IP address once a day, and the release asset is arm64 only because that is the free-tier shape — YAP_ASSET overrides the name elsewhere. Put GITHUB_TOKEN in /etc/yap-autoupdate.env if the anonymous API limit ever matters.

Rolling back

  1. docker compose down. Do not delete the yap-data volume.
  2. Restore the database file from before the upgrade (see backups), replacing yap.db, yap.db-wal and yap.db-shm together.
  3. Check out the previous tag, or copy deploy/bin/yap-server.prev into place, and docker compose up -d.
  4. Write the old tag back into /opt/yap/deployed-tag if the box follows releases, or the next timer run will upgrade it again.
  5. curl -sS https://HOST/api/v1/health — ok means the schema and the binary agree.

Publishing a release

One tag, and the workspace version in Cargo.toml has to match it: git tag v0.2.0 && git push origin v0.2.0. The release workflow builds linux x86_64, linux arm64 and windows x86_64, proves each binary starts, and publishes them with SHA256SUMS. It refuses a tag that does not match the workspace version, so a box following releases can never record a tag that is not a real release.

Updated . Part of hosting and self-hosting.