上篇文章我们介绍了如何用Gitea Action + act_runner实现更新自动构建与发布,往往我们希望部属多个runner为不同项目提供服务,但通过命令直接运行或运行在多个screen里并不容易维护,无法自动重启且无法统一查看状态。
本文介绍一种更优雅、标准化的方案:使用systemd管理多个Gitea act_runner 实例。这样可以实现:
✅ 开机自动启动
✅ 崩溃自动重启
✅ 统一日志管理(journalctl)
✅ 一条命令启动/停止所有 runner
准备工作
首先需要根据上篇文章在恰当的工作目录成功注册act_runner,您将获得数个配置文件目录
/etc/runners/service1/
/etc/runners/service2/
在每个配置文件目录下,都有config.yaml和.runner两个配置文件。如果没有,请输入以下命令生成配置文件
act_runner generate-config > config.yaml
一般的,需要进行以下两项修改
runner:
# Where to store the registration result. # 改为绝对路径
file: /etc/runners/service1/.runner
labels: # 如果需要使用宿主机直接运行而不是docker则需修改本部分
- "ubuntu-latest:host"
创建Systemed模板服务
新建/编辑一个service文件
sudo vim /etc/systemd/system/act-runner@.service
写入以下内容(根据情况修改):
[Unit]
Description=Gitea Act Runner instance %i
After=network.target
[Service]
User=www-data # 这里填写您的运行用户名
WorkingDirectory=/etc/runners
ExecStart=/usr/local/bin/act_runner daemon --config /etc/runners/%i/config.yaml
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
启动多个runners
加载配置
sudo systemctl daemon-reload
启动实例
sudo systemctl enable --now act-runner@service1
sudo systemctl enable --now act-runner@service2
……
至此,您的所有设置的act_runner应该可以开始运行。您可在您的Gitea上“仓库-设置-Actions-runners”查看Runners的状态是否为“空闲”等非离线情况。
管理多个runners
| 操作 | 命令 |
|---|---|
| 启动所有runner | sudo systemctl start 'act-runner@*' |
| 停止所有runner | sudo systemctl stop 'act-runner@*' |
| 重启所有runner | sudo systemctl restart 'act-runner@*' |
| 查看所有状态 | sudo systemctl status 'act-runner@*' |
| 查看所有runner的日志 | sudo journalctl -u gitlab-runner -f |
心情表态
+1
+1
+1
+1
+1
+1

近期评论