Skip to content

GitHub Actions self-hosted runners

Self-hosted GitHub Actions runners on the homelab LAN, so workflows can reach the private 192.168.1.x network (the k3s cluster and Home Assistant) that GitHub-hosted runners cannot.

Runners come in two lanes:

  • LXC containers are the default. Ordinary CI runs in an unprivileged Ubuntu 24.04 LXC, one runner per container, addressed by DHCP. This is where a new runner goes unless the job needs Docker.
  • The gh-runner-01 VM is for Docker. A VM hosts the runners whose jobs build or run containers, because Docker belongs in a VM rather than an unprivileged LXC. The VM hosts multiple runner services, each its own systemd unit.

Runner sets and labels

Runner set Lane Scope Labels Docker
nocterra-N LXC the nocterra repo self-hosted, linux, godot no
faxme-N LXC org-wide self-hosted, linux, faxme no
cm-ci-N gh-runner-01 VM org-wide self-hosted, cm-ci yes (daemon on the VM)

Deployed now: three nocterra-N LXC runners — nocterra-0, nocterra-1, nocterra-2 on CTIDs 210-212 (4 vCPU / 8 GB / 40 GB each), dedicated to the nocterra repo — and three faxme-N org-wide LXC runners, faxme-1, faxme-2, faxme-3 on CTIDs 221-223. The two sets differ in the registration URL (the nocterra repo vs the org), the labels, and the toolchain: nocterra runs the Godot/Linux CI toolchain, faxme runs the claude-manager toolchain without Docker (see below). To change the toolchain on an already-running container, re-run its toolchain script into it with pct exec (idempotent) rather than reprovisioning.

The two LXC sets run different toolchains: nocterra-N get the Godot/Linux CI toolchain (install-linux-ci-tools.sh), while faxme-N run claude-manager CI and so get the claude-manager toolchain (install-cm-ci-tools.sh with WITH_DOCKER=0) — the same tools as the Docker VM minus Docker, since Docker jobs belong on the VM. The deploy wrapper selects it with TOOLCHAIN=cm (see below). GitHub adds an implicit Linux label to every self-hosted runner, so a bare runs-on: [self-hosted, linux] is not lane-specific — it can land on any Linux runner, the Docker VM included. Always name the lane's distinguishing custom label: cm-ci for the Docker VM, godot for the nocterra runners, faxme for the org-wide pool.

Registration

  • faxme-N and cm-ci-N register at the organisation level — Organization → Settings → Actions → Runners → New self-hosted runner, so every repo in the org can use them. Org runners live in a runner group (the Default group unless you make another); make sure that group's repository-access policy covers the repos that should reach them.
  • nocterra-N register against the nocterra repo — that repo's Settings → Actions → Runners → New self-hosted runner, so they only serve nocterra.

Either way you generate the registration token (expires after ~1 h) in the GitHub UI as owner — no org API token is needed, so none of this depends on org-scoped access beyond your own account.

Keep the registration token off the wire

The token expires after ~1 h, so exposure is bounded — but it still lands on a command line (the ssh / pct exec / sudo bash -s -- … <token> arguments), in the host's process table, and in sudo/journal logs while config.sh runs. Anyone who can read those within the hour could register a rogue runner. Use a fresh token per runner, let it expire once the runner shows online, and clear it from your shell history (set +o history).

The Home Assistant deploy runner

The Home Assistant deploy workflow targets a runner labelled homelab, deploy (it needs LAN access to the cluster). That is a separate runner from the three sets above; register one the same way — an LXC (no Docker needed) or the VM — with homelab,deploy as its labels.

Tool inventory

What each toolchain script installs. Godot, the .NET SDK, Python 3.12 and Trivy are downloaded by the workflows at job time — deliberately not baked in — so they are not listed here.

Godot / Linux CI (install-linux-ci-tools.sh) — the nocterra LXC runners

  • Base: git, curl, wget, unzip, zip, tar, xz-utils, jq, ca-certificates
  • .NET runtime libs: ICU and libssl3 (the ICU package name tracks the distro — the script picks libicu74 on Ubuntu 24.04, libicu72 on Debian 12)
  • python3, python3-venv, python3-pip
  • Headless graphics for Godot screenshots: xvfb, libgl1, libgl1-mesa-dri, mesa-vulkan-drivers, libvulkan1, libfontconfig1, libxcursor1, libxinerama1, libxrandr2, libxi6, libxkbcommon0, ALSA (libasound2t64 on Ubuntu 24.04 / libasound2 on Debian 12), libpulse0
  • GitHub CLI (gh)
  • Node.js 22 LTS (npm, npx) — via NodeSource, same as the Docker VM toolchain

claude-manager CI (install-cm-ci-tools.sh) — the Docker VM and the faxme LXC runners

The same script serves both lanes; WITH_DOCKER=0 drops only the Docker engine install and the github-runner-in-docker-group step for the faxme LXC runners (Docker jobs run on the VM). The build-essential + python3 base is what builds better-sqlite3's native module during npm ci.

  • Base: git, curl, wget, jq, openssl, ca-certificates, build-essential, python3
  • Node.js 22 LTS (npm, npx)
  • PowerShell 7 (pwsh), with Pester 5+ and PSScriptAnalyzer installed AllUsers; ScriptBlock logging disabled to cut journal noise
  • markdownlint-cli2 pinned to 0.23.3 (global npm)
  • gitleaks 8.30.1, trufflehog 3.99.0, zizmor (pinned in the script)
  • squid — installed, service disabled and stopped (provides /usr/lib/squid/basic_ncsa_auth for the proxy-credential test)
  • Docker engine (WITH_DOCKER=1, the VM only) — daemon enabled; the github-runner service user is in the docker group, so jobs use Docker without sudo. Skipped on the faxme LXC runners.
  • semgrep is intentionally not installed

Why the Linux CI script is distro-aware

Ubuntu 24.04's time64 transition renamed libasound2 to libasound2t64, and the ICU soname tracks the release. The script picks whichever name apt offers, so the same script works whether the container is Ubuntu 24.04 or a Debian base.

Prerequisites

  • SSH access as root to pve01 — every provision script is streamed there over SSH (bash -s) and drives pct/qm; nothing is copied onto the host.
  • The public keys to inject placed in /root/.ssh/authorized_keys on pve01 (the VM provisioner injects them).

Default lane: Ubuntu 24.04 LXC runners

One unprivileged container per runner, addressed by DHCP. The deployed set is three nocterra-N runners (Godot/Linux CI toolchain) and three faxme-N runners (claude-manager toolchain, no Docker):

CTID Name vCPU RAM Disk Toolchain
210 nocterra-0 4 8 GB 40 GB Godot/Linux CI
211 nocterra-1 4 8 GB 40 GB Godot/Linux CI
212 nocterra-2 4 8 GB 40 GB Godot/Linux CI
221 faxme-1 4 8 GB 40 GB claude-manager (no Docker)
222 faxme-2 4 8 GB 40 GB claude-manager (no Docker)
223 faxme-3 4 8 GB 40 GB claude-manager (no Docker)

Open: faxme-2 and faxme-3 run out of memory

Containers 222 (faxme-2) and 223 (faxme-3) have hit their 8 GB memory limit repeatedly since Oct 19. This is unresolved.

Add more the same way — a fresh container id and name each time. Name a runner for its purpose: nocterra-N for runners dedicated to the nocterra repo, or faxme-N for org-wide runners.

Deploy in one command

deploy-lxc-runner.sh runs the whole lane from your workstation — template, container, toolchain, runner, registration — streaming each sub-script to pve01 over SSH. Grab a registration token (expires after ~1 h) first (from the org for a faxme runner, from the nocterra repo for a nocterra runner).

# nocterra-dedicated runner (the deployed set — nocterra-0..2 on CTIDs 210-212):
./deploy-lxc-runner.sh 210 nocterra-0 https://github.com/Fax-Me-In-The-Cloud/nocterra <TOKEN> linux,godot

# or an org-wide faxme runner (org URL, labels linux,faxme, claude-manager toolchain
# without Docker) named faxme-N -- note the TOOLCHAIN=cm selector:
TOOLCHAIN=cm ./deploy-lxc-runner.sh 221 faxme-1 https://github.com/Fax-Me-In-The-Cloud <TOKEN> linux,faxme

Container id, name, URL and token are required; labels default to linux, and cores/RAM/disk default to the Linux CI profile's 4 / 8192 / 40. Repeat with a fresh id, name and token for each runner.

deploy-lxc-runner.sh
#!/usr/bin/env bash
# deploy-lxc-runner.sh -- stand up ONE LXC CI runner end to end.
#
# Run on your workstation, from this folder (it streams each sibling script to
# pve01 over SSH; nothing is copied onto the host). Chains the whole LXC lane:
# ensure template -> provision container (DHCP) -> Linux CI toolchain -> runner -> register.
#
#   Usage: ./deploy-lxc-runner.sh <ctid> <name> <url> <token> [labels] [cores] [mem_mb] [disk_gb]
#     ctid    container id, e.g. 210
#     name    runner name + CT hostname. Name it for its purpose: faxme-1 for an
#             org-wide runner, nocterra-1 for a runner dedicated to the nocterra repo.
#     url     org URL for an org-wide runner (https://github.com/Fax-Me-In-The-Cloud),
#             or a repo URL to dedicate it to one repo
#             (https://github.com/Fax-Me-In-The-Cloud/nocterra).
#     token   registration token (expires ~1 h) from that org's or repo's Settings ->
#             Actions -> Runners -> New self-hosted runner. Fresh one per runner.
#     labels  optional, default "linux". Use "linux,godot" for the nocterra runners,
#             or "linux,faxme" for the org-wide faxme runners.
#     cores/mem_mb/disk_gb  optional, default 4 / 8192 / 40 (the Linux CI profile minimum)
#
# Toolchain (TOOLCHAIN env, default "linux"):
#   linux  Godot/Linux CI toolchain (install-linux-ci-tools.sh) -- the nocterra runners.
#   cm     claude-manager CI toolchain (install-cm-ci-tools.sh, Docker-less) -- the faxme
#          runners. Same tools as the gh-runner-01 VM minus Docker (Docker jobs run on the VM).
#
# Env overrides: PVE (default root@192.168.1.4), TOOLCHAIN (default linux).
set -euo pipefail

PVE="${PVE:-root@192.168.1.4}"
TOOLCHAIN="${TOOLCHAIN:-linux}"
case "$TOOLCHAIN" in
  linux|cm) ;;
  *) echo "TOOLCHAIN must be 'linux' (Godot/nocterra) or 'cm' (claude-manager/faxme), not '$TOOLCHAIN'." >&2; exit 1 ;;
esac
CTID="${1:?ctid}"; NAME="${2:?name}"; URL="${3:?url}"; TOKEN="${4:?registration token}"
LABELS="${5:-linux}"; CORES="${6:-4}"; MEM="${7:-8192}"; DISK="${8:-40}"
here="$(cd "$(dirname "$0")" && pwd)"

echo "==> [1/5] ensure the Ubuntu 24.04 template on pve01"
ssh "$PVE" 'TEMPLATE_PREFIX=ubuntu-24.04-standard bash -s' < "$here/fetch-lxc-template.sh"

echo "==> [2/5] provision LXC $CTID ($NAME), DHCP, ${CORES}c/${MEM}MiB/${DISK}G"
ssh "$PVE" "bash -s -- $CTID $NAME $CORES $MEM $DISK" < "$here/provision-runner-lxc.sh"

echo "==> wait for the container to get network"
ready=0
for _ in $(seq 1 30); do
  if ssh "$PVE" "pct exec $CTID -- getent hosts github.com" >/dev/null 2>&1; then ready=1; break; fi
  sleep 2
done
[ "$ready" = 1 ] || { echo "CT $CTID has no network after ~60s (DHCP/DNS?). Fix networking and re-run." >&2; exit 1; }

echo "==> [3/5] install the $TOOLCHAIN toolchain"
if [ "$TOOLCHAIN" = "cm" ]; then
  # faxme lane: claude-manager CI toolchain, no Docker (Docker jobs run on the VM).
  ssh "$PVE" "pct exec $CTID -- env WITH_DOCKER=0 bash -s" < "$here/install-cm-ci-tools.sh"
else
  # nocterra lane: Godot/Linux CI toolchain.
  ssh "$PVE" "pct exec $CTID -- bash -s" < "$here/install-linux-ci-tools.sh"
fi

echo "==> [4/5] lay down the runner software"
ssh "$PVE" "pct exec $CTID -- bash -s" < "$here/setup-runner.sh"

echo "==> [5/5] register '$NAME' against $URL (labels: $LABELS)"
ssh "$PVE" "pct exec $CTID -- bash -s -- $NAME $URL $TOKEN $LABELS" < "$here/register-runner.sh"

echo
echo "Done. Verify:  ssh $PVE \"pct exec $CTID -- systemctl list-units 'actions.runner.*'\""

The steps it chains, to run by hand or to understand what it does:

Fetch the Ubuntu template (once)

ssh root@192.168.1.4 'TEMPLATE_PREFIX=ubuntu-24.04-standard bash -s' < fetch-lxc-template.sh
fetch-lxc-template.sh
#!/usr/bin/env bash
# Ensure an LXC template is in the Proxmox template store. Run first, as root on
# pve01, before provisioning any container. Downloads only if a matching template
# is not already present -- every container reuses it, so the provision script
# never downloads.
#
# Defaults to the Debian 12 template the game servers use. Override the prefix for
# other containers, e.g. the Ubuntu 24.04 runner LXC:
#   TEMPLATE_PREFIX=ubuntu-24.04-standard ./fetch-lxc-template.sh
set -euo pipefail

STORE="${STORE:-local}"                         # 'local' holds vztmpl content on this node
PREFIX="${TEMPLATE_PREFIX:-debian-12-standard}" # template family to ensure

pveam update

if pveam list "$STORE" | grep -qF "$PREFIX"; then
  echo "Template already present:"
  pveam list "$STORE" | grep -F "$PREFIX"
  exit 0
fi

# Pick the newest matching template the mirror offers (name carries the point
# release, e.g. debian-12-standard_12.7-1_amd64.tar.zst).
tmpl="$(pveam available --section system | awk -v p="$PREFIX" 'index($0,p){print $2}' | sort -V | tail -1)"
[ -n "$tmpl" ] || { echo "No $PREFIX template offered by 'pveam available'." >&2; exit 1; }

echo "Downloading $tmpl to $STORE"
pveam download "$STORE" "$tmpl"

Provision a container

Arguments are ctid hostname cores mem_mb disk_gb. The Linux CI profile wants 4+ cores, 8+ GB RAM, 40+ GB disk. The container takes its address via DHCP, so pick only a free container id — the script prints the leased IP when it finishes.

ssh root@192.168.1.4 'bash -s -- 210 nocterra-0 4 8192 40' < provision-runner-lxc.sh
provision-runner-lxc.sh
#!/usr/bin/env bash
# Create ONE unprivileged LXC container to host a GitHub Actions runner on pve01.
# Run as root on pve01. The container gets its address via DHCP (no fixed IPs to
# assign or track for the fleet). One parameterised provisioner per runner
# container -- the lane's toolchain is installed afterwards (install-linux-ci-tools.sh
# for nocterra, or install-cm-ci-tools.sh with WITH_DOCKER=0 for faxme) and the runner
# with setup-runner.sh + register-runner.sh, all via `pct exec`.
#
#   Usage: ./provision-runner-lxc.sh <ctid> <hostname> <cores> <mem_mb> <disk_gb> [swap_mb]
#     ctid      container id, e.g. 210
#     hostname  name it for its purpose, e.g. faxme-1 (org-wide) or nocterra-1
#     cores     vCPU count (the Linux CI profile wants 4+)
#     mem_mb    RAM limit in MiB (the Linux CI profile wants 8192+)
#     disk_gb   rootfs size in GiB on local-lvm (the Linux CI profile wants 40+)
#     swap_mb   optional swap in MiB (default 512)
#
# Overridable via env: BRIDGE (vmbr0), STORAGE (local-lvm), STORE (local, the
#   template store), TEMPLATE (auto-detected newest ubuntu-24.04-standard in STORE).
set -euo pipefail

if [ "$(id -u)" -ne 0 ]; then echo "Run as root on pve01." >&2; exit 1; fi

CTID="${1:?ctid}"; HOSTNAME="${2:?hostname}"
CORES="${3:?cores}"; MEM="${4:?mem_mb}"; DISK="${5:?disk_gb}"; SWAP="${6:-512}"

BRIDGE="${BRIDGE:-vmbr0}"; STORAGE="${STORAGE:-local-lvm}"; STORE="${STORE:-local}"

# Idempotent, but identity-guarded: a re-run with the same ctid+name is a no-op,
# but a ctid that already belongs to a DIFFERENT container (e.g. a typo that hits
# a game server) is refused -- so we never install a runner into the wrong CT.
if pct status "$CTID" >/dev/null 2>&1; then
  existing="$(pct config "$CTID" 2>/dev/null | awk -F': ' '/^hostname:/{print $2}')"
  if [ "$existing" = "$HOSTNAME" ]; then
    # same ctid+name: a prior run may have created but not started it -- ensure
    # it is running before the caller's pct-exec steps, then treat as a no-op.
    pct status "$CTID" 2>/dev/null | grep -q running || pct start "$CTID"
    echo "CT $CTID ($HOSTNAME) already exists -- ensured running, nothing else to do."; exit 0
  fi
  echo "CT $CTID already exists as '$existing', not '$HOSTNAME' -- refusing to touch it." >&2
  exit 1
fi

# Resolve the template (newest ubuntu-24.04-standard in 'local') unless pinned.
# Fetch it first with:  TEMPLATE_PREFIX=ubuntu-24.04-standard ./fetch-lxc-template.sh
TEMPLATE="${TEMPLATE:-$(pveam list "$STORE" 2>/dev/null | awk '/ubuntu-24.04-standard/{print $1}' | sort -V | tail -1)}"
[ -n "$TEMPLATE" ] || { echo "No ubuntu-24.04-standard template in 'local' -- run 'TEMPLATE_PREFIX=ubuntu-24.04-standard ./fetch-lxc-template.sh' first." >&2; exit 1; }

# Unprivileged for isolation. nesting=1 lets systemd run cleanly as the
# container's init (the runner registers as a systemd service). Docker is NOT
# needed in this lane; Docker jobs run on the VM lane instead. Address via DHCP.
pct create "$CTID" "$TEMPLATE" \
  --hostname "$HOSTNAME" \
  --cores "$CORES" --memory "$MEM" --swap "$SWAP" \
  --rootfs "${STORAGE}:${DISK}" \
  --net0 "name=eth0,bridge=${BRIDGE},ip=dhcp" \
  --unprivileged 1 \
  --features nesting=1 \
  --onboot 1

pct start "$CTID"

# Give DHCP a moment, then report the leased address for reference.
sleep 3
ip="$(pct exec "$CTID" -- ip -4 -o addr show dev eth0 2>/dev/null | awk '{print $4}' | cut -d/ -f1 || true)"
echo "CT $CTID ($HOSTNAME) created (DHCP) and started${ip:+ at $ip}."
echo "Next, from your workstation (where these scripts live):"
echo "  ssh root@192.168.1.4 'pct exec $CTID -- bash -s' < install-linux-ci-tools.sh   # nocterra/Godot"
echo "  # or faxme: ssh root@192.168.1.4 'pct exec $CTID -- env WITH_DOCKER=0 bash -s' < install-cm-ci-tools.sh"
echo "  ssh root@192.168.1.4 'pct exec $CTID -- bash -s' < setup-runner.sh"
echo "  ssh root@192.168.1.4 'pct exec $CTID -- bash -s -- <NAME> <URL> <TOKEN> <LABELS>' < register-runner.sh"

Install the toolchain and a runner into it

Everything inside the container runs via pct exec, driven from your workstation — the ssh root@192.168.1.4 '…' < script form streams each local script to pve01. Install the lane's toolchain, lay down the runner distribution, then register with a fresh token (it expires after ~1 h). A nocterra runner gets install-linux-ci-tools.sh and registers against the nocterra repo URL with linux,godot; a faxme runner gets install-cm-ci-tools.sh with WITH_DOCKER=0 and registers against the org URL with linux,faxme.

# nocterra (Godot/Linux CI toolchain):
ssh root@192.168.1.4 'pct exec 210 -- bash -s' < install-linux-ci-tools.sh
# faxme instead (claude-manager toolchain, no Docker):
#   ssh root@192.168.1.4 'pct exec 221 -- env WITH_DOCKER=0 bash -s' < install-cm-ci-tools.sh
ssh root@192.168.1.4 'pct exec 210 -- bash -s' < setup-runner.sh
ssh root@192.168.1.4 'pct exec 210 -- bash -s -- nocterra-0 https://github.com/Fax-Me-In-The-Cloud/nocterra <TOKEN> linux,godot' < register-runner.sh

Update the toolchain on a running runner (no reprovision)

The toolchain scripts are idempotent, so to refresh or change what an already-running container carries, stream the script into it with pct exec — no new container, no re-registration. For the faxme runners (claude-manager toolchain, no Docker) on CTIDs 221-223:

for id in 221 222 223; do
  ssh root@192.168.1.4 "pct exec $id -- env WITH_DOCKER=0 bash -s" < install-cm-ci-tools.sh
done

No runner restart is needed for a toolchain refresh. The tools install into standard PATH directories already in the runner service's environment, so a running runner picks them up on its next job. Do not add a blanket systemctl restart after a refresh — it interrupts any job in flight for no benefit. A restart is only needed when a change needs a fresh process session, notably the docker-group membership on the VM lane (see the VM lane); the Docker-less faxme and nocterra LXC runners never need one.

For the nocterra runners, refresh the toolchain by streaming install-linux-ci-tools.sh the same way into CTIDs 210-212.

install-linux-ci-tools.sh
#!/usr/bin/env bash
# install-linux-ci-tools.sh -- the Godot/Linux CI toolchain for a nocterra LXC runner.
# This is the nocterra lane only (headless-Godot graphics libs + gh + Node). The
# org-wide faxme runners run claude-manager CI, so they use install-cm-ci-tools.sh
# with WITH_DOCKER=0 instead -- a different toolchain, not this one. Distro-aware
# (picks the right package names on Ubuntu 24.04 or Debian), so it runs unchanged
# in the runner LXC.
#   In an LXC:   ssh root@192.168.1.4 'pct exec <ctid> -- bash -s' < install-linux-ci-tools.sh
# Idempotent: apt installs are safe to re-run.
#
# Godot itself, the .NET SDK, Python 3.12 and Trivy are downloaded by the
# workflows at job time -- deliberately NOT installed here. xvfb provides the
# virtual screen Godot needs for headless screenshots.
set -euo pipefail

if [ "$(id -u)" -ne 0 ]; then echo "Run as root (sudo)." >&2; exit 1; fi
export DEBIAN_FRONTEND=noninteractive

apt-get update -qq

# A few runtime libs differ by distro: Ubuntu 24.04's time64 transition renamed
# libasound2 -> libasound2t64, and the ICU soname tracks the release
# (libicu74 on Ubuntu 24.04, libicu72 on Debian 12). Pick whatever apt offers.
pick() { for p in "$@"; do apt-cache show "$p" >/dev/null 2>&1 && { echo "$p"; return; }; done; echo "$1"; }
LIBICU="$(pick libicu74 libicu72 libicu70)"
LIBASOUND="$(pick libasound2t64 libasound2)"

apt-get install -y --no-install-recommends \
  git curl wget unzip zip tar xz-utils jq ca-certificates sudo \
  "$LIBICU" libssl3 \
  python3 python3-venv python3-pip \
  xvfb libgl1 libgl1-mesa-dri mesa-vulkan-drivers libvulkan1 \
  libfontconfig1 libxcursor1 libxinerama1 libxrandr2 libxi6 libxkbcommon0 \
  "$LIBASOUND" libpulse0

echo "== GitHub CLI (gh) =="
if ! command -v gh >/dev/null 2>&1; then
  install -m 0755 -d /etc/apt/keyrings
  curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
    -o /etc/apt/keyrings/githubcli-archive-keyring.gpg
  chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
  echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
    > /etc/apt/sources.list.d/github-cli.list
  apt-get update -qq
  apt-get install -y gh
fi

echo "== Node.js 22 LTS (NodeSource) =="
# NodeSource's setup script is distro-aware (Ubuntu 24.04 / Debian 12 alike), same as
# the gh-runner-01 VM toolchain (install-cm-ci-tools.sh).
if ! node --version 2>/dev/null | grep -q '^v22\.'; then
  curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
  apt-get install -y nodejs
fi

echo
echo "Linux CI toolchain ready (icu=$LIBICU, alsa=$LIBASOUND, node=$(node --version 2>/dev/null || echo none))."
echo "Docker is not installed in LXC runners; Docker jobs run on the gh-runner-01 VM."
setup-runner.sh
#!/usr/bin/env bash
#
# setup-runner.sh -- one-time preparation of a runner host (VM or LXC).
#
# Installs the GitHub Actions runner prerequisites, creates a dedicated
# non-login service user, and lays down a pristine copy of the runner
# distribution that register-runner.sh clones per runner instance. Run ONCE
# per runner host (VM or LXC), as root. Re-running is safe (idempotent).
#
# Usage:  sudo ./setup-runner.sh [RUNNER_VERSION]
#   RUNNER_VERSION  optional, e.g. 2.319.1. Defaults to the latest release.
#
set -euo pipefail

BASE=/opt/actions-runner
DIST="$BASE/_dist"
RUNNER_USER=github-runner
ARCH=x64   # host is amd64/x64 (the VM and the Ubuntu LXC alike)

if [ "$(id -u)" -ne 0 ]; then
  echo "Run as root (sudo)." >&2
  exit 1
fi

# --- resolve the runner version -----------------------------------------------
version="${1:-}"
if [ -z "$version" ]; then
  echo "Resolving latest actions-runner release..."
  version="$(curl -fsSL https://api.github.com/repos/actions/runner/releases/latest \
    | grep -oP '"tag_name":\s*"v\K[^"]+')"
fi
[ -n "$version" ] || { echo "Could not determine runner version." >&2; exit 1; }
echo "Runner version: $version"

# --- deps + service user ------------------------------------------------------
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
apt-get install -y --no-install-recommends curl git ca-certificates tar

if ! id "$RUNNER_USER" >/dev/null 2>&1; then
  echo "Creating service user $RUNNER_USER"
  useradd --system --create-home --shell /usr/sbin/nologin "$RUNNER_USER"
fi

# --- lay down the pristine runner distribution --------------------------------
mkdir -p "$DIST"
tarball="actions-runner-linux-${ARCH}-${version}.tar.gz"
if [ ! -f "$DIST/config.sh" ]; then
  echo "Downloading $tarball"
  curl -fsSL -o "/tmp/$tarball" \
    "https://github.com/actions/runner/releases/download/v${version}/${tarball}"
  tar -xzf "/tmp/$tarball" -C "$DIST"
  rm -f "/tmp/$tarball"
else
  echo "Runner distribution already present at $DIST -- skipping download."
fi

# .NET runtime prerequisites (libicu etc.). Run every time -- it is idempotent,
# so a partial first run (deps failed after the tarball extracted) self-heals on
# re-run instead of being skipped by the download guard above.
"$DIST/bin/installdependencies.sh"

chown -R "$RUNNER_USER:$RUNNER_USER" "$BASE"

echo
echo "Runner host ready. Register one or more runners with:"
echo "  sudo ./register-runner.sh <name> <url> <registration-token> [labels]"
register-runner.sh
#!/usr/bin/env bash
#
# register-runner.sh -- register ONE GitHub Actions runner instance on this host
# and install it as a systemd service. Run once per runner, as root. Because the
# host keeps a pristine copy of the runner (setup-runner.sh), you can host many
# runners side by side: just re-run this with a different <name> and a fresh
# registration token.
#
# Usage:  sudo ./register-runner.sh <name> <url> <registration-token> [labels]
#   name    unique runner name, e.g. nocterra-0 or cm-ci-1
#   url     repo or org URL, e.g. https://github.com/Fax-Me-In-The-Cloud/homelab-pages
#   token   short-lived registration token (Settings -> Actions -> Runners ->
#           New self-hosted runner). Single-use -- one fresh token per runner.
#   labels  optional extra labels (comma-separated), e.g. homelab,deploy
#
set -euo pipefail

BASE=/opt/actions-runner
DIST="$BASE/_dist"
RUNNER_USER=github-runner

if [ "$(id -u)" -ne 0 ]; then
  echo "Run as root (sudo)." >&2
  exit 1
fi

name="${1:-}"; url="${2:-}"; token="${3:-}"; labels="${4:-}"
if [ -z "$name" ] || [ -z "$url" ] || [ -z "$token" ]; then
  echo "Usage: sudo ./register-runner.sh <name> <url> <registration-token> [labels]" >&2
  exit 1
fi
if [ ! -x "$DIST/config.sh" ]; then
  echo "Runner distribution missing at $DIST. Run setup-runner.sh first." >&2
  exit 1
fi

dir="$BASE/$name"
if [ -e "$dir" ]; then
  echo "Runner directory already exists: $dir (remove it or pick another name)." >&2
  exit 1
fi

echo "Creating runner instance at $dir"
cp -a "$DIST" "$dir"
chown -R "$RUNNER_USER:$RUNNER_USER" "$dir"

# Configure as the service user (never as root). --replace lets a re-registered
# name take over cleanly; --unattended avoids prompts.
config_args=(--unattended --url "$url" --token "$token" --name "$name" --work _work --replace)
[ -n "$labels" ] && config_args+=(--labels "$labels")
sudo -u "$RUNNER_USER" bash -c "cd '$dir' && ./config.sh $(printf '%q ' "${config_args[@]}")"

# Install + start the systemd service (svc.sh must run as root; it runs the
# runner process as $RUNNER_USER).
( cd "$dir" && ./svc.sh install "$RUNNER_USER" && ./svc.sh start )

# Self-heal: the unit svc.sh generates carries no Restart=, so a runner that exits
# for any reason (a dropped GitHub connection, a crash, a kill mid-job) stays down
# until it is started by hand. Add a drop-in so systemd brings it back, and disable
# the start-rate-limit latch so a flapping runner keeps retrying instead of latching
# 'failed'. KillMode=control-group overrides the KillMode=process of the generated
# unit: with 'process', a stop or restart kills only the main process and leaves the
# runner's children running next to the freshly started listener; with the control
# group, a restart takes the whole job tree down. svc.sh records the generated unit name in "$dir/.service".
unit="$(cat "$dir/.service")"
dropin="/etc/systemd/system/${unit}.d"
mkdir -p "$dropin"
cat > "$dropin/10-self-heal.conf" <<'EOF'
[Unit]
StartLimitIntervalSec=0

[Service]
Restart=always
RestartSec=10
KillMode=control-group
EOF
systemctl daemon-reload   # applies the drop-in to the running unit; no restart needed

echo
echo "Runner '$name' registered and started (self-heal: Restart=always). Check it with:"
echo "  cd $dir && ./svc.sh status"

Register-runner arguments: <NAME> <URL> <TOKEN> <LABELS>. Tokens expire after ~1 h, so grab a fresh one per runner.

Runners restart themselves (self-heal)

register-runner.sh installs a systemd drop-in on each runner so it self-heals. The unit svc.sh generates has no Restart=, so without this a runner that exits for any reason — a dropped GitHub connection, a crash, a kill while a job runs — stays offline until it is started by hand (which has stalled jobs for a day at a time). The drop-in sets Restart=always with RestartSec=10, and StartLimitIntervalSec=0 so repeated restarts never latch the unit failed. It also sets KillMode=control-group: the unit svc.sh generates uses KillMode=process, so a stop or restart would kill only the main process and leave the runner's child processes running next to the freshly started listener, which can leave two listeners for one runner. With the control group, a restart takes the whole job tree down. A job running at that moment is killed, and it fails cleanly instead of running on beside a second listener.

[Unit]
StartLimitIntervalSec=0

[Service]
Restart=always
RestartSec=10
KillMode=control-group

Runners registered before this was added carry no such drop-in, or an older one without KillMode. Arm the ones you already have with arm-runner-self-heal.sh: it installs the drop-in on every actions.runner.* unit on a host and starts any that are currently down, leaving running ones untouched — safe to run while jobs are in flight. The new KillMode takes effect at the runner's next stop or restart, and a listener that an earlier restart already left behind stays until it is killed or the container restarts.

# faxme-1/2/3:
for id in 221 222 223; do ssh root@192.168.1.4 "pct exec $id -- bash -s" < arm-runner-self-heal.sh; done
# the VM, and the nocterra runners:
ssh debian@192.168.1.6 'sudo bash -s' < arm-runner-self-heal.sh
for id in 210 211 212; do ssh root@192.168.1.4 "pct exec $id -- bash -s" < arm-runner-self-heal.sh; done
arm-runner-self-heal.sh
#!/usr/bin/env bash
# arm-runner-self-heal.sh -- make every GitHub Actions runner service on this host
# recover on its own. The unit svc.sh generates carries no Restart=, so a runner
# that exits for any reason -- a dropped GitHub connection, a crash, a kill while a
# job runs -- stays down until it is started by hand (which has stalled jobs for a
# day at a time). This installs a systemd drop-in with Restart=always (bring it
# back on any exit) and StartLimitIntervalSec=0 (never latch 'failed' on repeated
# restarts) and KillMode=control-group (a stop or restart takes the runner's whole
# process tree down; the unit svc.sh generates has KillMode=process, which leaves
# the old children running beside the new listener) for every actions.runner.* unit
# on the host, then starts any runner that is currently down. A running runner is
# left untouched, so it is safe to run while jobs are in flight; it is idempotent.
# The new KillMode applies from the runner's next stop or restart. Run as root.
#
#   VM:     ssh debian@192.168.1.6 'sudo bash -s' < arm-runner-self-heal.sh
#   faxme:  for id in 221 222 223; do ssh root@192.168.1.4 "pct exec $id -- bash -s" < arm-runner-self-heal.sh; done
#   (same, with CTIDs 210 211 212, for the nocterra runners)
set -euo pipefail
[ "$(id -u)" -eq 0 ] || { echo "Run as root." >&2; exit 1; }

shopt -s nullglob
units=(/etc/systemd/system/actions.runner.*.service)
if [ ${#units[@]} -eq 0 ]; then
  echo "No actions.runner.* units on this host -- nothing to do."
  exit 0
fi

for path in "${units[@]}"; do
  unit="$(basename "$path")"
  dropin="/etc/systemd/system/${unit}.d"
  mkdir -p "$dropin"
  cat > "$dropin/10-self-heal.conf" <<'EOF'
[Unit]
StartLimitIntervalSec=0

[Service]
Restart=always
RestartSec=10
KillMode=control-group
EOF
  echo "armed:   $unit"
done

systemctl daemon-reload

# Bring up any runner that is currently down. Start by exact unit name: a glob
# start (systemctl start 'actions.runner.*') only acts on units systemd currently
# has in memory, which a stopped unit may not be, so it can quietly do nothing.
# Keep going if one fails to start (e.g. a hand-removed runner dir) and report at the end.
rc=0
for path in "${units[@]}"; do
  unit="$(basename "$path")"
  if systemctl is-active --quiet "$unit"; then
    echo "running: $unit (left alone)"
  else
    systemctl reset-failed "$unit" 2>/dev/null || true
    if systemctl start "$unit"; then
      echo "started: $unit -> $(systemctl is-active "$unit")"
    else
      echo "FAILED:  $unit (see: journalctl -u $unit)" >&2
      rc=1
    fi
  fi
done
exit "$rc"

Docker lane: the gh-runner-01 VM

Jobs that build or run containers go here, because Docker belongs in a VM rather than an unprivileged LXC.

Property Value
vmid / node 9001 / pve01
IP (static, cloud-init) 192.168.1.6/24, gw 192.168.1.1
CPU / RAM / disk 2 vCPU / 4 GB / 40 GB on local-lvm
OS Debian 12 (bookworm) cloud image, vmbr0

Size the VM for the number of concurrent runners

Each runner service runs one job at a time, so N services give N parallel jobs. The claude-manager CI profile calls for 4+ cores and 8+ GB RAM per concurrent runner, and jobs build Docker images — well above the VM's current 2 vCPU / 4 GB. Resize the VM (qm set 9001 --cores … --memory …, grow the disk) to match how many runners you register.

Prerequisites (VM)

  • The Debian 12 cloud image already in the Proxmox store at /var/lib/vz/template/iso/debian-12-genericcloud-amd64.qcow2 (fetch it once, below). The provision script imports it; it does not download.

Fetch the cloud image (once)

ssh root@192.168.1.4 'bash -s' < fetch-cloud-image.sh
fetch-cloud-image.sh
#!/usr/bin/env bash
# Ensure the Debian 12 cloud image is in the Proxmox store. Run first, as root on
# pve01, before provisioning. Downloads only if the image is not already there.
set -euo pipefail

IMG=/var/lib/vz/template/iso/debian-12-genericcloud-amd64.qcow2
URL=https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2

if [ -f "$IMG" ]; then
  echo "Image already present: $IMG"
  exit 0
fi

echo "Downloading $URL"
curl -fsSL -o "$IMG" "$URL"
echo "Fetched: $IMG"

Provision the VM

Imports the Debian 12 cloud image from the store, creates VMID 9001 with the runner spec (static 192.168.1.6), and starts it.

ssh root@192.168.1.4 'bash -s' < provision-gh-runner.sh
provision-gh-runner.sh
#!/usr/bin/env bash
# Create gh-runner-01 on this Proxmox host. Run as root on pve01.
set -euo pipefail

VMID=9001
IMG=/var/lib/vz/template/iso/debian-12-genericcloud-amd64.qcow2

# Idempotent: if the VM already exists, do nothing and succeed.
qm status "$VMID" >/dev/null 2>&1 && { echo "VM $VMID already exists -- nothing to do."; exit 0; }

# Fail before touching qm if the keys we inject are missing.
[ -f /root/.ssh/authorized_keys ] || { echo "Put your public key(s) in /root/.ssh/authorized_keys first." >&2; exit 1; }

# Use the cloud image already in the Proxmox store -- fetch it once beforehand
# (see gh-runner.md), don't download here.
[ -f "$IMG" ] || { echo "Cloud image not in the store: $IMG -- fetch it first (see gh-runner.md)." >&2; exit 1; }

qm create $VMID --name gh-runner-01 --memory 4096 --cores 2 --cpu host --net0 virtio,bridge=vmbr0 --scsihw virtio-scsi-single
qm set $VMID --scsi0 local-lvm:0,import-from=$IMG --ide2 local-lvm:cloudinit --boot order=scsi0 --serial0 socket --vga serial0
qm set $VMID --ciuser debian --ipconfig0 ip=192.168.1.6/24,gw=192.168.1.1 --sshkeys /root/.ssh/authorized_keys --agent enabled=1 --onboot 1
qm disk resize $VMID scsi0 40G
qm start $VMID

Prerequisites and re-running

The --sshkeys line injects /root/.ssh/authorized_keys from pve01 — make sure your public key is there first (the script fails fast if it is missing). The script is idempotent: if VMID 9001 already exists it prints a message and exits without changes. To rebuild, qm destroy 9001 first.

Install the guest agent

SSH to the VM at its static ipconfig0 address (192.168.1.6) and install the QEMU guest agent. This is a generic VM step — reuse the same script for any VM.

ssh debian@192.168.1.6 'sudo bash -s' < install-qemu-agent.sh
install-qemu-agent.sh
#!/usr/bin/env bash
# Install + enable the QEMU guest agent in a Debian/Ubuntu VM, so Proxmox can
# read the VM's IP and do graceful shutdown. Generic and reusable for ANY VM --
# not specific to the runner host. Run on the VM (via sudo).
set -euo pipefail

export DEBIAN_FRONTEND=noninteractive
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends qemu-guest-agent
sudo systemctl enable --now qemu-guest-agent
echo "qemu-guest-agent installed and running."

Why the VM shows \"Guest Agent not running\" until now

--agent enabled=1 only opens the agent channel on the Proxmox side; the Debian cloud image has no guest daemon until this step installs it. The VM is reachable the whole time at its static 192.168.1.6, which is why you can SSH in to run this before the agent is up.

Install the toolchain and register runners

With the VM up, deploy-cm-runner.sh runs the lane from your workstation — claude-manager toolchain, runner base, registration — in one command. The toolchain and runner-base steps are idempotent, so re-run with a new name and a fresh token to add each runner; pass SKIP_SETUP=1 to skip straight to registration once the VM is prepared.

./deploy-cm-runner.sh cm-ci-1 https://github.com/Fax-Me-In-The-Cloud <TOKEN>
deploy-cm-runner.sh
#!/usr/bin/env bash
# deploy-cm-runner.sh -- stand up ONE claude-manager CI runner on the gh-runner-01 VM.
#
# Run on your workstation, from this folder (it streams each sibling script to the
# VM over SSH; nothing is copied onto it). Chains the Docker lane: claude-manager
# toolchain -> runner -> register. The toolchain and runner-base steps are
# idempotent, so re-run with a new name + fresh token to add another runner; set
# SKIP_SETUP=1 to skip straight to registering when the VM is already prepared.
#
#   Usage: ./deploy-cm-runner.sh <name> <url> <token>
#     name      unique runner name, e.g. cm-ci-1
#     url       the org URL (org-wide runner), e.g. https://github.com/Fax-Me-In-The-Cloud,
#               or a single repo URL to pin the runner to one repo
#     token     registration token (expires ~1 h) from the org's (or repo's) Settings ->
#               Actions -> Runners -> New self-hosted runner. Re-run with a fresh one per runner.
#
# Env overrides: VM (default debian@192.168.1.6), SKIP_SETUP (default 0).
set -euo pipefail

VM="${VM:-debian@192.168.1.6}"
SKIP_SETUP="${SKIP_SETUP:-0}"
NAME="${1:?runner name}"; URL="${2:?url}"; TOKEN="${3:?registration token}"
here="$(cd "$(dirname "$0")" && pwd)"

if [ "$SKIP_SETUP" != "1" ]; then
  echo "==> [1/3] install the claude-manager CI toolchain (idempotent)"
  ssh "$VM" 'sudo bash -s' < "$here/install-cm-ci-tools.sh"

  echo "==> [2/3] lay down the runner software (idempotent)"
  ssh "$VM" 'sudo bash -s' < "$here/setup-runner.sh"
else
  echo "==> [1-2/3] SKIP_SETUP=1 -- assuming toolchain + runner base are already installed"
fi

echo "==> [3/3] register '$NAME' against $URL (labels: cm-ci)"
ssh "$VM" "sudo bash -s -- $NAME $URL $TOKEN cm-ci" < "$here/register-runner.sh"

echo
echo "Done. Verify:  ssh $VM \"systemctl list-units 'actions.runner.*'\""

The steps it chains, to run by hand:

ssh debian@192.168.1.6 'sudo bash -s' < install-cm-ci-tools.sh
ssh debian@192.168.1.6 'sudo bash -s' < setup-runner.sh
ssh debian@192.168.1.6 'sudo bash -s -- cm-ci-1 https://github.com/Fax-Me-In-The-Cloud <TOKEN> cm-ci' < register-runner.sh

Docker-group membership is picked up when the runner process starts, and deploy-cm-runner.sh installs the toolchain before it registers the runner, so a freshly deployed runner already has it. Only a runner that was already registered before the toolchain first ran needs a restart to join the group. Restart it when it is idle, by its exact unit name — a glob like systemctl restart 'actions.runner.*' only acts on units systemd currently has in memory, which a stopped runner may not be:

u=actions.runner.Fax-Me-In-The-Cloud.cm-ci-1.service
sudo systemctl reset-failed "$u" 2>/dev/null
sudo systemctl restart "$u"

The Docker-less faxme and nocterra LXC runners never need this.

install-cm-ci-tools.sh
#!/usr/bin/env bash
# install-cm-ci-tools.sh -- claude-manager CI toolchain for a runner host.
# Serves both lanes that run claude-manager CI, the only difference being Docker:
#   - the gh-runner-01 Docker VM (Debian 12), WITH Docker (default):
#       ssh debian@192.168.1.6 'sudo bash -s' < install-cm-ci-tools.sh
#   - the org-wide faxme LXC runners (Ubuntu 24.04), WITHOUT Docker (Docker jobs
#     belong on the VM), by setting WITH_DOCKER=0:
#       ssh root@192.168.1.4 'pct exec <ctid> -- env WITH_DOCKER=0 bash -s' < install-cm-ci-tools.sh
# Distro-aware (picks the Ubuntu 24.04 / Debian 12 Microsoft repo). Idempotent:
# re-running upgrades/repairs in place. Pinned versions are exact.
#
# Installs: git curl wget jq openssl ca-certificates build-essential python3,
# Node.js 22 LTS, PowerShell 7 (+ Pester, PSScriptAnalyzer, AllUsers scope; ScriptBlock
# logging disabled to cut pwsh's journal noise), markdownlint-cli2 (pinned),
# gitleaks/trufflehog/zizmor (pinned), squid (installed, service disabled). With
# WITH_DOCKER=1 (default) it also installs the
# Docker engine (daemon enabled; the github-runner service user joins the docker
# group so jobs use Docker without sudo). semgrep is intentionally not installed.
#
# Env: WITH_DOCKER (default 1; set 0 for the Docker-less LXC runners).
set -euo pipefail

WITH_DOCKER="${WITH_DOCKER:-1}"

MDLINT_VERSION=0.23.3
GITLEAKS_VERSION=8.30.1
TRUFFLEHOG_VERSION=3.99.0
ZIZMOR_VERSION=1.31.1
RUNNER_USER=github-runner

if [ "$(id -u)" -ne 0 ]; then echo "Run as root (sudo)." >&2; exit 1; fi
export DEBIAN_FRONTEND=noninteractive

# The Docker-less lane (WITH_DOCKER=0) has no use for a Docker apt source, and one left
# for another distro or codename (for example debian + noble) makes every apt-get update
# fail with a missing Release file. Drop it unless it names this host's own distro and
# codename. The Docker lane keeps its source: it is rewritten only when Docker is absent.
if [ "$WITH_DOCKER" != "1" ] && [ -f /etc/apt/sources.list.d/docker.list ]; then
  . /etc/os-release
  grep -q "linux/${ID} ${VERSION_CODENAME} " /etc/apt/sources.list.d/docker.list \
    || rm -f /etc/apt/sources.list.d/docker.list
fi

echo "== base packages =="
apt-get update -qq
apt-get install -y --no-install-recommends \
  git curl wget jq openssl ca-certificates sudo build-essential python3 \
  gnupg apt-transport-https lsb-release

echo "== Node.js 22 LTS (NodeSource) =="
if ! node --version 2>/dev/null | grep -q '^v22\.'; then
  curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
  apt-get install -y nodejs
fi

echo "== PowerShell 7 (packages.microsoft.com) =="
if ! command -v pwsh >/dev/null 2>&1; then
  # The Microsoft repo is keyed by distro + version, so pick the one matching the
  # host: debian/12 on the VM, ubuntu/24.04 on the faxme LXCs.
  . /etc/os-release
  pmc_url="https://packages.microsoft.com/config/${ID}/${VERSION_ID}/packages-microsoft-prod.deb"
  tmp="$(mktemp -d)"
  curl -fsSL -o "$tmp/pmc.deb" "$pmc_url"
  dpkg -i "$tmp/pmc.deb"; rm -rf "$tmp"
  apt-get update -qq
  apt-get install -y powershell
fi

echo "== PowerShell modules (AllUsers): Pester 5+, PSScriptAnalyzer =="
pwsh -NoProfile -Command '
  Set-PSRepository PSGallery -InstallationPolicy Trusted
  if (-not (Get-Module -ListAvailable Pester | Where-Object { $_.Version.Major -ge 5 })) {
    Install-Module Pester -Scope AllUsers -MinimumVersion 5.0.0 -Force -SkipPublisherCheck
  }
  if (-not (Get-Module -ListAvailable PSScriptAnalyzer)) {
    Install-Module PSScriptAnalyzer -Scope AllUsers -Force
  }'

echo "== PowerShell: quiet ScriptBlock logging (journal noise on a CI runner) =="
# pwsh logs every script block it flags as suspicious (Add-Type, base64, reflection /
# dynamic member access, ...) to the journal at Warning level; GitGuard and Pester run pwsh
# constantly and trip that
# heuristic, so the host journal fills with ScriptBlock_Compile warnings. Disabling
# ScriptBlockLogging in the machine config stops them. Merge into any existing
# powershell.config.json so other settings survive; jq output is always valid JSON, we leave the
# file world-readable (pwsh crashes at startup if it cannot read its config), and confirm pwsh
# still starts.
pscfg="$(pwsh -NoProfile -Command '$PSHOME' | tr -d '\r')/powershell.config.json"
base='{}'; [ -f "$pscfg" ] && base="$(cat "$pscfg")"
if printf '%s' "$base" | jq -e . >/dev/null 2>&1; then
  printf '%s' "$base" \
    | jq '.PowerShellPolicies.ScriptBlockLogging.EnableScriptBlockLogging = false
        | .PowerShellPolicies.ScriptBlockLogging.EnableScriptBlockInvocationLogging = false' \
      > "${pscfg}.tmp" && mv "${pscfg}.tmp" "$pscfg" && chmod 0644 "$pscfg"
else
  echo "WARNING: $pscfg exists but is not valid JSON; left untouched." >&2
fi
pwsh -NoProfile -Command '[void]$PSVersionTable.PSVersion'   # fail loudly if the config broke pwsh

echo "== markdownlint-cli2 @${MDLINT_VERSION} (global, pinned) =="
npm install -g "markdownlint-cli2@${MDLINT_VERSION}"

echo "== gitleaks ${GITLEAKS_VERSION} =="
if ! gitleaks version 2>/dev/null | grep -q "${GITLEAKS_VERSION}"; then
  tmp="$(mktemp -d)"
  curl -fsSL -o "$tmp/gl.tgz" \
    "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
  tar -xzf "$tmp/gl.tgz" -C "$tmp" gitleaks
  install -m 0755 "$tmp/gitleaks" /usr/local/bin/gitleaks; rm -rf "$tmp"
fi

echo "== trufflehog ${TRUFFLEHOG_VERSION} =="
if ! trufflehog --version 2>&1 | grep -q "${TRUFFLEHOG_VERSION}"; then
  tmp="$(mktemp -d)"
  curl -fsSL -o "$tmp/th.tgz" \
    "https://github.com/trufflesecurity/trufflehog/releases/download/v${TRUFFLEHOG_VERSION}/trufflehog_${TRUFFLEHOG_VERSION}_linux_amd64.tar.gz"
  tar -xzf "$tmp/th.tgz" -C "$tmp" trufflehog
  install -m 0755 "$tmp/trufflehog" /usr/local/bin/trufflehog; rm -rf "$tmp"
fi

echo "== zizmor ${ZIZMOR_VERSION} =="
if ! zizmor --version 2>/dev/null | grep -q "${ZIZMOR_VERSION}"; then
  tmp="$(mktemp -d)"
  curl -fsSL -o "$tmp/zz.tgz" \
    "https://github.com/zizmorcore/zizmor/releases/download/v${ZIZMOR_VERSION}/zizmor-x86_64-unknown-linux-gnu.tar.gz"
  tar -xzf "$tmp/zz.tgz" -C "$tmp"
  install -m 0755 "$(find "$tmp" -type f -name zizmor | head -1)" /usr/local/bin/zizmor; rm -rf "$tmp"
fi

echo "== squid (installed, service disabled/stopped) =="
apt-get install -y --no-install-recommends squid
systemctl disable --now squid 2>/dev/null || true

if [ "$WITH_DOCKER" = "1" ]; then
  echo "== Docker engine (daemon enabled) =="
  if ! command -v docker >/dev/null 2>&1; then
    . /etc/os-release
    install -m 0755 -d /etc/apt/keyrings
    curl -fsSL "https://download.docker.com/linux/${ID}/gpg" -o /etc/apt/keyrings/docker.asc
    chmod a+r /etc/apt/keyrings/docker.asc
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/${ID} ${VERSION_CODENAME} stable" \
      > /etc/apt/sources.list.d/docker.list
    apt-get update -qq
    apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  fi
  systemctl enable --now docker
else
  echo "== Docker skipped (WITH_DOCKER=0 -- Docker jobs run on the gh-runner-01 VM) =="
fi

# The runner runs as $RUNNER_USER (created by setup-runner.sh). Ensure it exists;
# with Docker it also joins the docker group so jobs use Docker without sudo.
id "$RUNNER_USER" >/dev/null 2>&1 || useradd --system --create-home --shell /usr/sbin/nologin "$RUNNER_USER"
if [ "$WITH_DOCKER" = "1" ]; then
  usermod -aG docker "$RUNNER_USER"
fi

echo
if [ "$WITH_DOCKER" = "1" ]; then
  echo "claude-manager CI toolchain ready (with Docker)."
  echo "A runner ALREADY registered before this ran needs one restart to pick up the new"
  echo "docker-group membership (a freshly deployed runner already has it). Restart it when"
  echo "idle, by its exact unit name -- a glob 'systemctl start actions.runner.*' may match nothing."
  echo "See 'Update the toolchain on a running runner' in gh-runner.md."
else
  echo "claude-manager CI toolchain ready (no Docker; faxme LXC lane)."
  echo "No runner restart needed -- these tools install into the runner's existing PATH, so a"
  echo "running runner picks them up on its next job; restarting only risks interrupting a job."
fi

Network egress

claude-manager CI jobs reach these hosts; allow them through any egress filter:

  • github.com, api.github.com, objects.githubusercontent.com
  • registry.npmjs.org
  • ghcr.io (including ghcr.io/aquasecurity/trivy-db)

Pester and PSScriptAnalyzer are baked in by install-cm-ci-tools.sh, so powershellgallery.com is needed only while that script runs, not at job time.

Verify

# LXC runner (run from your workstation):
ssh root@192.168.1.4 'pct exec 210 -- systemctl list-units "actions.runner.*" --no-pager'
# VM runners:
ssh debian@192.168.1.6 'systemctl list-units "actions.runner.*" --no-pager'

Look for one actions.runner.*.service per registered runner, all active (running), and each showing Idle under the org's (or the nocterra repo's) Settings → Actions → Runners.

Confirm self-heal is armed — each runner should report Restart=always and KillMode=control-group (Restart=no or KillMode=process means the drop-in is missing or old; run arm-runner-self-heal.sh):

ssh root@192.168.1.4 'pct exec 221 -- systemctl show -p Restart -p KillMode "actions.runner.*"'

Each runner should have exactly one Runner.Listener process; a second one is a leftover from a restart under the old KillMode:

ssh root@192.168.1.4 'pct exec 221 -- pgrep -fc Runner.Listener'

Rename or remove a runner

A registered runner has no in-place rename — GitHub fixes the name at registration. To rename one, deregister it and register again under the new name: the container or VM and its installed toolchain stay, only the runner's config and systemd service are recreated (seconds, no rebuild). Removal and rename use a removal token (from the runner's … menu → Remove on the Runners page), which is optional — without it the runner is torn down locally and left "offline" until you remove it by hand.

# Rename an LXC runner (old name -> new name) -- run from your workstation:
ssh root@192.168.1.4 'pct exec 210 -- bash -s -- <OLD_NAME> <REMOVAL_TOKEN>' < remove-runner.sh
ssh root@192.168.1.4 'pct exec 210 -- bash -s -- <NEW_NAME> <URL> <REG_TOKEN> <LABELS>' < register-runner.sh

# Rename a VM runner:
ssh debian@192.168.1.6 'sudo bash -s -- <OLD_NAME> <REMOVAL_TOKEN>' < remove-runner.sh
ssh debian@192.168.1.6 'sudo bash -s -- <NEW_NAME> https://github.com/Fax-Me-In-The-Cloud <REG_TOKEN> cm-ci' < register-runner.sh
remove-runner.sh
#!/usr/bin/env bash
# Remove ONE GitHub Actions runner instance from this host: stop + uninstall its
# service, deregister it from GitHub (if a token is given), and delete its
# directory. Run as root on the VM.
#   Usage: sudo ./remove-runner.sh <name> [removal-token]
#   removal-token: OPTIONAL. From GitHub, the same Runners page as registration
#                  (the runner's "..." menu -> Remove gives the token). Omit it to
#                  just tear the runner down locally -- e.g. a failed runner you
#                  can't get a token for; it will linger as "offline" in GitHub
#                  until you remove it from the Runners page by hand.
set -euo pipefail

BASE=/opt/actions-runner
RUNNER_USER=github-runner

if [ "$(id -u)" -ne 0 ]; then
  echo "Run as root (sudo)." >&2
  exit 1
fi

name="${1:-}"; token="${2:-}"
if [ -z "$name" ]; then
  echo "Usage: sudo ./remove-runner.sh <name> [removal-token]" >&2
  exit 1
fi

dir="$BASE/$name"
if [ ! -d "$dir" ]; then
  echo "No such runner: $dir" >&2
  exit 1
fi

cd "$dir"
./svc.sh stop || true
./svc.sh uninstall || true
if [ -n "$token" ]; then
  sudo -u "$RUNNER_USER" ./config.sh remove --token "$token"
else
  echo "No token given -- skipping GitHub deregistration. Remove '$name' from the" >&2
  echo "Runners page by hand if it lingers as offline." >&2
fi
cd /
rm -rf "$dir"
echo "Runner '$name' removed."

To retire an LXC runner's container entirely, remove the runner as above then pct stop <ctid> && pct destroy <ctid> on pve01.

Troubleshooting

  • installdependencies.sh fails — the runner needs libicu; it is pulled in by that script. Re-run sudo /opt/actions-runner/_dist/bin/installdependencies.sh after sudo apt-get update (drop the sudo inside an LXC, where pct exec already runs as root).
  • Runner shows offline right after registration — check the service: cd /opt/actions-runner/<name> && sudo ./svc.sh status and its own log, tail -40 $(ls -t /opt/actions-runner/<name>/_diag/Runner_*.log | head -1) (cleaner than the journal — it is just that runner's own events).
  • A runner is offline and won't come back — with the self-heal drop-in (see "Runners restart themselves") a runner restarts itself, so this should be rare. If one is still down, start it by its exact unit name: a glob is the trap — systemctl start 'actions.runner.*' only acts on units systemd currently has in memory, which a stopped runner may not be, so it can do nothing (systemd warns unit globs expand to loaded units). Find the unit from disk, then start it by name: systemctl list-unit-files 'actions.runner.*' (or ls /etc/systemd/system/actions.runner.*.service), then sudo systemctl reset-failed <unit> and sudo systemctl start <unit>. If it comes up active but still won't connect (its _diag/Runner_*.log crashes during startup), that runner's install is damaged — remove and re-register it, or redeploy the container. If the drop-in is missing (a runner registered before self-heal was added), run arm-runner-self-heal.sh.
  • Docker jobs fail with a permission error — the github-runner user joins the docker group during install-cm-ci-tools.sh; a runner that was already registered before that ran needs a restart to pick up the group (a freshly deployed one already has it). Restart it when idle, by its exact unit name — see the VM lane.
  • DNS timeouts from jobs — hosts resolve via the LAN Pi-holes → Unbound (see Unbound); a job that can't reach github.com usually means /etc/resolv.conf isn't pointing at 192.168.1.60/.21.