Ask for the registration and capacity at first boot

gitea-runner-setup asks on the console for the number of parallel jobs,
the Gitea URL and a registration token, and registers the runner. It runs
until the runner is registered, and logins wait for it, as for
systemd-firstboot. The capacity goes to a drop-in of gitea-runner.service,
which passes it to the config as CAPACITY, so the config stays read-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Job79andClaude Opus 5.5 committed 2026-11-23 18:57:23 +00:00
1 parent 094ee671d7
commit 018f15172d
7 files changed
+59 -9

No files matched your search

+2
View File
@@ -8,6 +8,8 @@ runner:
# file is where `gitea-runner register` keeps the registration, wherever it
# runs. gitea-runner.path starts the runner once it is there.
file: /var/lib/gitea-runner/.runner
# capacity is the number of parallel jobs, set by gitea-runner.service.
capacity: ${CAPACITY}
# shutdown_timeout lets running jobs finish when the runner stops, as it
# does before an update reboots the machine.
shutdown_timeout: 1h
@@ -5,7 +5,9 @@
# systemd-networkd is disabled by Fedora, which uses NetworkManager.
enable systemd-networkd.service
# gitea-runner.path starts the runner once it is registered.
# gitea-runner-setup.service registers the runner, and gitea-runner.path then
# starts it.
enable gitea-runner-setup.service
enable gitea-runner.path
disable gitea-runner.service
@@ -0,0 +1,21 @@
# gitea-runner-setup.service runs /usr/libexec/gitea-runner-setup on the
# console until the runner is registered, after systemd-firstboot has asked
# its questions there. Logins wait for it, as for systemd-firstboot, so no
# getty reads the same console.
[Unit]
Description=Gitea runner setup
ConditionPathExists=!/var/lib/gitea-runner/.runner
Wants=network-online.target
After=systemd-firstboot.service network-online.target
Before=systemd-user-sessions.service
[Service]
Type=oneshot
# HOME is where gitea-runner keeps its cache, as in gitea-runner.service.
Environment=HOME=/var/lib/gitea-runner
ExecStart=/usr/libexec/gitea-runner-setup
StandardInput=tty
StandardOutput=tty
[Install]
WantedBy=multi-user.target
@@ -1,5 +1,5 @@
# gitea-runner.path starts the runner once it is registered, so a new machine
# waits for `gitea-runner -c /etc/gitea-runner/config.yaml register`.
# waits for gitea-runner-setup.service.
[Unit]
Description=Start the Gitea runner once registered
@@ -11,6 +11,9 @@ After=network-online.target podman.socket
Requires=podman.socket
[Service]
# CAPACITY is the number of parallel jobs. gitea-runner-setup writes a drop-in
# that overrides it, which `systemctl edit gitea-runner` changes.
Environment=CAPACITY=1
# HOME holds the cache of actions/cache, next to the registration.
Environment=HOME=/var/lib/gitea-runner
Environment=DOCKER_HOST=unix:///run/podman/podman.sock
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# gitea-runner-setup asks on the console for the number of parallel jobs and
# the runner's registration, and registers the runner. gitea-runner.path then
# starts it. gitea-runner-setup.service runs it until the runner is registered.
#
# The capacity goes to a drop-in of gitea-runner.service, which passes it to
# /etc/gitea-runner/config.yaml as CAPACITY. It is written first, because the
# runner starts as soon as it is registered.
set -euo pipefail
read -rp "Parallel jobs [1]: " capacity
[[ $capacity =~ ^[1-9][0-9]*$ ]] || capacity=1
mkdir -p /etc/systemd/system/gitea-runner.service.d
printf '[Service]\nEnvironment=CAPACITY=%s\n' "$capacity" \
> /etc/systemd/system/gitea-runner.service.d/capacity.conf
systemctl daemon-reload
export CAPACITY=$capacity
until [[ -f /var/lib/gitea-runner/.runner ]]; do
read -rp "Gitea URL: " url
read -rp "Registration token: " token
gitea-runner -c /etc/gitea-runner/config.yaml register --no-interactive \
--instance "$url" --token "$token" || echo "Try again."
done