From 7fdfe902916fe9cb1bb2b0774c67251c9553d661 Mon Sep 17 00:00:00 2001 From: fanyang Date: Fri, 9 Oct 2026 21:23:02 +0800 Subject: [PATCH] feat(cli): support configurable local state directory (#2654) Add --state-dir and ET_STATE_DIR for persisted web-client machine IDs. Fixes #2340 --- easytier/locales/app.yml | 3 +++ easytier/src/core.rs | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/easytier/locales/app.yml b/easytier/locales/app.yml index d20b243a..f9bbf306 100644 --- a/easytier/locales/app.yml +++ b/easytier/locales/app.yml @@ -13,6 +13,9 @@ core_clap: the machine id to identify this machine, used for config recovery after disconnection, must be unique and fixed. by default it is loaded from persisted local state; on first start it may be migrated from system information or generated, then remains fixed. zh-CN: |+ Web 配置服务器通过 machine id 来识别机器,用于断线重连后的配置恢复,需要保证唯一且固定不变。默认从本地持久化状态读取;首次启动时可能基于系统信息迁移或生成,之后保持固定不变。 + state_dir: + en: "directory for persistent local state, currently used for the Web config server machine ID. Uses the platform default when unset; ignored when --machine-id is specified." + zh-CN: "本地持久化状态目录,目前用于保存 Web 配置服务器的机器 ID。未指定时使用平台默认目录;指定 --machine-id 时不使用此目录。" config_file: en: "path to the config file, NOTE: the options set by cmdline args will override options in config file" zh-CN: "配置文件路径,注意:命令行中的配置的选项会覆盖配置文件中的选项" diff --git a/easytier/src/core.rs b/easytier/src/core.rs index f2adf9e3..29e1d159 100644 --- a/easytier/src/core.rs +++ b/easytier/src/core.rs @@ -100,6 +100,13 @@ struct Cli { )] machine_id: Option, + #[arg( + long, + env = "ET_STATE_DIR", + help = t!("core_clap.state_dir").to_string() + )] + state_dir: Option, + #[arg( short, long, @@ -1536,7 +1543,7 @@ async fn run_main(cli: Cli) -> anyhow::Result<()> { config_server_url_s, crate::common::MachineIdOptions { explicit_machine_id: cli.machine_id.clone(), - state_dir: None, + state_dir: cli.state_dir.clone(), }, cli.network_options.hostname.clone(), cli.network_options.secure_mode.unwrap_or(false),