dnfs2: --no-confs 模式 + 全量 CLI 参数(dnfs.ini 字段全部可 CLI 覆盖)
- 新增 --db-host/--db-port/--db-timeout - 新增 --review-url/--review-timeout - 新增 --gateway-url/--gateway-timeout - 新增 --no-confs 开关:跳过 confs 拉取,完全靠 CLI + ENV + 默认值 - services.yaml: dnfs2 启用 --no-confs,所有配置写进 args
This commit is contained in:
1 parent
fc4e1c4a61
commit
22ade06114
2 files changed
+50
-2
No files matched your search
+24
-1
@@ -28,7 +28,30 @@ services:
|
|||||||
# --- 文件服务 ---
|
# --- 文件服务 ---
|
||||||
- name: dnfs2
|
- name: dnfs2
|
||||||
cmd: bash /opt/micro_servers/dnfs2/_run.sh
|
cmd: bash /opt/micro_servers/dnfs2/_run.sh
|
||||||
args: ["--instance", "dnfs2", "--log-level", "info"]
|
args:
|
||||||
|
- "--no-confs"
|
||||||
|
- "--instance"
|
||||||
|
- "dnfs2"
|
||||||
|
- "--log-level"
|
||||||
|
- "info"
|
||||||
|
- "--host"
|
||||||
|
- "127.0.0.1"
|
||||||
|
- "--port"
|
||||||
|
- "8006"
|
||||||
|
- "--db-host"
|
||||||
|
- "127.0.0.1"
|
||||||
|
- "--db-port"
|
||||||
|
- "8005"
|
||||||
|
- "--db-timeout"
|
||||||
|
- "10"
|
||||||
|
- "--review-url"
|
||||||
|
- "http://127.0.0.1:8007/review"
|
||||||
|
- "--review-timeout"
|
||||||
|
- "10"
|
||||||
|
- "--gateway-url"
|
||||||
|
- "http://127.0.0.1:8443/whoami"
|
||||||
|
- "--gateway-timeout"
|
||||||
|
- "5"
|
||||||
depends_on: [db2, ai_review]
|
depends_on: [db2, ai_review]
|
||||||
sleep_before: 0
|
sleep_before: 0
|
||||||
|
|
||||||
|
|||||||
+26
-1
@@ -171,6 +171,7 @@ struct Config {
|
|||||||
std::string instance = "dnfs2";
|
std::string instance = "dnfs2";
|
||||||
std::string log_level = "info"; // debug|info|warn|error
|
std::string log_level = "info"; // debug|info|warn|error
|
||||||
std::string confs_config_name = "dnfs.ini"; // --config 覆盖
|
std::string confs_config_name = "dnfs.ini"; // --config 覆盖
|
||||||
|
bool no_confs = false; // --no-confs: 跳过 confs 拉取
|
||||||
};
|
};
|
||||||
|
|
||||||
static Config load_config(int argc, char* argv[]) {
|
static Config load_config(int argc, char* argv[]) {
|
||||||
@@ -187,14 +188,24 @@ static Config load_config(int argc, char* argv[]) {
|
|||||||
" --host <addr> 绑定地址(别名: --addr/-a),默认 127.0.0.1\n"
|
" --host <addr> 绑定地址(别名: --addr/-a),默认 127.0.0.1\n"
|
||||||
" --port <num> 监听端口(别名: -p),默认 8006\n"
|
" --port <num> 监听端口(别名: -p),默认 8006\n"
|
||||||
" --threads <num> 工作线程数(别名: -t),默认 4\n"
|
" --threads <num> 工作线程数(别名: -t),默认 4\n"
|
||||||
|
" --db-host <addr> 数据库地址,默认 127.0.0.1\n"
|
||||||
|
" --db-port <num> 数据库端口,默认 8005\n"
|
||||||
|
" --db-timeout <sec> 数据库超时秒数,默认 10\n"
|
||||||
|
" --review-url <url> AI 审核服务 URL,默认 http://127.0.0.1:8007/review\n"
|
||||||
|
" --review-timeout <sec> AI 审核超时秒数,默认 10\n"
|
||||||
|
" --gateway-url <url> 网关验签 URL,默认 http://127.0.0.1:8443/whoami\n"
|
||||||
|
" --gateway-timeout <sec> 网关超时秒数,默认 5\n"
|
||||||
" --config <name> confs 拉取的配置名,默认 dnfs.ini\n"
|
" --config <name> confs 拉取的配置名,默认 dnfs.ini\n"
|
||||||
|
" --no-confs 跳过 confs 拉取,完全依赖 CLI + ENV + 默认值\n"
|
||||||
" --log-level <level> debug|info|warn|error,默认 info\n"
|
" --log-level <level> debug|info|warn|error,默认 info\n"
|
||||||
" --instance <name> 实例名(注册中心用),默认 dnfs2\n"
|
" --instance <name> 实例名(注册中心用),默认 dnfs2\n"
|
||||||
" --help, -h 显示此帮助并退出\n\n"
|
" --help, -h 显示此帮助并退出\n\n"
|
||||||
"配置优先级: CLI > 环境变量 > confs > 默认值\n");
|
"配置优先级: CLI > 环境变量 > confs > 默认值\n"
|
||||||
|
"使用 --no-confs 时跳过 confs,优先级变为: CLI > 环境变量 > 默认值\n");
|
||||||
std::exit(0);
|
std::exit(0);
|
||||||
}
|
}
|
||||||
if (arg == "--config" && i + 1 < argc) cfg.confs_config_name = argv[++i];
|
if (arg == "--config" && i + 1 < argc) cfg.confs_config_name = argv[++i];
|
||||||
|
if (arg == "--no-confs") cfg.no_confs = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. confs 引导地址
|
// 1. confs 引导地址
|
||||||
@@ -208,6 +219,8 @@ static Config load_config(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. 从 confs 拉取配置文件(retry_on_refused=true,等待 confs 就绪)
|
// 2. 从 confs 拉取配置文件(retry_on_refused=true,等待 confs 就绪)
|
||||||
|
// --no-confs 模式下跳过,直接用 ENV + CLI + 默认值
|
||||||
|
if (!cfg.no_confs) {
|
||||||
std::string ini_text;
|
std::string ini_text;
|
||||||
try {
|
try {
|
||||||
RpcClient confs_client(cfg.confs_host, cfg.confs_port, "dnfs2",
|
RpcClient confs_client(cfg.confs_host, cfg.confs_port, "dnfs2",
|
||||||
@@ -261,6 +274,7 @@ static Config load_config(int argc, char* argv[]) {
|
|||||||
cfg.review_timeout = std::stod(get("ai_review", "timeout", std::to_string(cfg.review_timeout)));
|
cfg.review_timeout = std::stod(get("ai_review", "timeout", std::to_string(cfg.review_timeout)));
|
||||||
cfg.gateway_url = get("gateway", "url", cfg.gateway_url);
|
cfg.gateway_url = get("gateway", "url", cfg.gateway_url);
|
||||||
cfg.gateway_timeout = std::stod(get("gateway", "timeout", std::to_string(cfg.gateway_timeout)));
|
cfg.gateway_timeout = std::stod(get("gateway", "timeout", std::to_string(cfg.gateway_timeout)));
|
||||||
|
}
|
||||||
|
|
||||||
// 4. 环境变量覆盖(Docker 兼容)
|
// 4. 环境变量覆盖(Docker 兼容)
|
||||||
if (const char* v = std::getenv("LISTEN_ADDR")) cfg.listen_host = v;
|
if (const char* v = std::getenv("LISTEN_ADDR")) cfg.listen_host = v;
|
||||||
@@ -276,6 +290,13 @@ static Config load_config(int argc, char* argv[]) {
|
|||||||
if ((arg == "--addr" || arg == "-a" || arg == "--host") && i + 1 < argc) cfg.listen_host = argv[++i];
|
if ((arg == "--addr" || arg == "-a" || arg == "--host") && i + 1 < argc) cfg.listen_host = argv[++i];
|
||||||
else if ((arg == "--port" || arg == "-p") && i + 1 < argc) cfg.listen_port = safe_stoi(argv[++i], "--port");
|
else if ((arg == "--port" || arg == "-p") && i + 1 < argc) cfg.listen_port = safe_stoi(argv[++i], "--port");
|
||||||
else if ((arg == "--threads" || arg == "-t") && i + 1 < argc) cfg.threads = safe_stoi(argv[++i], "--threads");
|
else if ((arg == "--threads" || arg == "-t") && i + 1 < argc) cfg.threads = safe_stoi(argv[++i], "--threads");
|
||||||
|
else if (arg == "--db-host" && i + 1 < argc) cfg.db_host = argv[++i];
|
||||||
|
else if (arg == "--db-port" && i + 1 < argc) cfg.db_port = safe_stoi(argv[++i], "--db-port");
|
||||||
|
else if (arg == "--db-timeout" && i + 1 < argc) cfg.db_timeout = std::stod(argv[++i]);
|
||||||
|
else if (arg == "--review-url" && i + 1 < argc) cfg.review_url = argv[++i];
|
||||||
|
else if (arg == "--review-timeout" && i + 1 < argc) cfg.review_timeout = std::stod(argv[++i]);
|
||||||
|
else if (arg == "--gateway-url" && i + 1 < argc) cfg.gateway_url = argv[++i];
|
||||||
|
else if (arg == "--gateway-timeout" && i + 1 < argc) cfg.gateway_timeout = std::stod(argv[++i]);
|
||||||
else if (arg == "--log-level" && i + 1 < argc) cfg.log_level = argv[++i];
|
else if (arg == "--log-level" && i + 1 < argc) cfg.log_level = argv[++i];
|
||||||
else if (arg == "--instance" && i + 1 < argc) cfg.instance = argv[++i];
|
else if (arg == "--instance" && i + 1 < argc) cfg.instance = argv[++i];
|
||||||
}
|
}
|
||||||
@@ -539,9 +560,13 @@ public:
|
|||||||
);
|
);
|
||||||
_log_queue->start();
|
_log_queue->start();
|
||||||
|
|
||||||
|
if (cfg.no_confs) {
|
||||||
|
std::printf("[dnfs2] 配置来源: CLI + ENV + 默认值(--no-confs 模式)\n");
|
||||||
|
} else {
|
||||||
std::printf("[dnfs2] 配置来源: confs (%s @ %s:%d)\n",
|
std::printf("[dnfs2] 配置来源: confs (%s @ %s:%d)\n",
|
||||||
_cfg.confs_config_name.c_str(),
|
_cfg.confs_config_name.c_str(),
|
||||||
_cfg.confs_host.c_str(), _cfg.confs_port);
|
_cfg.confs_host.c_str(), _cfg.confs_port);
|
||||||
|
}
|
||||||
std::printf("[dnfs2] instance=%s log-level=%s\n",
|
std::printf("[dnfs2] instance=%s log-level=%s\n",
|
||||||
_cfg.instance.c_str(), _cfg.log_level.c_str());
|
_cfg.instance.c_str(), _cfg.log_level.c_str());
|
||||||
std::printf("[dnfs2] Token 验签: gateway %s\n", _cfg.gateway_url.c_str());
|
std::printf("[dnfs2] Token 验签: gateway %s\n", _cfg.gateway_url.c_str());
|
||||||
|
|||||||
Reference in new issue
Block a user