Keeping a deployment up to date =============================== A deployment changes in three ways. Debian updates its own packages once a day. The roles pull or rebuild their container images when they run, which is only when somebody runs them. And the versions written down in the repository move only with a commit. This chapter says which part of the stack changes in which way, how to see that something is waiting, when to go ahead and when to ask first, and how a change is rolled out. Moving to a new Debian release is a procedure of its own, see :doc:`upgrading`. What updates itself ------------------- Debian packages ~~~~~~~~~~~~~~~ The ``unattended-upgrades`` role switches on apt's periodic runs: ``apt-daily.timer`` fetches the package lists and ``apt-daily-upgrade.timer`` runs unattended-upgrades, once a day each. Which packages get installed is decided by the ``50unattended-upgrades`` file that ships with the Debian package, and the role leaves it as it is: the security archive of the running release, and the release itself, which changes at every point release. ``-updates`` is not on that list; what arrives there waits for a person and is only counted. unattended-upgrades never reboots the host (``ae_unattended_upgrades_automatic_reboot`` is ``false``). A new kernel is installed, but it only runs after a reboot, and that is left to a person; see :ref:`updates-reboots`. On a Debian 12 host the ``podman`` role holds every package from the Kubic repository, so apt never upgrades podman, conmon, crun and the rest there; :doc:`upgrading` explains why. Nextcloud apps ~~~~~~~~~~~~~~ The Nextcloud container runs the role's ``configure.sh`` every time it starts (the image's ``before-starting`` hook). The script switches the app store on, runs ``occ app:update --all`` and switches the store off again, so every restart of ``ae-nextcloud`` brings the apps to their newest release for the running Nextcloud version. Nextcloud itself is not updated this way: the update notification app is disabled, the web updater is switched off (``upgrade.disable-web``), and the server version moves only with the image tag, see below. What a playbook run brings -------------------------- Container images are pulled or built by the role that runs the container, at the moment the role runs, and at no other time. No timer on the host pulls an image, and podman's auto-update is not used. What a run brings depends on how the role names its image. .. list-table:: :header-rows: 1 :widths: 20 35 45 * - Kind - Roles - What it takes * - Pinned to a version - ``caddy``, ``nextcloud``, ``lldap``, ``grafana``, ``prometheus``, ``collabora``, the exporters - A new release: a commit that changes the version, then a run of the role. A rebuild of the same tag: a run for ``caddy`` and ``nextcloud``, ``podman pull`` and a restart by hand for the others. * - Floating tag - ``roundcube`` (``1.7.x-fpm``), ``postgres`` (``18``), ``redis`` (``8``) - A run of the role. ``postgres`` needs a restart on top. * - Built on the host - ``postfix``, ``dovecot``, ``rspamd``, ``unbound``, ``mailman``, ``seam``, ``knutt``, ``website``, ``bokstaever`` - A run of the role. Pinned to a version The version is a variable in the role's ``defaults/main.yml``; for Nextcloud it is ``ae_nextcloud_version`` in ``ansible/group_vars/all.yml``, so that a host can override it. A new release needs a commit that changes the value, and then a run of the role. Docker's official images re-push a released tag when the base under it gets fixes. ``caddy`` and ``nextcloud`` pull their tag again on every run (``force`` on the pull) and restart their container only when the digest moved, so for them a run is enough to get a rebuilt tag. The other pinned roles never fetch a tag again once the host has it; a rebuilt tag takes ``podman pull`` and a restart of the unit by hand, see :ref:`updates-alert-image-outdated`. Floating tag ``roundcube`` follows its release branch, ``postgres`` and ``redis`` their major version. Each run pulls the tag again and restarts the container when the digest moved, so point releases arrive with any run of the role. ``postgres`` is the exception: it pulls but does not restart, because every application that requires it would restart along with it. The new image is used from the next deliberate restart of ``ae-postgres`` or the next reboot. ``mattermost``'s ``release-11`` floats as well, but it is never pulled again once the image is on the host. Built on the host ``postfix``, ``dovecot``, ``rspamd`` and ``unbound`` build on a fresh ``debian:trixie`` without a layer cache. ``mailman`` builds from the ``docker-mailman`` submodule, its web image on ``alpine:3.23``. ``seam``, ``knutt``, ``website`` and ``bokstaever`` check out the branch they follow and build from it; ``website`` with ``ae_website_source`` set builds from a checkout on the control machine instead. Every run of these roles pulls the base image again (``--pull=always``) and rebuilds, so the packages inside are as current as the last run, and no newer: nothing rebuilds them in between. A run of a role that follows a branch also deploys whatever that branch holds at the moment. A new mailman release is a commit that moves the submodule. .. _updates-reboots: Reboots ------- A kernel update, and any other package that needs a reboot, creates ``/run/reboot-required`` and adds its name to ``/run/reboot-required.pkgs``. Both files are on a tmpfs, so the reboot removes them. A reboot takes every service on the host away for a few minutes, which is why nothing does it unattended; the "Reboot pending" alert says when one has waited for three days. Kernel updates come about once a month. Pick a time when few people use the services, and reboot: .. code-block:: sh cat /run/reboot-required.pkgs systemctl reboot When the host is back, systemd has started the containers in their usual order: .. code-block:: sh uname -r systemctl list-units 'ae-*' --state=failed podman ps ``uname -r`` names the new kernel, no unit is failed, and ``podman ps`` lists the containers again. The reboot also starts PostgreSQL on the image the ``postgres`` role pulled last. "Reboot pending" resolves a few minutes after the boot, once the update metrics have run. Seeing what is waiting ---------------------- Two timers write what is pending into node-exporter's textfile collector (``/ae/node-exporter/textfile/``), and Grafana alerts on it. The mails go to the addresses in ``ae_grafana_alert_addresses`` (see :doc:`becoming-an-admin`); the alert rules page in Grafana shows the current state of every rule. ``ae-update-metrics``, from the ``unattended-upgrades`` role Runs hourly, two minutes after a boot, and right after every ``apt-daily`` and ``apt-daily-upgrade`` run, and writes ``ae-updates.prom``: whether a reboot is pending and since when, the pending upgrades with the security ones counted apart, the age of apt's copy of the Debian security index, and how many unattended-upgrades runs in a row have failed. It never takes apt's lock and never runs ``apt-get update``. ``ae-image-update-check``, from the ``podman`` role Runs hourly and compares the image of every running container that came from a registry - including containers that no role manages - with what its tag points at in the registry now, and writes ``ae-image-updates.prom``. It asks with anonymous HEAD requests, asks about each tag once per UTC day and again after a container of that tag was restarted, and never pulls. Images built on the host are not checked. The alert rules on these metrics: .. list-table:: :header-rows: 1 :widths: 30 70 * - Alert - Fires when * - Reboot pending - a reboot was first asked for more than 3 days ago * - Security updates pending - security updates have been pending for more than 2 days without a break * - Unattended upgrades failing - the last two runs of unattended-upgrades, or more, logged an error * - Package lists stale - apt's copy of the Debian security index is more than 3 days old, for 2 hours * - Container image outdated - the tag of a running container has pointed at another image for more than 7 days * - Container image check failing - the registry has not answered for a tag for more than 3 days A deployment that lists ``unattended-upgrades`` or ``podman`` in ``ae_disabled_roles`` gets none of that role's rules. On the host the same information is one command away: .. code-block:: sh cat /ae/node-exporter/textfile/ae-updates.prom cat /ae/node-exporter/textfile/ae-image-updates.prom apt list --upgradable What no alert covers: * A new release of a pinned image. The image check compares a container with its own tag, and ``34.0.4-fpm`` does not move when ``34.0.5-fpm`` appears. Somebody has to follow the releases and security announcements of the software in the stack. * The packages inside the images built on the host. They are as current as the last run of their role. * Updates from ``-updates``. They are counted (``ae_apt_upgrades_pending{origin="other"}``), but no rule looks at them. Going ahead or asking first --------------------------- These rules are there so that a routine update does not wait for the one person who usually does it, and a risky one does not happen by accident. Go ahead A rebuilt image under a tag that already runs, a point release of a floating tag, a rebuild of the images built on the host, and a patch release of a pinned image (Caddy ``2.11.7`` to ``2.11.9``, Nextcloud ``34.0.4`` to ``34.0.5``). Security fixes usually are of this kind. Follow the procedure below and tell the other admins afterwards. Read the release notes first A minor release of a pinned image (Grafana ``13.2`` to ``13.3``, Prometheus ``v3.15`` to ``v3.16``). Go ahead when the notes name no breaking change, no change to the configuration and no migration to run by hand; otherwise treat it as a major release. A project that is still at ``0.x``, like lldap, can break things in a minor release, so treat those as major releases too. Ask first A major release (Nextcloud ``34`` to ``35``, a new Roundcube branch, a new PostgreSQL or Redis major), anything that migrates a database, and a new Debian or Alpine release, for the host or for the images built on it. Agree on it with the other admins, take a backup and a snapshot, and pick a time when somebody can watch it through. Many of these cannot be undone except from the backup. The comment above a version variable says what moving it involves; read it before changing the value. At the time of writing: * ``ae_nextcloud_version`` in ``ansible/group_vars/all.yml`` has to match or be newer than the installed version. The image refuses to downgrade and to skip a major, so a host several majors behind moves one major at a time. Keep it on the latest patch release, for the reason in the example below. * ``ae_roundcube_version``: a new branch is a one-way upgrade. On start the image copies the new release over the web volume and migrates the database schema in place; going back means restoring both. * ``ae_postgres_version``: a new major does not migrate the data, the server refuses to start on it. ``upgrade-postgres.yml`` does the migration; its header describes the run. * ``ae_lldap_version``: the database schema is migrated on start, so only ever move it forward. * ``ae_prometheus_version``: Prometheus 3 reads the data of 2.x, but cannot go back below 2.55 once it has written to it. * ``ae_redis_version``: newer servers read the dump files of older ones, not the other way round. .. _updates-procedure: Rolling out a change -------------------- Every deployment runs from a clone of its own. Commit a version bump in the clone you work in, one variable per commit (the subject is the role and the new version, ``caddy: 2.11.9``), and push it. Then, in the deployment's clone: 1. Bring the clone up to date. .. code-block:: sh git status --short git pull --ff-only git submodule update --init --recursive cd ansible make collections ``git status`` must show nothing: the files of the deployment are all ignored by git, and a deployment clone has no changes of its own. ``make collections`` is only needed when ``requirements.yml`` changed. 2. Run the role in check mode, with a diff. .. code-block:: sh ansible-playbook -i hosts.ini setup.yml --check --diff --tags nextcloud