Skip to content
How
Preparing a CI host

Preparing a CI host

Commands to run once per machine

A self-hosted runner is the same machine on the next job. Everything a build leaves behind is still there tomorrow, and the commands below are what a host needs before anybody points a workflow at it:

sudo ./<product>.sh support ci-privileges <user>     # si#92
sudo ./<product>.sh support ci-disk-hygiene          # si#327
sudo ./<product>.sh support ci-arm64                 # si#358, only where a product builds linux/arm64

All of them need root, all are idempotent, and all refuse with a message that names the cure rather than failing quietly. None is placed by the catalogue: a product that never provisions a CI host should not find commands in its CLI that change who may become root or restart a docker engine.

Why the disk one exists

This platform’s own CI died of a full disk, and the way it died is the argument for the command:

E: You don't have enough free space in /var/cache/apt/archives/

Eight minutes into a docker build, with every gate before it green. On a second run of the same commit the step ended with conclusion: null, no log at all, and the runner went offline. Neither text mentions a disk. The machine had 64 GB in /var/lib/docker against a ZFS refquota of the same size — so free space on the pool bought nothing, and the container’s own df was the only place the truth was visible.

Three things fill a runner, and ci-disk-hygiene answers each one:

what grows what stops it
container logs, unbounded under the default json-file driver log-opts: max-size 50m, max-file 3
the build cache, never reclaimed unless asked builder.gc with a 10 GB ceiling — the engine keeps itself in check, no cron needed
images and stopped containers, per run a daily simplon-docker-prune.timer pruning anything older than 48h

It merges into /etc/docker/daemon.json and never replaces it. That file is where a host’s data-root, registry-mirrors and insecure-registries live; a command that wrote a fresh document carrying only its own four settings would take a mirror away from a machine that needs one, and the symptom would appear on the next build, nowhere near the cause. A file it cannot parse is a refusal, not a reason to start fresh.

It restarts the engine only when the document actually moved. systemctl restart docker kills every running container — on a runner, including the job that called the command. A second run on a configured host therefore touches nothing.

Look before you apply, which is what -n is for on a fleet:

sudo ./<product>.sh support ci-disk-hygiene -n

linux/arm64 on an amd64 runner

A multi-platform image (si#347) that RUNs anything in its arm64 stages needs an emulator on the runner. Without one the build fails a minute in with exec format error. support ci-arm64 checks first and installs only when needed:

  1. systemd-detect-virt decides the recipe. A VM or bare metal gets qemu-user-binfmt, which registers the emulator through systemd-binfmt at every boot. An lxc container gets a boot-time script and a unit ordered before docker. In an LXC container tonistiigi/binfmt --install is refused with permission denied, so the script registers qemu-aarch64 in the container’s own binfmt_misc. The interpreter is copied out of the same pinned tonistiigi/binfmt image. The recipe is firn’s, measured in firn#945. Any other answer is refused by name, and nothing is changed.
  2. The answer is asked of the simplon builder, the one a multi-platform build uses. A builder created before the emulator was registered does not see it, so the command drops it with docker buildx rm simplon and lets it be created again.
  3. Three outcomes, each with its own text: already set up (nothing installed), set up (this run changed the host or only renewed the builder), or red, when the builder still does not list linux/arm64.
./<product>.sh support ci-arm64 -n     # which recipe this host takes, and what would run; needs no root
sudo ./<product>.sh support ci-arm64
docker buildx ls                       # the simplon builder lists linux/arm64

The two halves that run inside a job

./<product>.sh support ci-disk-preflight    # before the job's own steps
./<product>.sh support ci-disk-cleanup      # after them, whatever they decided

Neither needs a privilege. The preflight reads df — not docker, so it works on a runner whose engine is installed inside the job — and refuses below 15% free, which is the same line as “85% used”. A machine that cannot finish the work says so in one second instead of eight minutes, with the disk named. A disk it could not measure is reported rather than passed over as a healthy one, and does not fail the job: a preflight that blocked every build because df changed its output would cost more than the defect it guards.

The cleanup prunes build cache older than a day. There is an age filter because an unfiltered prune on every run would trade a full disk for a cold build every time, and there is no --volumes anywhere, because a runner with a persistent volume would lose it and the loss would look like a bug somewhere else.

A generated workflow places both for you, when the job’s runner kind says the disk survives it:

jobs:
  build:
    runner: { kind: self-hosted-debian, labels: <your-runner> }

github-ubuntu gets neither, because that machine is destroyed after every job and cannot have the problem. A job that writes runs-on: itself gets neither either — that spelling says the machine is mine, and the kernel has no table entry to reason from. If the two coordinates are not placed in the command tree, the generated file says so in a comment naming what to place: a step calling a command that does not exist would fail on the runner with the manifest looking correct.

The preflight stands after the checkout, and that is a limit rather than a preference. It is one of the product’s own commands, and a command needs the checkout it lives in. A checkout is cheap; what the preflight buys is every step after it.

Can the kernel run a container at all (si#623)

./<product>.sh support ci-docker-preflight   # first, before the disk preflight

It runs the kernel’s pinned busybox with docker run --rm from where the kernel uses docker: inside the kernel container through the mounted socket on the container route, on the host on the venv route. Green only when that container ran; docker version answering is not enough, because a daemon can answer and still refuse the caller. On 2026-11-11 a runner update on ghr-8 left every docker call refused with permission denied ... /var/run/docker.sock while the disk preflight stayed green.

A refusal prints docker’s own line, then the facts it is diagnosed from: the uid, gid and groups the kernel runs as, the socket’s uid, gid and mode, the gids --group-add handed the kernel container (or none on the venv route), and the way out - the docker group and a runner restart for a host runner, 0660 for a socket no group can write, the launcher’s --group-add for a container that did not get the socket’s gid.

A generated workflow places it on the same jobs as the disk pair, as their first step, when the product has placed support:ci-docker-preflight; otherwise the file says what to place. It is placed on its own, so a product that placed only the disk pair keeps both of those.

What a cancelled job left running (si#756)

A cancelled job does not stop every container it started. The kernel stops its containers on SIGINT and SIGTERM, but the runner’s SIGKILL a few seconds into a cancel reaches no handler, and on a machine that survives the job the container runs on into the next job’s checkout. firn measured a gradle check container still running after the whole cancel sequence (si#409).

So every generated job starts with a step that removes them, ahead of its checkout. The product writes nothing for it. It cannot be one of the product’s commands, because it has to run before the checkout those commands live in, so it is a short shell step the kernel writes into the file.

  • What it removes: a container that carries simplon.run=<product>, the label the kernel puts on every container it starts, and has a bind mount inside this job’s workspace. The runner runs one job at a time, so such a container is an orphan. A container of another checkout or of a developer’s gate on the same daemon mounts something else and is left alone. A mount given through a symlink is not matched.
  • Where it runs: if: runner.environment != 'github-hosted' && runner.os != 'Windows'. It does not matter whether the job names its machine with runner: or runs-on:: GitHub says at run time whether the machine outlives the job. A GitHub-hosted machine is destroyed after every job, so the step is skipped there. A runner too old to set runner.environment runs it.
  • What it says: each orphan by name and image, then N orphaned container(s) removed, which is 0 on a clean machine. With no docker client yet, or a daemon docker ps cannot reach, it prints a warning and lets the job go on: the job’s own first docker step meets the same daemon and says why. An orphan that is still there after docker rm --force fails the step, because it would be writing into this job’s checkout. The step has a 5-minute limit.

Verifying it

docker system df          # before and after - `ci-disk-hygiene` prints both itself
df -h /var/lib/docker
systemctl list-timers simplon-docker-prune.timer

Warning before it hurts, one level up

The preflight refuses at 15% free, which is late by design — it is the last line, not the first. The first line belongs on the host that runs the containers, because a container cannot see the pool it is quota’d out of: df inside it reports the quota, which is right for the preflight and useless for “which of my machines is about to break”.

deploy/ci-hosts/ in this repository carries that sweep as a shell script and a systemd timer for a Proxmox host: it walks the runner containers with pct, reports any whose root filesystem is over 80% used, and exits non-zero so that whatever already watches failed units is the alert channel. It is deliberately not a simplon command and deliberately does not prune: a threshold that pages somebody depends on who is on call, and a script that quietly repaired the symptom would hide a runner that fills up every day from the person who needs to know it does.

Refuse to start, and alert, when the runner cannot run a container

On 2026-11-11 a runner update on ghr-8 left the runner’s user unable to use the docker socket. The runner kept taking jobs, and each one went red about thirty steps in, on symptoms. deploy/ci-hosts/ carries the host-side check for it (si#624). It runs on the runner machine, not on the Proxmox host, because the question is what the runner’s own user may do with that machine’s socket. It is green only when a container ran: docker run --rm --network none of the kernel’s pinned busybox. A daemon that answers docker version can still refuse the caller.

Two ways in, one script:

  • runner-docker-check.conf, a drop-in for the runner’s unit. Its ExecStartPre= runs the script with --self as the unit’s User=, with the groups the runner is about to start with, so the unit refuses to start and systemctl status says why.
  • runner-docker-check.timer, every 15 minutes, because the runner updates itself without restarting through systemd and ExecStartPre= never sees what an update changed. As root, it reads the credentials of every running actions.runner.* unit’s main process from /proc/<pid>/status - the groups the process has now, not what /etc/group says, since a group is inherited at process start - and runs the container with exactly those. A failed runner-docker-check.service is the alert, as with runner-disk-alert. No running runner unit is also a failure: nothing was checked, and that is not a healthy machine.

A refusal prints docker’s own line, who was checked (uid, gid, groups), the socket’s owner, group and mode, and the way out: the socket’s group for the runner’s user and a restart of the runner, or SocketMode=0660 for a socket no group can write.

Install, on the runner machine, as root:

install -m 0755 deploy/ci-hosts/runner-docker-check.sh /usr/local/sbin/
unit=$(systemctl list-units --type=service --no-legend --plain 'actions.runner.*' | awk '{ print $1 }')
mkdir -p "/etc/systemd/system/$unit.d"
install -m 0644 deploy/ci-hosts/runner-docker-check.conf "/etc/systemd/system/$unit.d/"
install -m 0644 deploy/ci-hosts/runner-docker-check.service deploy/ci-hosts/runner-docker-check.timer \
    /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now runner-docker-check.timer

unit must name exactly one unit; on a machine with several runners, install the drop-in once per unit.

Verify:

systemctl cat "$unit" | grep ExecStartPre      # the drop-in is read
systemctl restart "$unit"; systemctl status "$unit"    # active, and the journal shows `ok ... ran a container`
systemctl start runner-docker-check.service; systemctl status runner-docker-check.service
systemctl list-timers runner-docker-check.timer

To see it red without touching the runner, run the check as a user without the socket’s group:

setpriv --reuid 65534 --regid 65534 --clear-groups /usr/local/sbin/runner-docker-check.sh --self; echo rc=$?

It prints ALERT ... could not run a container, docker’s permission denied, the socket line and the way out, and rc=1.