编译新的agent
This commit is contained in:
parent
2a562514bc
commit
89cd6a1d8b
@ -241,6 +241,8 @@ Response 200:`{"ok":true}`
|
|||||||
> 说明:该能力用于“启动/重启/关闭主程序(media-server)并选择加载哪个配置文件”。
|
> 说明:该能力用于“启动/重启/关闭主程序(media-server)并选择加载哪个配置文件”。
|
||||||
>
|
>
|
||||||
> agent 启动 media-server 时会显式传入:`--config <resolved_config_path>`,因此不依赖 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`
|
### 6.1 `POST /v1/media-server/start`
|
||||||
用途:启动本机 media-server(若已运行则幂等返回 ok;若已运行但 config 不同则 409)。
|
用途:启动本机 media-server(若已运行则幂等返回 ok;若已运行但 config 不同则 409)。
|
||||||
@ -252,6 +254,8 @@ Body(可选,JSON):
|
|||||||
{"config":"cam1"}
|
{"config":"cam1"}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
说明:若请求 body 非空,则必须带 `Content-Type: application/json`;若 body 为空,可不带该 header。
|
||||||
|
|
||||||
`config` 解析规则:
|
`config` 解析规则:
|
||||||
- 为空/缺省:使用 `agent.config_path`
|
- 为空/缺省:使用 `agent.config_path`
|
||||||
- 非空:只允许文件名/配置名(禁止包含 `/`、`\\`、`..`);若不带扩展名自动补 `.json`;最终从 `agent.media_server_process.configs_dir` 下解析为 `<configs_dir>/<config>.json`
|
- 非空:只允许文件名/配置名(禁止包含 `/`、`\\`、`..`);若不带扩展名自动补 `.json`;最终从 `agent.media_server_process.configs_dir` 下解析为 `<configs_dir>/<config>.json`
|
||||||
@ -277,6 +281,8 @@ Body(可选,JSON):
|
|||||||
{"config":"cam1"}
|
{"config":"cam1"}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
说明:若请求 body 非空,则必须带 `Content-Type: application/json`;若 body 为空,可不带该 header。
|
||||||
|
|
||||||
Response 200:
|
Response 200:
|
||||||
```json
|
```json
|
||||||
{"ok":true,"running":true,"pid":1234,"config_path":"/home/orangepi/Desktop/OrangePi3588Media/configs/cam1.json"}
|
{"ok":true,"running":true,"pid":1234,"config_path":"/home/orangepi/Desktop/OrangePi3588Media/configs/cam1.json"}
|
||||||
|
|||||||
@ -16,10 +16,10 @@
|
|||||||
"config_path": "./test_cam1_strict_minio_alarm_rtsp_server.json",
|
"config_path": "./test_cam1_strict_minio_alarm_rtsp_server.json",
|
||||||
"media_server_process": {
|
"media_server_process": {
|
||||||
"enable": true,
|
"enable": true,
|
||||||
"exec_path": "/home/orangepi/Desktop/OrangePi3588Media/build/media-server",
|
"exec_path": "../build/media-server",
|
||||||
"work_dir": "/home/orangepi/Desktop/OrangePi3588Media",
|
"work_dir": "..",
|
||||||
"configs_dir": "/home/orangepi/Desktop/OrangePi3588Media/configs",
|
"configs_dir": "../configs",
|
||||||
"pid_file": "/var/run/rk3588sys-media-server.pid",
|
"pid_file": "./rk3588sys-media-server.pid",
|
||||||
"graceful_timeout_ms": 5000
|
"graceful_timeout_ms": 5000
|
||||||
},
|
},
|
||||||
"media_server_base_url": "http://127.0.0.1:9000",
|
"media_server_base_url": "http://127.0.0.1:9000",
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -65,7 +66,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
store := modelstore.New(cfg.Agent.ModelsDir, cfg.Agent.MaxUploadMB)
|
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{
|
httpSrv := &http.Server{
|
||||||
Addr: cfg.Agent.Listen,
|
Addr: cfg.Agent.Listen,
|
||||||
|
|||||||
@ -49,10 +49,10 @@ type InfoResponse struct {
|
|||||||
UptimeSec int64 `json:"uptime_sec"`
|
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
|
var pc *procctl.Controller
|
||||||
if agentCfg.MediaServerProcess.Enable {
|
if agentCfg.MediaServerProcess.Enable {
|
||||||
pc = procctl.New(agentCfg)
|
pc = procctl.New(agentCfg, baseDir)
|
||||||
}
|
}
|
||||||
s := &Server{
|
s := &Server{
|
||||||
agentCfg: agentCfg,
|
agentCfg: agentCfg,
|
||||||
|
|||||||
@ -37,11 +37,23 @@ type Controller struct {
|
|||||||
defCfg string
|
defCfg string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(agentCfg config.AgentConfig) *Controller {
|
func New(agentCfg config.AgentConfig, baseDir string) *Controller {
|
||||||
return &Controller{
|
p := agentCfg.MediaServerProcess
|
||||||
proc: agentCfg.MediaServerProcess,
|
if baseDir != "" {
|
||||||
defCfg: agentCfg.ConfigPath,
|
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 }
|
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, _ := json.Marshal(pf2)
|
||||||
b = append(b, '\n')
|
b = append(b, '\n')
|
||||||
if err := files.WriteFileAtomic(c.proc.PidFile, b, 0o644); err != nil {
|
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{}, fmt.Errorf("write pid file: %w", err)
|
||||||
}
|
}
|
||||||
return Status{Running: true, Pid: pid, ConfigPath: resolved}, nil
|
return Status{Running: true, Pid: pid, ConfigPath: resolved}, nil
|
||||||
|
|||||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user