# Updating

> Moving to a new release: back up, check out the new tag, pull the images and start again. The migrations run before the API, and open tabs reload by themselves.

## Before you start

1. **Read the release notes** of the new tag on GitHub: they say what changed, new settings in
   `.env.example`, and anything to do by hand.
2. **Back up** ([Backups](https://docs.klang.gg/self-hosting/backups/)). Migrations only go forward: the backup is the
   only way back.
3. Update one release at a time if you’re several behind, reading each one’s notes.

## Update

From the repository’s folder:

```bash
git fetch --tags
git checkout v0.0.32          # the new release
cd selfhost
```

Compare your `.env` with the new `.env.example` and add what’s new (`diff .env.example .env`
helps). The tag’s `docker-compose.yml` names its own images, so there’s no version to change in
`.env` (unless you set `KLANG_VERSION` there to pin one: remove that line). Then:

```bash
docker compose pull
docker compose up -d
docker compose restart caddy   # so it reads the new release’s Caddyfile
```

If you build the images yourself, `docker compose build` instead of `pull`.

What happens:

- `migrate` runs the new migrations, and the API and the gateways only start once it’s done. If
  one fails, the new API doesn’t start: `docker compose logs migrate` says why, and your backup
  is the way back.
- `s3-init` runs again and applies the store’s current policies.
- People with Klang open get reconnected. If the app in an open tab is older than the new
  gateway accepts, it reloads itself at a quiet moment (not during a call, not with a message
  half written), so nobody has to refresh.

Check it with `docker compose ps`: every service `running` or `healthy`, and `migrate` and
`s3-init` `Exited (0)`.

## Your changes

`git checkout` only works if you haven’t edited the repository’s files.

- **Your settings** are in `.env` and **your changes to the services** in
  `compose.override.yml`. Git ignores both, and an update never touches them.
- **An edited `Caddyfile`** (the panel’s address list, for example) is a change to a file of the
  repository. Keep it across the update with `git stash` before `git checkout` and
  `git stash pop` after, and check the result if the release changed the Caddyfile too.

## Going back

The database can’t be migrated back. To return to the previous release, restore the backup you
made before updating ([Restore](https://docs.klang.gg/self-hosting/backups/#restore)) with the previous tag checked
out.

## Cleaning up

Old images stay on disk. When the new release works, list Klang’s and remove the previous
version’s by name:

```bash
docker image ls 'ghcr.io/klang-gg/*'
docker image rm ghcr.io/klang-gg/klang-api:0.0.31   # and the other four of that version
```
