Skip to content

Commit 04a73eb

Browse files
committed
fix: use abs path
1 parent eb47b8a commit 04a73eb

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

config.yaml.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ server:
66
port: 8080
77
addr: 0.0.0.0
88
runners:
9+
# 本地运行可用 ./runners;Docker/docker-compose 请改为 /app/runners(与卷挂载一致)
910
base_path: ./runners
1011
items: [] # 预置 Runner 列表,也可通过 Web 界面添加

docs/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cp config.yaml.example config.yaml
1212
|------|------|------|
1313
| `server.port` | HTTP 服务端口 | `8080` |
1414
| `server.addr` | 监听地址;空则仅绑定端口(等价所有接口) ||
15-
| `runners.base_path` | 所有 Runner 安装目录的根路径 | `./runners` |
15+
| `runners.base_path` | 所有 Runner 安装目录的根路径;Docker 部署时请设为 `/app/runners`(与卷挂载一致) | `./runners` |
1616
| `runners.items` | 预置的 Runner 列表 | 也可通过 Web 界面添加 |
1717

1818
「GitHub 显示检查」所需的 token 仅在各 runner 目录下配置,见 [添加 Runner](adding-runner.md) 中的说明。

internal/handler/handler.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/rand"
66
"encoding/json"
7+
"fmt"
78
"net/http"
89
"os"
910
"os/exec"
@@ -68,7 +69,13 @@ func runInstallRunnerScript(basePath, runnerName string, timeout time.Duration)
6869
}
6970

7071
// runConfigScript 在 installDir 下执行 config 脚本向 GitHub 注册,超时 2 分钟;返回输出与 error
72+
// 将 installDir 转为绝对路径,避免相对路径在 exec 时随进程 CWD 解析导致找不到 config 脚本
7173
func runConfigScript(installDir, url, token string, labels []string, timeout time.Duration) ([]byte, error) {
74+
absDir, err := filepath.Abs(installDir)
75+
if err != nil {
76+
return nil, fmt.Errorf("解析 runner 路径失败: %w", err)
77+
}
78+
installDir = absDir
7279
configScript := filepath.Join(installDir, runner.ConfigScriptName())
7380
args := []string{"--url", url, "--token", token}
7481
if len(labels) > 0 {

internal/runner/runner.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,13 @@ func processExists(pid int) bool {
259259
var execCommand = exec.Command
260260

261261
// Start 在 installDir 下后台启动 runner(执行 run.sh/run.cmd)
262+
// 将 installDir 转为绝对路径,避免相对路径在 exec 时随进程 CWD 解析导致找不到 run.sh
262263
func Start(installDir string) error {
264+
absDir, err := filepath.Abs(installDir)
265+
if err != nil {
266+
return fmt.Errorf("解析 runner 路径失败: %w", err)
267+
}
268+
installDir = absDir
263269
script := filepath.Join(installDir, RunScriptName())
264270
if _, err := os.Stat(script); err != nil {
265271
return fmt.Errorf("未找到运行脚本 %s: %w", script, err)
@@ -278,7 +284,13 @@ func Start(installDir string) error {
278284
}
279285

280286
// Stop 向 runner 进程发送停止信号(读取 pid 后 SIGTERM;Windows 用 taskkill)
287+
// 将 installDir 转为绝对路径,确保能正确找到该 runner 的 pid 文件
281288
func Stop(installDir string) error {
289+
absDir, err := filepath.Abs(installDir)
290+
if err != nil {
291+
return fmt.Errorf("解析 runner 路径失败: %w", err)
292+
}
293+
installDir = absDir
282294
pid, err := readRunnerPid(installDir)
283295
if err != nil || pid <= 0 {
284296
return fmt.Errorf("未找到 runner pid 文件或 pid 无效: %w", err)

0 commit comments

Comments
 (0)