arc attach 把本地目錄反向掛載進一個遠端 arc daemon,在那臺遠端 daemon 的 /modules/{namespace} 下暴露成一個 provider。這跟 arc afs mount 方向相反:不是把遠端的東西掛進本地 AFS,而是把本地的東西讓遠端 AFS 看得到。
用法
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:4900或ws://host:4900/ws/attach--namespace <name>:在目標上暴露用的 namespace,掛在/modules/{namespace}下(目錄 attach 用)--source <dir>:要暴露成 provider 的本地目錄(目錄 attach 用)--as-engine <name>:單獨的 engine id;配合--as-host用時只是顯示後設資料(遠端 id 用的是peer.json的id)--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 會優雅地斷開,讓遠端那邊乾淨地解除安裝。
示例
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 解析,不用過濾掉人類可讀的文字:
$ arc attach --to ws://127.0.0.1:PORT/ws/attach --source /tmp --namespace test --jsonstdout(成功 attach 時只有這一行):
{"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:
$ arc attach --to ws://127.0.0.1:1/ws/attach --source /tmp --jsonstdout:(空)
stderr:
ERROR: attach requires --namespace and --source, or --as-engine, or --as-host$ arc attach --to ws://127.0.0.1:9/ws/attach --namespace test --source /tmp --jsonstdout:(空)
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