core: 移除 init.txt 向后兼容,仅支持 services.yaml

- InitParser: 移除 parseTxt(),load() 不再回退 init.txt
- pmc_mtd: parse_self_init_list 移除 TXT 分支,非 .yaml 文件报错退出
- main.cpp: --help 中 -i 参数描述移除 .txt
- Makefile: install/uninstall 移除 init.txt 拷贝/删除
- services.yaml: 头注释移除 init.txt 相关措辞
- 删除 init.txt 文件
- README (core + 项目根): 全部 init.txt 引用替换为 services.yaml
- core README: 补全 liblogc/yaml-cpp 依赖声明,修正文件结构
This commit is contained in:
qing committed 2026-08-10 05:39:00 +00:00
1 parent f041bf284b
commit b0d71a4c58
9 files changed
+53 -119

No files matched your search

+1 -1
View File
@@ -149,7 +149,7 @@ int main(int argc, char** argv) {
("list", "list process all run") /* 列出运行中的进程 */
("kill", po::value<int>(), "kill a process") /* 杀死一个进程 */
/********* 子系统服务模式 ********/
("init,i", po::value<std::string>(), "self-init config (dir or .yaml/.txt file)") /* 输入自启动配置 */
("init,i", po::value<std::string>(), "self-init config (dir or .yaml file)") /* 输入自启动配置 */
("serve", po::value<int>(), "Run as http server") /* 启用http伺服器 */
("confs", po::value<int>(), "Run embedded confs rpc server"); /* 启用内嵌confs配置服务 */
+6 -8
View File
@@ -93,14 +93,11 @@ catch(std::exception& exp) {
/* 解析自启动列表、添加自启动项
*
* 兼容两种格式:
* - services.yaml(结构化声明,含 args/env/depends_on/sleep_before)
* - init.txt(纯命令列表,每行一条 bash 命令,# 开头为注释)
* 仅支持 services.yaml 格式(结构化声明,含 args/env/depends_on/sleep_before)
*
* path 可以是:
* - 目录路径 → 自动查找 services.yaml 或 init.txt
* - 目录路径 → 自动查找目录下的 services.yaml
* - .yaml 文件 → 按 YAML 解析
* - 其他文件 → 按 TXT 解析(向后兼容 init.txt)
*
* 如果在解析过程中出错,只是打印异常 */
void parse_self_init_list(std::string &path)
@@ -110,14 +107,15 @@ try {
std::vector<registry::ServiceConfig> services;
if (fs::is_directory(path)) {
/* 目录模式:InitParser::load 自动查找 services.yaml → init.txt */
/* 目录模式:InitParser::load 查找 services.yaml */
services = registry::InitParser::load(path);
} else if (path.size() > 5 && path.substr(path.size() - 5) == ".yaml") {
/* YAML 文件模式 */
services = registry::InitParser::parseYaml(path);
} else {
/* TXT 文件模式(向后兼容 init.txt) */
services = registry::InitParser::parseTxt(path);
/* 不再支持 init.txt 纯命令列表格式 */
std::cerr << "parse_self_init_list: 不支持的配置格式,请使用 services.yaml" << std::endl;
return;
}
if (services.empty()) {
+1 -40
View File
@@ -25,21 +25,13 @@ std::vector<ServiceConfig> InitParser::load(const std::string& dir) {
namespace fs = std::filesystem;
auto yaml_path = fs::path(dir) / "services.yaml";
auto txt_path = fs::path(dir) / "init.txt";
/* 优先 services.yaml */
if (fs::exists(yaml_path)) {
std::cerr << "[InitParser] 使用 services.yaml: " << yaml_path << std::endl;
return parseYaml(yaml_path.string());
}
/* 回退 init.txt */
if (fs::exists(txt_path)) {
std::cerr << "[InitParser] 回退 init.txt: " << txt_path << std::endl;
return parseTxt(txt_path.string());
}
std::cerr << "[InitParser] 未找到 services.yaml 或 init.txt 于 " << dir << std::endl;
std::cerr << "[InitParser] 未找到 services.yaml 于 " << dir << std::endl;
return {};
}
@@ -95,37 +87,6 @@ std::vector<ServiceConfig> InitParser::parseYaml(const std::string& path) {
return result;
}
std::vector<ServiceConfig> InitParser::parseTxt(const std::string& path) {
std::vector<ServiceConfig> result;
std::ifstream file(path);
if (!file.is_open()) {
std::cerr << "[InitParser] 无法打开 init.txt: " << path << std::endl;
return {};
}
std::string line;
while (std::getline(file, line)) {
/* 去除注释(# 之后的内容) */
auto pos = line.find('#');
if (pos != std::string::npos)
line = line.substr(0, pos);
/* trim 空白 */
auto first = line.find_first_not_of(" \t\r\n");
if (first == std::string::npos)
continue; /* 空行 */
auto last = line.find_last_not_of(" \t\r\n");
line = line.substr(first, last - first + 1);
ServiceConfig svc;
svc.cmd = line;
/* init.txt 模式下 name/args/env/depends_on/sleep_before 均为空/默认 */
result.push_back(std::move(svc));
}
std::cerr << "[InitParser] init.txt 解析完成,共 " << result.size() << " 个服务" << std::endl;
return result;
}
} // namespace qing::registry