Files
blackbird/core/include/registry/InitParser.hh
T
qing 08df3929b2 feat(core): services.yaml 启动配置 + _run.sh 统一参数透传
Step 1: init.txt → services.yaml
- 新增 InitParser (yaml-cpp), 支持 YAML/TXT 双模式解析, 向后兼容 init.txt
- 新增 services.yaml 声明式服务配置 (name/cmd/args/depends_on/sleep_before)
- 改造 pmc_mtd.cpp 集成 InitParser, 支持目录/.yaml/.txt 三种路径模式
- Makefile 添加 InitParser 编译目标 + -lyaml-cpp 链接
- setup 脚本添加 libyaml-cpp-dev / yaml-cpp-devel 依赖
- core/_run.sh 改为 -i . (目录模式, 自动查找 services.yaml → init.txt)

Step 2: 11 个 _run.sh 统一参数透传
- 8 个脚本改动: 追加 "$@" / 移除 sleep / 修引号
- waf 保留 -c config.yaml 作为脚本默认值
- services.yaml waf args 改为 [] 避免重复传递
- 开发方案文档: docs/reports/core_services_yaml_dev_doc.md
2026-08-10 03:16:28 +08:00

50 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <string>
#include <vector>
#include <map>
namespace qing::registry {
/* 服务启动配置项
*
* 从 services.yaml 或 init.txt 解析出的单个服务声明。
* YAML 模式下包含完整的元数据;TXT 模式下仅 cmd 有值。
*/
struct ServiceConfig {
std::string name; /* 服务唯一标识 */
std::string cmd; /* 启动命令(如 bash /opt/.../_run.sh) */
std::vector<std::string> args; /* 传递给 _run.sh 的命令行参数 */
std::map<std::string, std::string> env; /* 启动前设置的环境变量 */
std::vector<std::string> depends_on; /* 依赖的服务名列表(未来 DAG 排序用) */
int sleep_before = 0; /* 启动前等待秒数 */
/* 拼接完整命令:cmd + " " + args... */
std::string toCommand() const;
};
/* 启动配置解析器
*
* 优先读 services.yaml(结构化声明),不存在则回退 init.txt(纯命令列表)。
* 两种格式都输出 std::vector<ServiceConfig>,调用方无需关心来源。
*/
class InitParser {
public:
/* 入口:传入配置目录(如 /etc/Nidus)
*
* 查找顺序:
* 1. <dir>/services.yaml → parseYaml()
* 2. <dir>/init.txt → parseTxt()
* 3. 都不存在 → 返回空 vector,调用方自行处理
*/
static std::vector<ServiceConfig> load(const std::string& dir);
/* 解析 services.yaml */
static std::vector<ServiceConfig> parseYaml(const std::string& path);
/* 解析 init.txt(向后兼容,每行一条命令,# 开头为注释) */
static std::vector<ServiceConfig> parseTxt(const std::string& path);
};
} // namespace qing::registry