ssh-net 26.10.57 → 26.10.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -6
- package/README.md +37 -27
- package/libexec/cli.mjs +30 -47
- package/libexec/commands/install.mjs +13 -31
- package/libexec/commands/start.mjs +9 -15
- package/libexec/commands/status.mjs +16 -38
- package/libexec/commands/stop.mjs +17 -63
- package/libexec/commands/uninstall.mjs +13 -73
- package/libexec/commands/update.mjs +10 -36
- package/libexec/lib/jobctl.mjs +2 -3
- package/libexec/lib/manage.mjs +13 -15
- package/libexec/lib/paths.mjs +5 -4
- package/libexec/lib/runtime.mjs +25 -64
- package/libexec/lib/systemd.mjs +4 -3
- package/libexec/sn-route +14 -23
- package/package.json +1 -1
- package/libexec/lib/cliargs.mjs +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,14 +1,38 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
跳号至 26.9.17 对齐累计数,13–16 永久空缺)。发布 = 改版本号 + 发
|
|
7
|
-
GitHub Release(Actions 自动跑测试后 npm publish;跳号与 0.x 的完整
|
|
8
|
-
考据见 git 史)。
|
|
3
|
+
本项目使用 npm 公共分发,版本号格式为**年.月.序号**:月内序号递增,
|
|
4
|
+
跨月从 1 开始;历史跳号不补、不另维护累计发包数。发布 = 改版本号 +
|
|
5
|
+
CHANGELOG + 发 GitHub Release,Actions 跑测试后 npm publish。
|
|
9
6
|
|
|
10
7
|
## [Unreleased]
|
|
11
8
|
|
|
9
|
+
## [26.10.59] - 2026-10-25
|
|
10
|
+
|
|
11
|
+
### 简化
|
|
12
|
+
|
|
13
|
+
- install/status 的对账只汇总有无变化,core 的 edge 任务直接列 launchd
|
|
14
|
+
事实;删除 runtime-version 版本戳与 update 后置校验,旧文件由 install
|
|
15
|
+
和 uninstall 清理
|
|
16
|
+
- stop/uninstall 始终按磁盘 job/unit 操作,不再读取 topology 或维护独立
|
|
17
|
+
恢复模式;stop peer 仍只关闭主动恢复,系统查询与停止失败照常报错
|
|
18
|
+
- sn-route 的 follower 本轮不再接管被杀的 leader,ENSURE 改为空锁文件;
|
|
19
|
+
并发仍只报一次名,失败印记过期后的下一条连接负责重试
|
|
20
|
+
- update 保留明确版本安装与防降级,删除 ETARGET 专属分支和升级/降级
|
|
21
|
+
措辞;publish 删除 latest 防反超检查,不补历史 Release,版本号按月编号
|
|
22
|
+
|
|
23
|
+
### 发布纪律
|
|
24
|
+
|
|
25
|
+
- 明确「发布」包含提交、合并回 main、推送、GitHub Release 与在线机器升级
|
|
26
|
+
|
|
27
|
+
## [26.10.58] - 2026-10-25
|
|
28
|
+
|
|
29
|
+
### 文档与文案
|
|
30
|
+
|
|
31
|
+
- README 按角色补齐安装与卸载命令,增加办公室/外出切换入口;修正端口、
|
|
32
|
+
FileVault 恢复和 BTM 实测表述,收敛 README、design 与 notes 的重复内容
|
|
33
|
+
- 精简命令帮助;node 安装与卸载的权限错误直接提示可执行的 `sudo -i` 命令
|
|
34
|
+
- 发布流程明确包含在线机器升级与版本、状态核对;npm link 开发机只重跑 install
|
|
35
|
+
|
|
12
36
|
## [26.10.57] - 2026-10-24
|
|
13
37
|
|
|
14
38
|
### 简化
|
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@ Linux devbox(node),也让 core/node 能连回 edge。五台工作机之外
|
|
|
16
16
|
反向 core / node ── 最近登记的入口地址 ──► edge
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
-
|
|
20
|
-
|
|
19
|
+
- 外出到 core 优先使用 IPv6 回连;通知并等待回连的预算为 6 秒,未就绪时
|
|
20
|
+
本次连接走中继,后续连接自动重试;外出到 node 走中继
|
|
21
21
|
- edge 默认没有常驻连接进程;发起 ssh 时才选路。core/node 到中继的通道常驻
|
|
22
22
|
- edge 合盖或关机后,core 最多再拨两次,随后休眠;edge 下次发起 ssh 或执行
|
|
23
23
|
`ssh-net start peer` 时唤醒
|
|
@@ -41,8 +41,9 @@ Linux devbox(node),也让 core/node 能连回 edge。五台工作机之外
|
|
|
41
41
|
|
|
42
42
|
首次安装前完成这些准备:
|
|
43
43
|
|
|
44
|
-
1. 五台工作机都有 Node 24
|
|
45
|
-
|
|
44
|
+
1. 五台工作机都有 Node 24+ 和 npm,非交互 SSH 的 PATH 已包含 npm 全局 bin,
|
|
45
|
+
保证安装后能找到 `ssh-net`;node 的管理命令统一通过 `sudo -i` 运行,避免
|
|
46
|
+
sudo 的 `secure_path` 丢掉 fnm 路径
|
|
46
47
|
2. 运行 `dot apply ssh`,落盘 `~/.ssh/ssh-net/topology`、静态 Host 块,以及
|
|
47
48
|
位于所有 Host 块之前的 `Include ~/.ssh/ssh-net/conf.d/*`。topology 管名称、
|
|
48
49
|
用户和端口,静态 IP 只放在 `~/.ssh/config`;格式见 [design §4](docs/design.md#4-个人配置dotfiles-托管)
|
|
@@ -53,19 +54,23 @@ Linux devbox(node),也让 core/node 能连回 edge。五台工作机之外
|
|
|
53
54
|
|
|
54
55
|
## 安装
|
|
55
56
|
|
|
57
|
+
core、edge 以普通用户执行:
|
|
58
|
+
|
|
56
59
|
```bash
|
|
57
60
|
npm install -g ssh-net
|
|
61
|
+
ssh-net install
|
|
58
62
|
```
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
node 以 root 登录环境执行:
|
|
61
65
|
|
|
62
66
|
```bash
|
|
63
|
-
|
|
64
|
-
ssh-net install
|
|
65
|
-
|
|
66
|
-
# node:root 登录环境
|
|
67
|
+
sudo -i npm install -g ssh-net
|
|
67
68
|
sudo -i ssh-net install
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
安装后检查(node 的下列命令同样加 `sudo -i`):
|
|
68
72
|
|
|
73
|
+
```bash
|
|
69
74
|
# edge:首次安装后开启中继与 IPv6 直连
|
|
70
75
|
ssh-net start
|
|
71
76
|
|
|
@@ -97,13 +102,15 @@ cd ~/space/ssh-net && npm link
|
|
|
97
102
|
|
|
98
103
|
### edge
|
|
99
104
|
|
|
105
|
+
edge 不自动判断所在网络,按下面的场景与需求手动操作:
|
|
106
|
+
|
|
100
107
|
| 命令 | 行为 |
|
|
101
108
|
| --- | --- |
|
|
102
|
-
| `ssh-net start` |
|
|
109
|
+
| `ssh-net start` | 外出:开启 relay + peer,并立即检查、恢复 IPv6 直连(同 `start peer`) |
|
|
110
|
+
| `ssh-net stop` | 办公室:关闭 relay + peer 和本地转发,ssh 改用静态 LAN 地址;core 在现有连接退出后停止重试 |
|
|
103
111
|
| `ssh-net start relay` | 只开启 relay,不改变 peer;peer 已开时仍会自动恢复直连,已关时保持关闭 |
|
|
104
112
|
| `ssh-net start peer` | 补上 relay + peer,跳过近期失败印记并等待本次直连结果;重复执行可立即重试 |
|
|
105
113
|
| `ssh-net stop peer` | 停止主动恢复;现有直连断开前仍可供新 ssh 使用,断开后走中继 |
|
|
106
|
-
| `ssh-net stop` | 关闭 relay + peer 和本地转发;core 在现有连接退出后停止重试 |
|
|
107
114
|
| `ssh-net status` | 默认本地快查开关、后台任务、本地转发和安装产物,不做线路实测 |
|
|
108
115
|
| `ssh-net status --probe` | 在本地检查基础上实测 relay、peer 和已安装的转发口 |
|
|
109
116
|
|
|
@@ -120,8 +127,8 @@ cd ~/space/ssh-net && npm link
|
|
|
120
127
|
edge 的通知和两次重试机制自动管理,不需要手动干预;node 的中继服务由 systemd
|
|
121
128
|
自动重启。需要手动重拉中继时,先 `stop` 再 `start`
|
|
122
129
|
|
|
123
|
-
core 的 status 中,edge
|
|
124
|
-
|
|
130
|
+
core 的 status 中,edge 行只列出**自动连接任务**的注册、运行、休眠和上次
|
|
131
|
+
退出事实,不表示 SSH 线路已经连通;下方「ssh 入口」是最近登记的地址及其新旧
|
|
125
132
|
|
|
126
133
|
### 退出码
|
|
127
134
|
|
|
@@ -143,30 +150,39 @@ ssh-net update <版本号> # 切换或回滚;显式当前版也会重跑 i
|
|
|
143
150
|
- 无参确认已最新时不会重装或修复组件;需要按当前版重新同步时,显式运行
|
|
144
151
|
`ssh-net update <当前版本>`,或直接运行 `ssh-net install`
|
|
145
152
|
- 查询失败或 registry 返回比当前更旧的版本时,在安装前停止,不退回 `@latest`;
|
|
146
|
-
|
|
153
|
+
安装失败直接保留 npm 原因,刚发布遇到 ETARGET 时等几分钟,用同一明确版本号重试
|
|
147
154
|
- node 使用 `sudo -i ssh-net update`;开发机的 `npm link` 状态不要用 update
|
|
148
155
|
- **core/node 升级会恢复此前 stop 的中继服务**;维护停机期间不要顺手升级
|
|
149
156
|
- 已在运行的进程只在下次重连后使用更新后的运行时脚本;服务配置变化或用
|
|
150
157
|
`stop` 后 `start` 手动重拉可能断开当前连接
|
|
151
158
|
|
|
152
|
-
##
|
|
159
|
+
## 配置缺失时停止与卸载
|
|
153
160
|
|
|
154
161
|
`install`、`update`、`status` 等命令需要有效 topology、静态 Host 配置和本机
|
|
155
162
|
主机名匹配;修复配置运行 `dot apply ssh`
|
|
156
163
|
|
|
157
|
-
`stop`、`uninstall`
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
`stop`、`uninstall` 始终不读 topology,只按磁盘上的 ssh-net job/unit 操作,
|
|
165
|
+
配置正常与损坏时走同一条路径。`stop peer` 仍只关闭主动恢复;其余 stop 形式
|
|
166
|
+
级联清除 relay/peer 并停止本机中继与本地转发任务。系统查询或服务停止失败
|
|
167
|
+
仍会报错,不会假装成功。若 plist/unit 也被手删,需用 launchctl/systemctl
|
|
168
|
+
检查系统注册表里的残留
|
|
162
169
|
|
|
163
170
|
## 卸载
|
|
164
171
|
|
|
172
|
+
core、edge:
|
|
173
|
+
|
|
165
174
|
```bash
|
|
166
175
|
ssh-net uninstall
|
|
167
176
|
npm uninstall -g ssh-net
|
|
168
177
|
```
|
|
169
178
|
|
|
179
|
+
node:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
sudo -i ssh-net uninstall
|
|
183
|
+
sudo -i npm uninstall -g ssh-net
|
|
184
|
+
```
|
|
185
|
+
|
|
170
186
|
顺序不能反过来:npm 不负责删除 launchd/systemd 任务。先卸包会留下重复重启的
|
|
171
187
|
注册任务和失效脚本路径
|
|
172
188
|
|
|
@@ -185,19 +201,13 @@ npm uninstall -g ssh-net
|
|
|
185
201
|
|
|
186
202
|
| 文件 | 内容 |
|
|
187
203
|
| --- | --- |
|
|
188
|
-
| [docs/design.md](docs/design.md) |
|
|
204
|
+
| [docs/design.md](docs/design.md) | 角色与路径、配置契约、设计理由与一次性准备 |
|
|
189
205
|
| [docs/notes.md](docs/notes.md) | 仍有效的实测、排障和已知边界;已修复且无现行价值的记录移出 |
|
|
190
206
|
| [CHANGELOG.md](CHANGELOG.md) | 版本历史与升级注意事项 |
|
|
191
207
|
|
|
192
|
-
运行时代码、模板默认值和测试 fixture 不写真实 IP、主机公钥或指纹;私有运维
|
|
193
|
-
文档与 CHANGELOG 可含个人别名,真实 IP 和密钥仍只放 dotfiles
|
|
194
|
-
|
|
195
208
|
开发要求 Node 24+,零依赖、零构建:
|
|
196
209
|
|
|
197
210
|
```bash
|
|
198
211
|
node --test
|
|
199
212
|
npm pack --dry-run
|
|
200
213
|
```
|
|
201
|
-
|
|
202
|
-
发布通过 GitHub Release 触发测试和 npm publish,不在本地发布。当前版本与历史
|
|
203
|
-
见 [CHANGELOG.md](CHANGELOG.md)
|
package/libexec/cli.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// ssh-net 控制面入口:参数路由 + buildContext。业务都在 lib/ 与 commands/,
|
|
3
3
|
// 本文件只做装配、帮助与错误边界。
|
|
4
4
|
import os from 'node:os';
|
|
5
|
-
import {
|
|
5
|
+
import { parseTopology, validateHostContract } from './lib/config.mjs';
|
|
6
6
|
import { parseStaticHosts } from './lib/sshconfig.mjs';
|
|
7
7
|
import { localHostname, matchIdentity } from './lib/identity.mjs';
|
|
8
8
|
import { machinePaths } from './lib/paths.mjs';
|
|
@@ -20,12 +20,12 @@ import { runRegister as registerRun } from './commands/register.mjs';
|
|
|
20
20
|
import { run as updateRun } from './commands/update.mjs';
|
|
21
21
|
|
|
22
22
|
const COMMANDS = {
|
|
23
|
-
install: { run: installRun, desc: '
|
|
24
|
-
update: { run: updateRun, desc: '
|
|
25
|
-
uninstall: { run: uninstallRun, desc: '
|
|
26
|
-
start: { run: startRun, desc: 'edge
|
|
27
|
-
stop: { run: stopRun, desc: '
|
|
28
|
-
status: { run: statusRun, desc: '
|
|
23
|
+
install: { run: installRun, desc: '安装或修复本机组件;edge 可选 --with-link/--without-link' },
|
|
24
|
+
update: { run: updateRun, desc: '升级或按版本号切换并同步组件;core/node 会恢复中继服务' },
|
|
25
|
+
uninstall: { run: uninstallRun, desc: '按磁盘任务停止并删除本机组件;之后再 npm uninstall -g' },
|
|
26
|
+
start: { run: startRun, desc: '启动中继;edge 默认同时恢复 IPv6 直连(relay|peer)' },
|
|
27
|
+
stop: { run: stopRun, desc: '按磁盘任务停止中继与本地转发;peer 仅关闭自动恢复' },
|
|
28
|
+
status: { run: statusRun, desc: '查看本机状态;--probe 增加线路实测' },
|
|
29
29
|
_register: { run: registerRun, internal: true, desc: '内部 RPC(core):接收 edge 的连接通知,建/唤自动连接任务' },
|
|
30
30
|
};
|
|
31
31
|
|
|
@@ -40,30 +40,41 @@ function help() {
|
|
|
40
40
|
.map(([name, c]) => ` ${name.padEnd(10)} ${c.desc}`),
|
|
41
41
|
'',
|
|
42
42
|
'配置:~/.ssh/ssh-net/topology 与 ~/.ssh/config(由 dot apply ssh 生成)',
|
|
43
|
-
'
|
|
43
|
+
'stop/uninstall 只按磁盘任务操作,不读配置;角色差异与日常示例见 README',
|
|
44
44
|
];
|
|
45
45
|
return lines.join('\n');
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/** 配置或本机身份不满足正常命令前提;stop/uninstall 可据此转磁盘恢复模式。 */
|
|
49
|
-
const contextError = (message) => new ConfigError(0, message);
|
|
50
|
-
|
|
51
|
-
/** 读取配置文件的 IO 失败也属于可恢复的配置前提,不把系统错误原样抛成死路。 */
|
|
52
48
|
function readConfig(file) {
|
|
53
49
|
try {
|
|
54
50
|
return readFileOrNull(file);
|
|
55
51
|
} catch (err) {
|
|
56
|
-
throw
|
|
52
|
+
throw new Error(`无法读取配置 ${file}(${err.code ?? '未知错误'}):${err.message}`);
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
55
|
|
|
60
|
-
/**
|
|
61
|
-
function
|
|
56
|
+
/** 停止/卸载与正常命令共用的本机上下文;前者只使用这些磁盘与系统接口。 */
|
|
57
|
+
function buildBaseContext() {
|
|
62
58
|
const env = process.env;
|
|
63
59
|
const paths = machinePaths(env);
|
|
60
|
+
return {
|
|
61
|
+
env,
|
|
62
|
+
paths,
|
|
63
|
+
runner: createRunner(env),
|
|
64
|
+
progress: (message) => process.stderr.write(`${message}\n`),
|
|
65
|
+
state: createStateStore(paths),
|
|
66
|
+
uid: process.getuid(),
|
|
67
|
+
platform: process.platform,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** 装配需要 topology、本机身份与静态 Host 契约的命令上下文。 */
|
|
72
|
+
function buildContext() {
|
|
73
|
+
const base = buildBaseContext();
|
|
74
|
+
const { paths } = base;
|
|
64
75
|
const text = readConfig(paths.topologyFile);
|
|
65
76
|
if (text === null)
|
|
66
|
-
throw
|
|
77
|
+
throw new Error(`缺配置 ${paths.topologyFile}——先运行 dot apply ssh;stop/uninstall 不读配置,可直接执行`);
|
|
67
78
|
const topo = parseTopology(text);
|
|
68
79
|
|
|
69
80
|
// 静态主机表(IP 唯一来源);~/.ssh/config 缺失时给空表,契约校验报具体缺口
|
|
@@ -74,37 +85,15 @@ function buildContext() {
|
|
|
74
85
|
const hostname = localHostname(os.hostname());
|
|
75
86
|
const self = matchIdentity(topo, hostname);
|
|
76
87
|
if (!self)
|
|
77
|
-
throw
|
|
88
|
+
throw new Error(
|
|
78
89
|
`本机主机名 ${hostname} 不在 topology 的 host 行中(登记:${[...topo.byHostname.keys()].join('、')})`,
|
|
79
90
|
);
|
|
80
91
|
return {
|
|
81
|
-
|
|
82
|
-
paths,
|
|
92
|
+
...base,
|
|
83
93
|
topo,
|
|
84
94
|
hostTable,
|
|
85
95
|
self,
|
|
86
96
|
role: self.role,
|
|
87
|
-
runner: createRunner(env),
|
|
88
|
-
progress: (message) => process.stderr.write(`${message}\n`),
|
|
89
|
-
state: createStateStore(paths),
|
|
90
|
-
uid: process.getuid(),
|
|
91
|
-
platform: process.platform,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** 配置不可用时仍保留停止/卸载入口;恢复命令只能依赖磁盘产物,不读 topo。 */
|
|
96
|
-
function buildRecoveryContext(cause) {
|
|
97
|
-
const env = process.env;
|
|
98
|
-
const paths = machinePaths(env);
|
|
99
|
-
return {
|
|
100
|
-
env,
|
|
101
|
-
paths,
|
|
102
|
-
runner: createRunner(env),
|
|
103
|
-
progress: (message) => process.stderr.write(`${message}\n`),
|
|
104
|
-
state: createStateStore(paths),
|
|
105
|
-
uid: process.getuid(),
|
|
106
|
-
platform: process.platform,
|
|
107
|
-
configError: cause,
|
|
108
97
|
};
|
|
109
98
|
}
|
|
110
99
|
|
|
@@ -126,13 +115,7 @@ async function main() {
|
|
|
126
115
|
return 2;
|
|
127
116
|
}
|
|
128
117
|
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
ctx = buildContext();
|
|
132
|
-
} catch (err) {
|
|
133
|
-
if (!(err instanceof ConfigError) || !['stop', 'uninstall'].includes(cmd)) throw err;
|
|
134
|
-
ctx = buildRecoveryContext(err);
|
|
135
|
-
}
|
|
118
|
+
const ctx = ['stop', 'uninstall'].includes(cmd) ? buildBaseContext() : buildContext();
|
|
136
119
|
const result = await entry.run(ctx, argv.slice(1));
|
|
137
120
|
if (typeof result === 'string') {
|
|
138
121
|
process.stdout.write(`${result}\n`);
|
|
@@ -28,24 +28,14 @@ import {
|
|
|
28
28
|
renderEdgeHost, renderEdgeLinkPlist, renderRelayPlist, renderRelayUnit, renderRoutes,
|
|
29
29
|
} from '../lib/render.mjs';
|
|
30
30
|
|
|
31
|
-
/**
|
|
31
|
+
/** 对账只汇总有无变化;具体差异看文件与 launchd/systemd,不维护逐态文案。 */
|
|
32
32
|
function compNote(results, entities) {
|
|
33
|
-
|
|
34
|
-
created: '新拷脚本', updated: '更新脚本', repaired: '补执行权限',
|
|
35
|
-
linked: '新软链', relinked: '修正软链', replaced: '换为软链',
|
|
36
|
-
};
|
|
37
|
-
const counts = new Map();
|
|
38
|
-
for (const s of results) {
|
|
39
|
-
if (s === 'unchanged') continue;
|
|
40
|
-
counts.set(s, (counts.get(s) ?? 0) + 1);
|
|
41
|
-
}
|
|
42
|
-
if (counts.size === 0) return '';
|
|
43
|
-
const summary = `本次更新:${[...counts].map(([k, n]) => `${LABELS[k] ?? k} ${n} 个`).join('、')}`;
|
|
33
|
+
if (!results.some(Boolean)) return '';
|
|
44
34
|
const residentUpdated = entities.some(([name], i) =>
|
|
45
|
-
results[i]
|
|
35
|
+
results[i] && RESIDENT_SCRIPTS.includes(name));
|
|
46
36
|
return residentUpdated
|
|
47
|
-
?
|
|
48
|
-
:
|
|
37
|
+
? '后台脚本已同步,常驻进程将在下次重连后使用新版'
|
|
38
|
+
: '后台脚本已同步';
|
|
49
39
|
}
|
|
50
40
|
|
|
51
41
|
/** 安装结果文案:组件刷新/配置更新若干条 note 合并进一对括号(''=零附加信息)。 */
|
|
@@ -56,22 +46,18 @@ function notesPart(...notes) {
|
|
|
56
46
|
|
|
57
47
|
/** plist/unit 的同构部署结果统一变成用户可读的任务变化。 */
|
|
58
48
|
function deploymentNote(r, task, config) {
|
|
59
|
-
if (r.
|
|
60
|
-
|
|
61
|
-
if (r.revived) return `${task}已恢复`;
|
|
62
|
-
if (r.registered) return `${task}已注册`;
|
|
63
|
-
return '';
|
|
49
|
+
if (!r.changed) return '';
|
|
50
|
+
return r.restarted ? `${config}已更新,可能断开当前连接` : `${task}已同步`;
|
|
64
51
|
}
|
|
65
52
|
|
|
66
|
-
/** core/node 安装结果同构:服务配置未变只报刷新项,变了报中继通道已开启。 */
|
|
67
53
|
function coreNodeInstallMsg(comp, entryChanged, result, relayLine) {
|
|
68
54
|
const note = notesPart(
|
|
69
55
|
comp,
|
|
70
56
|
entryChanged ? 'edge 入口已更新' : '',
|
|
71
57
|
deploymentNote(result, '中继任务', '中继服务配置'),
|
|
72
58
|
);
|
|
73
|
-
if (
|
|
74
|
-
return
|
|
59
|
+
if (!note)
|
|
60
|
+
return `已安装,服务配置无需改动;中继通道已开启(${relayLine})`;
|
|
75
61
|
return `安装完成${note},中继通道已开启(${relayLine})`;
|
|
76
62
|
}
|
|
77
63
|
|
|
@@ -188,7 +174,7 @@ async function installEdge(ctx, args) {
|
|
|
188
174
|
});
|
|
189
175
|
const r = syncPlist(ctx, { label, plistPath, content });
|
|
190
176
|
if (r.lintError) throw new Error(`link plist 校验失败:${r.lintError}`);
|
|
191
|
-
linkChanged =
|
|
177
|
+
linkChanged = r.changed;
|
|
192
178
|
linkNote = deploymentNote(r, '本地转发任务', '本地转发配置');
|
|
193
179
|
} else {
|
|
194
180
|
// 默认零常驻:清掉加装过的 link 全部产物。plist 必须先 bootout,否则
|
|
@@ -207,13 +193,9 @@ async function installEdge(ctx, args) {
|
|
|
207
193
|
// 选路 Match 与尾部打标块(VS Code 标识 + 本机别名)
|
|
208
194
|
const routesChanged = syncConfFile(paths.routesFile, renderRoutes(topo, ctx.self.alias));
|
|
209
195
|
const depNote = localNotifyDepNote();
|
|
210
|
-
const head = linkOn
|
|
211
|
-
? '安装完成(含本地端口转发)'
|
|
212
|
-
: '安装完成(默认不安装本地端口转发;需要时运行 ssh-net install --with-link)';
|
|
196
|
+
const head = linkOn ? '安装完成(含本地端口转发)' : '安装完成';
|
|
213
197
|
const base = (!comp && !linkChanged && !routesChanged && flag === undefined)
|
|
214
|
-
?
|
|
215
|
-
? '已安装(本地端口转发已启用),无需改动'
|
|
216
|
-
: '已安装,无需改动(未安装本地端口转发)')
|
|
198
|
+
? '已安装,配置无需改动'
|
|
217
199
|
: `${head}${notesPart(comp, linkNote, routesChanged ? 'ssh 配置片段已更新' : '')}`;
|
|
218
200
|
const startNote = ctx.state.isOn('relay')
|
|
219
201
|
? ''
|
|
@@ -275,7 +257,7 @@ function installCore(ctx) {
|
|
|
275
257
|
function installNode(ctx) {
|
|
276
258
|
const { topo, paths, runner } = ctx;
|
|
277
259
|
if (ctx.uid !== 0)
|
|
278
|
-
throw new Error('node 安装写 /etc/systemd/system 需要 root
|
|
260
|
+
throw new Error('node 安装写 /etc/systemd/system 需要 root,请运行 sudo -i ssh-net install');
|
|
279
261
|
const entryChanged = syncEdgeEntries(ctx);
|
|
280
262
|
const plan = coreNodeRuntimePlan(topo);
|
|
281
263
|
const comp = compNote(ensureRuntime(ctx, plan.entities, plan.links), plan.entities);
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
// start:edge 两开关(缺省或 -a/--all=relay+peer,peer 自动补 relay);
|
|
2
2
|
// core 重新 enable+bootstrap uplink-relay;node systemctl。link 不是
|
|
3
3
|
// 运行时开关(转发口只取决于装没装附加件)。peer 路径复用 sn-route 做
|
|
4
|
-
//
|
|
5
|
-
// 检查与恢复照做,措辞区分「已开启」与「已是开启状态」。
|
|
4
|
+
// 人工强制恢复,不在控制面另维护一套报名实现。
|
|
6
5
|
import fs from 'node:fs';
|
|
7
6
|
import * as systemd from '../lib/systemd.mjs';
|
|
8
7
|
import { ensureLoaded } from '../lib/manage.mjs';
|
|
9
|
-
import { assertUnitSwitchArgs } from '../lib/cliargs.mjs';
|
|
10
8
|
import { SWITCH_NAMES } from '../lib/state.mjs';
|
|
11
9
|
import { SN_ROUTE } from '../lib/manifest.mjs';
|
|
12
10
|
import { relayLabel, relayUnitName, snRouteArgv } from '../lib/render.mjs';
|
|
@@ -22,12 +20,12 @@ function parseTargets(args) {
|
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
/** 先保存开关,再沿日常 ssh 的选路路径强制确保一次;未就绪不撤销用户意图。 */
|
|
25
|
-
function startEdgePeer(ctx
|
|
23
|
+
function startEdgePeer(ctx) {
|
|
26
24
|
const route = ctx.paths.binScript(SN_ROUTE);
|
|
27
25
|
if (!fs.existsSync(route))
|
|
28
26
|
throw new Error('未安装(缺 sn-route)——先跑 ssh-net install');
|
|
29
27
|
|
|
30
|
-
const prefix =
|
|
28
|
+
const prefix = 'relay 和 peer 开关已开启';
|
|
31
29
|
ctx.state.setOn(['relay', 'peer']);
|
|
32
30
|
// FORCE 只跳过新鲜失败印记;probe、ENSURE 与等待预算都和普通 ssh 相同。
|
|
33
31
|
// stdio:'inherit':sn-route 进度和报名错误直达终端。
|
|
@@ -53,12 +51,8 @@ function startCore(ctx) {
|
|
|
53
51
|
const plist = ctx.paths.plistFile(label);
|
|
54
52
|
if (!fs.existsSync(plist)) throw new Error(`尚未安装(缺 ${plist}),先跑 ssh-net install`);
|
|
55
53
|
// start 语义:在册但停着要踢活;在跑但 disabled 只清 override、不闪断
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
59
|
-
if (action === 'bootstrapped') return '中继通道已开启';
|
|
60
|
-
if (action === 'kickstarted') return '中继通道已重新拉起';
|
|
61
|
-
return '中继通道已在运行';
|
|
54
|
+
ensureLoaded(ctx, { label, plistPath: plist }, { kickWhenStopped: true });
|
|
55
|
+
return '中继通道已开启';
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
export function run(ctx, args = []) {
|
|
@@ -66,16 +60,16 @@ export function run(ctx, args = []) {
|
|
|
66
60
|
const before = ctx.state.readSwitches();
|
|
67
61
|
const targets = parseTargets(args); // ['relay','peer'] 或 ['relay']
|
|
68
62
|
|
|
69
|
-
if (targets.includes('peer'))
|
|
70
|
-
return startEdgePeer(ctx, before.relay && before.peer);
|
|
63
|
+
if (targets.includes('peer')) return startEdgePeer(ctx);
|
|
71
64
|
ctx.state.setOn(['relay']);
|
|
72
65
|
const peerNote = before.peer
|
|
73
66
|
? 'peer 保持开启,仍会主动恢复 IPv6 直连'
|
|
74
67
|
: 'peer 仍关闭;需要自动恢复时运行 ssh-net start peer';
|
|
75
|
-
return `relay
|
|
68
|
+
return `relay 已开启(${peerNote})`;
|
|
76
69
|
}
|
|
77
70
|
// core/node 是单总开关(等同 --all):显式 -a/--all 收下,其余参数拒绝
|
|
78
|
-
|
|
71
|
+
if (args.length && !(args.length === 1 && (args[0] === '-a' || args[0] === '--all')))
|
|
72
|
+
throw new Error('本机是单总开关,start 不带参数(-a/--all 亦可,等同缺省)');
|
|
79
73
|
if (ctx.role === 'core') return startCore(ctx);
|
|
80
74
|
if (ctx.role === 'node') {
|
|
81
75
|
systemd.enableStart(ctx.runner, relayUnitName(ctx.topo.relay.alias));
|
|
@@ -4,9 +4,7 @@
|
|
|
4
4
|
// 退出码:无「需要处理」事项 0;有可行动问题 1。线路关闭或 peer 暂不可用不等于
|
|
5
5
|
// 安装故障;实测发现中继不可用会进入处理项。
|
|
6
6
|
import fs from 'node:fs';
|
|
7
|
-
import {
|
|
8
|
-
auditScript, auditLink, runtimeVersionIssue,
|
|
9
|
-
} from '../lib/runtime.mjs';
|
|
7
|
+
import { auditScript, auditLink } from '../lib/runtime.mjs';
|
|
10
8
|
import { packageScriptPath } from '../lib/paths.mjs';
|
|
11
9
|
import * as launchd from '../lib/launchd.mjs';
|
|
12
10
|
import * as systemd from '../lib/systemd.mjs';
|
|
@@ -23,8 +21,8 @@ import {
|
|
|
23
21
|
} from '../lib/render.mjs';
|
|
24
22
|
|
|
25
23
|
/**
|
|
26
|
-
*
|
|
27
|
-
* @returns {{issues:string[], entityAudits:{name:string,audit:string}[]
|
|
24
|
+
* 各角色共用的实体+软链体检;完全未安装只报根因,不级联报其他产物。
|
|
25
|
+
* @returns {{issues:string[], entityAudits:{name:string,audit:string}[]}}
|
|
28
26
|
*/
|
|
29
27
|
function runtimeIssues(ctx, { entities, links }) {
|
|
30
28
|
const issues = [];
|
|
@@ -43,21 +41,10 @@ function runtimeIssues(ctx, { entities, links }) {
|
|
|
43
41
|
// 部分缺失:探针丢了会让开着的隧道恒判中继,不能只显示不报
|
|
44
42
|
issues.push(`后台脚本不完整(缺 ${entityAudits.filter((a) => a.audit === 'missing').map((a) => a.name).join('、')})——跑一次 ssh-net install 修复`);
|
|
45
43
|
for (const [linkName, entityName] of links) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
issues.push(`后台脚本异常(${linkName}:${r})——跑一次 ssh-net install 修复`);
|
|
44
|
+
if (!auditLink(ctx.paths.binScript(linkName), entityName))
|
|
45
|
+
issues.push(`后台脚本或服务软链异常(${linkName})——跑一次 ssh-net install 修复`);
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
|
-
return { issues, entityAudits, allMissing };
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** 三个 collector 的共同前奏:版本戳问题 + 实体/软链体检。 */
|
|
55
|
-
function baseAudit(ctx, plan) {
|
|
56
|
-
const issues = [];
|
|
57
|
-
const { issues: rtIssues, entityAudits, allMissing } = runtimeIssues(ctx, plan);
|
|
58
|
-
const vIssue = runtimeVersionIssue(ctx.paths);
|
|
59
|
-
if (vIssue && !allMissing) issues.push(vIssue);
|
|
60
|
-
issues.push(...rtIssues);
|
|
61
48
|
return { issues, entityAudits };
|
|
62
49
|
}
|
|
63
50
|
|
|
@@ -146,7 +133,7 @@ async function collectEdge(ctx, probe) {
|
|
|
146
133
|
const { topo, paths, state } = ctx;
|
|
147
134
|
const linkInstalled = fs.existsSync(paths.linkEnabledFile);
|
|
148
135
|
const plan = edgeRuntimePlan(topo, linkInstalled);
|
|
149
|
-
const { issues, entityAudits } =
|
|
136
|
+
const { issues, entityAudits } = runtimeIssues(ctx, plan);
|
|
150
137
|
|
|
151
138
|
// routes 被手删/过期会让 ssh 静默退回 lan 直连,是故障。sn-route 没装时
|
|
152
139
|
// 上面已报「尚未安装」,不重复
|
|
@@ -210,7 +197,7 @@ async function collectEdge(ctx, probe) {
|
|
|
210
197
|
|
|
211
198
|
async function collectCore(ctx, probe) {
|
|
212
199
|
const { topo, paths } = ctx;
|
|
213
|
-
const { issues } =
|
|
200
|
+
const { issues } = runtimeIssues(ctx, coreNodeRuntimePlan(topo));
|
|
214
201
|
|
|
215
202
|
// disabled override 是整域同一份字典:relay job 与各 edge job 共用一次拉取
|
|
216
203
|
const dmap = launchd.disabledMap(ctx.runner, ctx.uid);
|
|
@@ -237,8 +224,7 @@ async function collectCore(ctx, probe) {
|
|
|
237
224
|
const bad = [];
|
|
238
225
|
if (callbackEntityAudit !== 'ok')
|
|
239
226
|
bad.push(`连接脚本${callbackEntityAudit === 'missing' ? '缺失' : '过期'}`);
|
|
240
|
-
|
|
241
|
-
if (linkState !== 'ok') bad.push(`软链(${linkState})`);
|
|
227
|
+
if (!auditLink(paths.binScript(linkName), entityName)) bad.push('服务软链异常');
|
|
242
228
|
if (bad.length)
|
|
243
229
|
issues.push(`${e.alias} 的自动连接脚本异常(${bad.join('、')})——它下次连过来时会自动刷新(或跑一次 ssh-net install 手动修复)`);
|
|
244
230
|
}
|
|
@@ -248,7 +234,6 @@ async function collectCore(ctx, probe) {
|
|
|
248
234
|
disabled: st.disabled,
|
|
249
235
|
running: st.running,
|
|
250
236
|
lastExitCode: st.lastExitCode,
|
|
251
|
-
v6: ctx.state.readEdgeV6(e.alias),
|
|
252
237
|
entry: entryByAlias.get(e.alias),
|
|
253
238
|
});
|
|
254
239
|
}
|
|
@@ -266,7 +251,7 @@ async function collectCore(ctx, probe) {
|
|
|
266
251
|
|
|
267
252
|
async function collectNode(ctx, probe) {
|
|
268
253
|
const { topo } = ctx;
|
|
269
|
-
const { issues } =
|
|
254
|
+
const { issues } = runtimeIssues(ctx, coreNodeRuntimePlan(topo));
|
|
270
255
|
const entries = edgeEntries(ctx, issues);
|
|
271
256
|
|
|
272
257
|
const unit = relayUnitName(topo.relay.alias);
|
|
@@ -354,20 +339,13 @@ function renderEdgeLines(s, lines) {
|
|
|
354
339
|
}
|
|
355
340
|
|
|
356
341
|
function edgeTaskState(e) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (e.running) return '已标记休眠,进程尚未退出';
|
|
365
|
-
if (failed) return `已标记休眠,但上次退出 ${e.lastExitCode};launchd 仍可能自动重拉`;
|
|
366
|
-
return '休眠中(这台笔记本下次 ssh 或 start peer 时自动唤醒)';
|
|
367
|
-
}
|
|
368
|
-
if (e.running) return `运行中(仅表示任务进程,不代表线路已通)${exitNote(e.lastExitCode)}`;
|
|
369
|
-
if (failed) return `未运行(上次退出 ${e.lastExitCode},launchd 会自动重拉)`;
|
|
370
|
-
return '未运行(对端下次通知时会重新拉起)';
|
|
342
|
+
// 只列 launchd 事实,不为每种组合另写一句推断;排障解释集中在 notes
|
|
343
|
+
const facts = [
|
|
344
|
+
e.registered ? '已注册' : '未注册',
|
|
345
|
+
e.running ? '运行中' : '未运行',
|
|
346
|
+
];
|
|
347
|
+
if (e.registered && e.disabled) facts.push('休眠');
|
|
348
|
+
return `${facts.join(',')}${exitNote(e.lastExitCode)}`;
|
|
371
349
|
}
|
|
372
350
|
|
|
373
351
|
function renderCoreLines(s, lines) {
|