后台持续运行
请选择 其中一种 方式来托管 Daemon 进程。每种方式都拥有进程的生命周期控制权,请勿混用。
在任何操作系统上都最简单的方案。它会为当前用户在后台守护启动 wx serve。
wx daemon startwx daemon statuswx daemon logs --followwx daemon stop支持异常崩溃自动重启,并随用户登录会话启动。安装官方示例 用户服务文件:
mkdir -p ~/.config/systemd/user ~/.config/agent-wechat/servercurl -fsSLo ~/.config/systemd/user/agent-wechat-native.service \ https://raw.githubusercontent.com/thisnick/agent-wechat/main/deploy/native/agent-wechat-native.servicetest -f ~/.config/agent-wechat/server/config.toml || echo 'schemaVersion = 1' > ~/.config/agent-wechat/server/config.toml在启用服务前,请检查并调整配置:
ExecStart=默认执行~/.local/bin/wx。若command -v wx路径不同请修改。- 如果你是通过
--official登录的,请将微信目录添加到ReadWritePaths=中,例如%h/xwechat_files %h/.xwechat。默认配置下该服务单元仅对~/.local/share/agent-wechat拥有写权限。
systemctl --user daemon-reloadsystemctl --user enable --now agent-wechat-native在无图形界面的服务器上,请执行 loginctl enable-linger,使 systemd 用户服务在未登录时依然保持运行。
基于示例配置 compose.yaml 与 server.toml 开始:
-
将
image:指定为ghcr.io/thisnick/agent-wechat-native:latest并移除build:部分。 -
创建 API 访问令牌:一份供本地 CLI 使用,一份归属容器内部用户(UID 10001)。
Terminal window umask 077; mkdir -p ~/.config/agent-wechat secretshead -c 32 /dev/urandom | base64 > ~/.config/agent-wechat/box-tokensudo install -m 600 -o 10001 -g 10001 ~/.config/agent-wechat/box-token secrets/api-token -
启动容器并从宿主机登录:
Terminal window docker compose up -dwx config servers add box --url http://127.0.0.1:6174 \--token-file ~/.config/agent-wechat/box-tokenwx --server-name box accounts create --alias mewx --server-name box auth login
如需使用现有的 Linux 版微信数据,将包含 xwechat_files 和 .xwechat 的目录以挂载卷的形式挂载到 volumes:(例如 /home/you:/profiles/wechat),然后使用 --official=/profiles/wechat 登录。容器以 UID 10001 运行,需确保该用户拥有目录读写权限。
在 macOS 和 Windows 上,Docker Desktop 可以运行相同的镜像。由于示例采用了 host 网络模式,请在 Settings › Resources › Network 中启用对应支持。