Skip to content

Commit

Permalink
contrib: setup_templates: use write_file for the runner service
Browse files Browse the repository at this point in the history
This results in the file being written unconditionally on every boot.
This also means that the file in cloud-init and the one in the machine
will not become out of sync.
The drawback is that we need to systemctl deamon-reload on every boot now,
which should however be okay performance-wise.
  • Loading branch information
hnez committed Aug 22, 2024
1 parent 76bd8cd commit 28525f7
Showing 1 changed file with 23 additions and 37 deletions.
60 changes: 23 additions & 37 deletions contrib/setup_templates/generic/cloud-init/user-data
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,28 @@ write_files:
ExecStart=
ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM

runcmd:
- systemctl daemon-reload
- systemctl enable --now --no-block "[email protected]"
- |
set -e -u

# Set up a service that mounts the job config file system and runs the job
# script inside of it under the `runner` user.

SERVICE_FILE="github-action-runner.service"
SERVICE_PATH="/etc/systemd/system/${SERVICE_FILE}"

if ! test -e "${SERVICE_PATH}"
then
cat > "${SERVICE_PATH}" << 'EOF'
[Unit]
Description=GitHub JIT Runner
After=network.target cloud-final.service

[Service]
ExecStartPre=+/usr/bin/mount -o rw,fmask=0022,dmask=0022,uid=runner,gid=runner --mkdir /dev/disk/by-label/JOBDATA /home/runner/config
ExecStart=/home/runner/config/job.sh
ExecStopPost=+/usr/bin/systemctl poweroff
StandardOutput=journal+console
StandardError=journal+console
User=runner
WorkingDirectory=/home/runner
KillMode=process
KillSignal=SIGTERM
TimeoutStopSec=5min
- path: /etc/systemd/system/github-action-runner.service
content: |
[Unit]
Description=GitHub JIT Runner
After=network.target cloud-final.service

[Install]
WantedBy=cloud-init.target
EOF
[Service]
ExecStartPre=+/usr/bin/mount -o rw,fmask=0022,dmask=0022,uid=runner,gid=runner --mkdir /dev/disk/by-label/JOBDATA /home/runner/config
ExecStart=/home/runner/config/job.sh
ExecStopPost=+/usr/bin/systemctl poweroff
StandardOutput=journal+console
StandardError=journal+console
User=runner
WorkingDirectory=/home/runner
KillMode=process
KillSignal=SIGTERM
TimeoutStopSec=5min

[Install]
WantedBy=cloud-init.target

systemctl daemon-reload
systemctl enable "${SERVICE_FILE}"
systemctl start --no-block "${SERVICE_FILE}"
fi
runcmd:
- systemctl daemon-reload
- systemctl enable --now --no-block [email protected]
- systemctl enable --now --no-block github-action-runner.service

0 comments on commit 28525f7

Please sign in to comment.