编译新的agent
Some checks are pending
CI / host-build (push) Waiting to run
CI / rk3588-cross-build (push) Waiting to run

This commit is contained in:
sladro 2026-01-10 17:20:00 +08:00
parent 2a562514bc
commit 89cd6a1d8b
6 changed files with 36 additions and 11 deletions

View File

@ -241,6 +241,8 @@ Response 200`{"ok":true}`
> 说明:该能力用于“启动/重启/关闭主程序media-server并选择加载哪个配置文件”。
>
> agent 启动 media-server 时会显式传入:`--config <resolved_config_path>`,因此不依赖 media-server 内部默认配置。
>
> 路径说明:`agent.media_server_process` 下的 `exec_path/work_dir/configs_dir/pid_file` 支持绝对或相对路径;若为相对路径,则以 agent 启动参数 `--config <agent_config_path>` 的**配置文件所在目录**为基准解析。
### 6.1 `POST /v1/media-server/start`
用途:启动本机 media-server若已运行则幂等返回 ok若已运行但 config 不同则 409
@ -252,6 +254,8 @@ Body可选JSON
{"config":"cam1"}
```
说明:若请求 body 非空,则必须带 `Content-Type: application/json`;若 body 为空,可不带该 header。
`config` 解析规则:
- 为空/缺省:使用 `agent.config_path`
- 非空:只允许文件名/配置名(禁止包含 `/`、`\\`、`..`);若不带扩展名自动补 `.json`;最终从 `agent.media_server_process.configs_dir` 下解析为 `<configs_dir>/<config>.json`
@ -277,6 +281,8 @@ Body可选JSON
{"config":"cam1"}
```
说明:若请求 body 非空,则必须带 `Content-Type: application/json`;若 body 为空,可不带该 header。
Response 200
```json
{"ok":true,"running":true,"pid":1234,"config_path":"/home/orangepi/Desktop/OrangePi3588Media/configs/cam1.json"}

View File

@ -16,10 +16,10 @@
"config_path": "./test_cam1_strict_minio_alarm_rtsp_server.json",
"media_server_process": {
"enable": true,
"exec_path": "/home/orangepi/Desktop/OrangePi3588Media/build/media-server",
"work_dir": "/home/orangepi/Desktop/OrangePi3588Media",
"configs_dir": "/home/orangepi/Desktop/OrangePi3588Media/configs",
"pid_file": "/var/run/rk3588sys-media-server.pid",
"exec_path": "../build/media-server",
"work_dir": "..",
"configs_dir": "../configs",
"pid_file": "./rk3588sys-media-server.pid",
"graceful_timeout_ms": 5000
},
"media_server_base_url": "http://127.0.0.1:9000",

View File

@ -9,6 +9,7 @@ import (
"net/url"
"os"
"os/signal"
"path/filepath"
"strconv"
"strings"
"sync"
@ -65,7 +66,12 @@ func main() {
}
store := modelstore.New(cfg.Agent.ModelsDir, cfg.Agent.MaxUploadMB)
h := httpapi.New(cfg.Agent, ms, store, deviceID, agentPort, mediaPort, Version, GitSHA)
baseDir := filepath.Dir(*cfgPath)
if abs, err := filepath.Abs(*cfgPath); err == nil {
baseDir = filepath.Dir(abs)
}
h := httpapi.New(cfg.Agent, baseDir, ms, store, deviceID, agentPort, mediaPort, Version, GitSHA)
httpSrv := &http.Server{
Addr: cfg.Agent.Listen,

View File

@ -49,10 +49,10 @@ type InfoResponse struct {
UptimeSec int64 `json:"uptime_sec"`
}
func New(agentCfg config.AgentConfig, ms *mediaserver.Client, store *modelstore.Store, deviceID string, agentPort int, mediaPort int, version, gitSHA string) http.Handler {
func New(agentCfg config.AgentConfig, baseDir string, ms *mediaserver.Client, store *modelstore.Store, deviceID string, agentPort int, mediaPort int, version, gitSHA string) http.Handler {
var pc *procctl.Controller
if agentCfg.MediaServerProcess.Enable {
pc = procctl.New(agentCfg)
pc = procctl.New(agentCfg, baseDir)
}
s := &Server{
agentCfg: agentCfg,

View File

@ -37,11 +37,23 @@ type Controller struct {
defCfg string
}
func New(agentCfg config.AgentConfig) *Controller {
return &Controller{
proc: agentCfg.MediaServerProcess,
defCfg: agentCfg.ConfigPath,
func New(agentCfg config.AgentConfig, baseDir string) *Controller {
p := agentCfg.MediaServerProcess
if baseDir != "" {
if p.ExecPath != "" && !filepath.IsAbs(p.ExecPath) {
p.ExecPath = filepath.Join(baseDir, p.ExecPath)
}
if p.WorkDir != "" && !filepath.IsAbs(p.WorkDir) {
p.WorkDir = filepath.Join(baseDir, p.WorkDir)
}
if p.ConfigsDir != "" && !filepath.IsAbs(p.ConfigsDir) {
p.ConfigsDir = filepath.Join(baseDir, p.ConfigsDir)
}
if p.PidFile != "" && !filepath.IsAbs(p.PidFile) {
p.PidFile = filepath.Join(baseDir, p.PidFile)
}
}
return &Controller{proc: p, defCfg: agentCfg.ConfigPath}
}
func (c *Controller) Enabled() bool { return c != nil && c.proc.Enable }
@ -76,6 +88,7 @@ func (c *Controller) Start(configName string) (Status, error) {
b, _ := json.Marshal(pf2)
b = append(b, '\n')
if err := files.WriteFileAtomic(c.proc.PidFile, b, 0o644); err != nil {
_ = stopProcess(pid, 1*time.Second)
return Status{}, fmt.Errorf("write pid file: %w", err)
}
return Status{Running: true, Pid: pid, ConfigPath: resolved}, nil

Binary file not shown.