From 5f2a5c2b234d4f87e960f7fedf0c118477c289f2 Mon Sep 17 00:00:00 2001 From: Job79 Date: Sat, 14 Nov 2026 12:21:50 +0000 Subject: [PATCH] First-boot setup on the serial console too The setup asked only on the screen (tty1); it now also asks on the serial console (ttyS0), so a VM can be set up from a serial terminal or a script. Whichever console is answered first stops the setup on the other. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01V27snprgiQMRMB6RRDNjCX --- README.md | 2 +- .../system-preset/50-git-runner.preset | 2 +- .../systemd/system/gitea-runner-setup.service | 17 ---------------- .../system/gitea-runner-setup@.service | 20 +++++++++++++++++++ .../lib/systemd/system/gitea-runner.service | 3 ++- mkosi.extra/usr/libexec/gitea-runner-setup | 5 ++++- 6 files changed, 28 insertions(+), 21 deletions(-) delete mode 100644 mkosi.extra/usr/lib/systemd/system/gitea-runner-setup.service create mode 100644 mkosi.extra/usr/lib/systemd/system/gitea-runner-setup@.service diff --git a/README.md b/README.md index 632083d..21466db 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ A [Gitea Actions](https://docs.gitea.com/usage/actions/overview) runner packaged ## Install -Download [the disk image](https://git.plabble.org/Job79/git-runner-mkosi/releases/download/latest/git-runner.qcow2) (built weekly by the `os` workflow), resize it to the disk size you want (/var grows to fill it) and boot it with UEFI. The console asks for a root password, hostname, Gitea URL, registration token and number of parallel jobs; the runner then registers itself. +Download [the disk image](https://git.plabble.org/Job79/git-runner-mkosi/releases/download/latest/git-runner.qcow2) (built weekly by the `os` workflow), resize it to the disk size you want (/var grows to fill it) and boot it with UEFI. The screen and the serial console ask for a root password, hostname, Gitea URL, registration token and number of parallel jobs; the runner then registers itself. ## Images diff --git a/mkosi.extra/usr/lib/systemd/system-preset/50-git-runner.preset b/mkosi.extra/usr/lib/systemd/system-preset/50-git-runner.preset index 6273ea9..d2b939d 100644 --- a/mkosi.extra/usr/lib/systemd/system-preset/50-git-runner.preset +++ b/mkosi.extra/usr/lib/systemd/system-preset/50-git-runner.preset @@ -5,7 +5,7 @@ enable systemd-resolved.service enable nftables.service enable podman.socket enable getty@.service -enable gitea-runner-setup.service +enable gitea-runner-setup@.service tty1 ttyS0 enable etc-shadow.mount enable gitea-runner.service enable systemd-sysupdate-update.timer diff --git a/mkosi.extra/usr/lib/systemd/system/gitea-runner-setup.service b/mkosi.extra/usr/lib/systemd/system/gitea-runner-setup.service deleted file mode 100644 index fe94044..0000000 --- a/mkosi.extra/usr/lib/systemd/system/gitea-runner-setup.service +++ /dev/null @@ -1,17 +0,0 @@ -# First boot: asks for the root password and the runner's registration on the console (tty1). -[Unit] -Description=Gitea runner first-boot setup -ConditionPathExists=!/var/lib/gitea-runner/runner.env -Before=getty@tty1.service kmsconvt@tty1.service - -[Service] -Type=oneshot -ExecStart=/usr/libexec/gitea-runner-setup -StandardInput=tty -StandardOutput=tty -TTYPath=/dev/tty1 -TTYReset=yes -TTYVHangup=yes - -[Install] -WantedBy=multi-user.target diff --git a/mkosi.extra/usr/lib/systemd/system/gitea-runner-setup@.service b/mkosi.extra/usr/lib/systemd/system/gitea-runner-setup@.service new file mode 100644 index 0000000..970061c --- /dev/null +++ b/mkosi.extra/usr/lib/systemd/system/gitea-runner-setup@.service @@ -0,0 +1,20 @@ +# First boot: asks for the root password and the runner's registration, on the screen (tty1) and +# the serial console (ttyS0) at once; whichever is answered first stops the other. +[Unit] +Description=Gitea runner first-boot setup on %I +ConditionPathExists=!/var/lib/gitea-runner/runner.env +Before=getty@%i.service serial-getty@%i.service kmsconvt@%i.service + +[Service] +Type=oneshot +ExecStart=/usr/libexec/gitea-runner-setup +StandardInput=tty +StandardOutput=tty +TTYPath=/dev/%I +TTYReset=yes +TTYVHangup=yes +# Answering on one console stops the setup on the other (SIGTERM), which is no failure. +SuccessExitStatus=SIGTERM + +[Install] +WantedBy=multi-user.target diff --git a/mkosi.extra/usr/lib/systemd/system/gitea-runner.service b/mkosi.extra/usr/lib/systemd/system/gitea-runner.service index 116f067..3d32b77 100644 --- a/mkosi.extra/usr/lib/systemd/system/gitea-runner.service +++ b/mkosi.extra/usr/lib/systemd/system/gitea-runner.service @@ -3,7 +3,8 @@ Description=Gitea Actions runner Wants=network-online.target gitea-runner-images.service # gitea-runner-setup writes runner.env on first boot. -After=network-online.target podman.socket gitea-runner-images.service gitea-runner-setup.service +After=network-online.target podman.socket gitea-runner-images.service +After=gitea-runner-setup@tty1.service gitea-runner-setup@ttyS0.service Requires=podman.socket [Service] diff --git a/mkosi.extra/usr/libexec/gitea-runner-setup b/mkosi.extra/usr/libexec/gitea-runner-setup index 6dda22b..89423de 100755 --- a/mkosi.extra/usr/libexec/gitea-runner-setup +++ b/mkosi.extra/usr/libexec/gitea-runner-setup @@ -1,5 +1,6 @@ #!/bin/bash -# First boot: asks for the root password and the runner's registration on the console (tty1). +# First boot: asks for the root password and the runner's registration, on the screen (tty1) and the +# serial console (ttyS0) at once (gitea-runner-setup@.service). # /etc is read-only, so the answers go to /var: the password to /var/lib/shadow (etc-shadow.mount # puts it over /etc/shadow), the rest to the runner's runner.env. set -euo pipefail @@ -28,3 +29,5 @@ GITEA_RUNNER_REGISTRATION_TOKEN=$token GITEA_RUNNER_CAPACITY=$capacity ENV echo "Done. The runner registers itself within a few seconds." +# Stop the setup on the other console, which then shows its login. +systemctl --no-block stop "gitea-runner-setup@*.service"