跳到主要内容

arc attach

arc attach 把本地目录反向挂载进一个远程 arc daemon,当成一个 provider 暴露出去,让一台你没有 shell 权限的机器能通过 AFS 读到你本地的文件。

arc attach 把本地目录反向挂载进一个远程 arc daemon,在那台远程 daemon 的 /modules/{namespace} 下暴露成一个 provider。这跟 arc afs mount 方向相反:不是把远程的东西挂进本地 AFS,而是把本地的东西让远程 AFS 看得到。

用法

bash
arc attach --to <url> [options]

严格必填的只有 --to;还需要传什么取决于你要挂的是下面三种东西里的哪一种:

  • 目录 attach(默认那种):--namespace <name> + --source <dir>——把本地目录暴露成一个挂在远程 /modules/{namespace} 下的 provider
  • host attach--as-host——把这台主机的 HostFace 导出到远程的 /peers/{peer.json.id}(不需要 --namespace/--source)
  • engine attach:单独用 --as-engine <name>——以这个 id 挂一个裸的 code-agents engine;和 --as-host 搭配用时,它只是显示用的元数据

选项

  • --to <url>(必填):目标 daemon 的 URL,比如 ws://host:4900ws://host:4900/ws/attach
  • --namespace <name>:在目标上暴露用的 namespace,挂在 /modules/{namespace} 下(目录 attach 用)
  • --source <dir>:要暴露成 provider 的本地目录(目录 attach 用)
  • --as-engine <name>:单独的 engine id;配合 --as-host 用时只是显示元数据(远程 id 用的是 peer.jsonid)
  • --as-host:把这台主机的 HostFace 导出到目标的 /peers/{peer.json.id}
  • --readonly:把这个源暴露成只读(目录 attach 用)
  • --replace:替换这个 namespace 下已存在的 session
  • --token <token>:远程 daemon 的所有者访问令牌(本地回环目标可以跳过)
  • --browser:为授权流程打开浏览器(默认 true);配合 --token--no-browser 用于无人值守场景
  • --json:在 stdout 打印机器可读的事件,而不是默认的人类文本
  • --view:输出 view 格式(json 等价于 --json
  • --instance <name> / -i:这条命令作用在哪个本地 ARC 实例;省略即 default
  • --home <dir>:实例根(这台主机的 peer.json 和凭证放在哪;通常用不到)。要指定作用在哪个实例,用 --instance

按 Ctrl+C(SIGINT)时,arc attach 会优雅地断开,让远程那边干净地卸载。

示例

bash
arc attach --to ws://host:4900 --namespace my-local-src --source ./src --readonly
arc attach --to ws://host:4900 --as-host

--json

加了 --json 之后,每一条进度行(Attaching...to:namespace:source:Press Ctrl+C to detach.Detaching...)都挪到 stderr,stdout 只留下按行分隔的 JSON 事件——脚本 pipe arc attach ... --json 的 stdout 时可以直接当纯 JSON 解析,不用过滤掉人类可读的文字:

bash
$ arc attach --to ws://127.0.0.1:PORT/ws/attach --source /tmp --namespace test --json

stdout(成功 attach 时只有这一行):

json
{"event":"attached","sessionId":"sess_test_...","namespace":"test","targetPath":"/modules/test"}

stderr(全部进度,banner 已省略):

Attaching...
  to:        ws://127.0.0.1:PORT/ws/attach
  namespace: test
  source:    /tmp
Press Ctrl+C to detach.

失败的时候,--json 并不会在 stdout 多出一个对应的 JSON 对象——stdout 留空,报错依然只是 stderr 上那行人类文本 ERROR: ...,缺必需参数组合和连接失败都是这样,退出码都是 5

bash
$ arc attach --to ws://127.0.0.1:1/ws/attach --source /tmp --json

stdout:(空)

stderr:

ERROR: attach requires --namespace and --source, or --as-engine, or --as-host
bash
$ arc attach --to ws://127.0.0.1:9/ws/attach --namespace test --source /tmp --json

stdout:(空)

stderr:

Attaching...
  to:        ws://127.0.0.1:9/ws/attach
  namespace: test
  source:    /tmp
ERROR: attach failed [cockpit-unreachable]: connect ECONNREFUSED 127.0.0.1:9