# Self-update The app can replace its own container. The feature is off until `ALLOW_SELF_UPDATE=true`. It starts from the "Update available" tag next to the version, then **Self-update**. The UI drops while the container is replaced, then reloads and shows the result. The same result goes to the configured [notification](NOTIFICATIONS.md) URLs. If the app does not come back, the page stops waiting and shows an error. The agent and the socket-proxy are not part of this update. A running or queued check or update refuses the self-update. From the moment it starts until the app process is gone, new scheduled and manual jobs stay queued. The running process cannot recreate its own container, so a short-lived helper container from the new image performs the swap. ```mermaid flowchart TD Start[Manual self-update] --> Busy{Check or update active?} Busy -- yes --> Refuse[Refused] Busy -- no --> Pull[Pull the current tag] Pull -- already running --> Noop[No newer image] Pull -- newer --> Helper[Start the helper from the new image] Helper --> Swap[Rename the app, create the new container, connect secondary networks, stop the old one, back up SQLite, start the new one] Swap -- healthy --> Done[Remove the old container and the backup] Swap -- not healthy --> Roll[Remove the new container, restore the database, start the old one] Roll -- cannot finish --> Failed[Report failed and leave the old container stopped] ``` The helper is named `-self-update`. It receives only the app's Docker access (`DOCKER_HOST`, networks, and either the socket mount or, for `tcp://` and `https://` with `DOCKER_TLS_VERIFY`, the TLS variables and the certificate directory mount) and the data volume. The label `dev.quenary.tugtainer.protected` keeps scheduled updates away from it, and it is removed when it exits. The old container is renamed `-old` and is removed only after the new one is healthy. Every network is kept on Docker and on Podman: the primary network is set when the container is created, and the others are connected before it starts. The helper is attached the same way, so a socket-proxy on another network stays reachable. A pulled image that matches the running one stops with "No newer image". A pinned tag such as `:1.44.3` follows that tag; the dialog's GitHub comparison can disagree with it. If the new container cannot be removed, or the database cannot be restored, rollback stops and reports `failed`. The old version does not start beside the new one or on a migrated database. After startup the app (new or restored) waits for the helper, reports the result once, and drops the helper's journal. A leftover `-old` is removed only when that journal records it as the old container of a successful update. ## Migration from 1.x Upgrading the app container is manual. See [Upgrading to 2.x](../README.md#upgrading-to-2x). The helper accepts only a plan with `version: 2` and stops before it changes anything when the plan is older. ## Podman and systemd - For Podman hosts, the helper container runs against the same service socket and user namespace as the application (never switching rootless to rootful). - Recreation and self-update are refused before the container is stopped when it is managed by systemd or Quadlet (label or environment `PODMAN_SYSTEMD_UNIT`). The container keeps running. Use `podman auto-update` for those units. ## Requirements - `/tugtainer` is a volume or a bind mount. Otherwise the update is refused. - With the default SQLite database, the file lives inside `/tugtainer`. Other databases are not copied, so a failed update cannot undo their migrations. - The helper uses the app's Docker access. `DOCKER_HOST` is passed through. `DOCKER_TLS_VERIFY` and `DOCKER_CERT_PATH` are passed through, and the certificate directory is mounted read-only, only when the host is `tcp://` or `https://` and `DOCKER_TLS_VERIFY` is set. Self-update is refused when that directory is not already mounted on the app. - The provided socket-proxy allows renames when `CONTAINERS=1` and `POST=1`. - Without `JWT_SECRET_KEY` the new container generates a new secret and existing sessions end. ## Recovery A helper result of `failed` (rollback did not finish) or `interrupted` (the helper exited without a result) leaves the containers for an operator. Nothing else rolls back: `-old` stays stopped, and a new container may already exist under the original name, possibly on a migrated database. ```bash docker ps -a --filter name=tugtainer docker logs -self-update cat /path/to/tugtainer_data/self_update/state.json ``` `state.json` lists the steps that finished. The database copy remains in `self_update/backup/`. Recovery is: remove the new container if it exists, copy the backup files back beside `tugtainer.db`, rename `-old` to ``, and start it.