ssh-net 26.11.2 → 26.11.66
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 -3
- package/README.md +25 -19
- package/libexec/cli.mjs +23 -23
- package/libexec/commands/install.mjs +112 -182
- package/libexec/commands/register.mjs +1 -2
- package/libexec/commands/start.mjs +25 -18
- package/libexec/commands/status.mjs +59 -39
- package/libexec/commands/stop.mjs +6 -10
- package/libexec/commands/uninstall.mjs +11 -26
- package/libexec/commands/update.mjs +49 -21
- package/libexec/lib/conf.mjs +14 -3
- package/libexec/lib/config.mjs +3 -13
- package/libexec/lib/constants.mjs +3 -0
- package/libexec/lib/exec.mjs +2 -0
- package/libexec/lib/fsutil.mjs +33 -8
- package/libexec/lib/identity.mjs +16 -0
- package/libexec/lib/jobctl.mjs +1 -1
- package/libexec/lib/jobs.mjs +17 -17
- package/libexec/lib/launchd.mjs +17 -49
- package/libexec/lib/manage.mjs +117 -76
- package/libexec/lib/manifest.mjs +14 -57
- package/libexec/lib/paths.mjs +2 -4
- package/libexec/lib/probe.mjs +33 -46
- package/libexec/lib/runtime.mjs +29 -37
- package/libexec/lib/sshconfig.mjs +98 -17
- package/libexec/lib/systemd.mjs +214 -55
- package/libexec/sn-ipv6 +2 -2
- package/libexec/sn-route +110 -57
- package/libexec/ssh-net-link-core +2 -3
- package/package.json +1 -1
package/libexec/lib/systemd.mjs
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import os from 'node:os';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
-
import { readDirOrEmpty, readFileOrNull, writeFileAtomic } from './fsutil.mjs';
|
|
7
|
+
import { readDirOrEmpty, readFileOrNull, removeObsoleteNames, writeFileAtomic } from './fsutil.mjs';
|
|
8
8
|
|
|
9
9
|
/** @param {import('./exec.mjs').Runner} runner @param {string} unit 含 .service */
|
|
10
|
-
const sc = (runner, args) => runner.run('systemctl', args);
|
|
10
|
+
const sc = (runner, args) => runner.run('systemctl', args, { env: { LC_ALL: 'C' } });
|
|
11
11
|
|
|
12
12
|
/** 所有 reload 路径都把真失败抛出;恢复路径可给错误加「恢复后」前缀。 */
|
|
13
13
|
export function daemonReload(runner, errorPrefix = '') {
|
|
@@ -16,7 +16,13 @@ export function daemonReload(runner, errorPrefix = '') {
|
|
|
16
16
|
throw new Error(`${errorPrefix}systemctl daemon-reload 失败:${r.stderr.trim()}`);
|
|
17
17
|
}
|
|
18
18
|
export const enableUnit = (runner, unit) => sc(runner, ['enable', unit]);
|
|
19
|
-
|
|
19
|
+
function disableUnit(runner, unit, runtime = false) {
|
|
20
|
+
const r = sc(runner, runtime ? ['disable', '--runtime', unit] : ['disable', unit]);
|
|
21
|
+
const detail = r.stderr.trim();
|
|
22
|
+
if (r.code !== 0 && ![`Unit ${unit} not loaded.`, `Unit ${unit} does not exist.`, `Unit file ${unit} does not exist.`]
|
|
23
|
+
.some((message) => detail.endsWith(message)))
|
|
24
|
+
throw new Error(`systemctl disable 失败:${detail}`);
|
|
25
|
+
}
|
|
20
26
|
export const startUnit = (runner, unit) => sc(runner, ['start', unit]);
|
|
21
27
|
const stopUnit = (runner, unit) => sc(runner, ['stop', unit]);
|
|
22
28
|
export const restartUnit = (runner, unit) => sc(runner, ['restart', unit]);
|
|
@@ -25,21 +31,13 @@ export const restartUnit = (runner, unit) => sc(runner, ['restart', unit]);
|
|
|
25
31
|
* 磁盘上指定前缀的 unit 文件名(卸载清理改名前的残留;目录不存在时空)。
|
|
26
32
|
* @param {string} unitDir
|
|
27
33
|
* @param {string} prefix
|
|
34
|
+
* @param {boolean} [includePending] 停止和卸载时也处理仅剩更新记录的服务
|
|
28
35
|
* @returns {string[]}
|
|
29
36
|
*/
|
|
30
|
-
export function unitNamesOnDisk(unitDir, prefix) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/** 没装/已卸的 unit 放行(stop 的 not-loaded 与 disable 的 does not exist
|
|
36
|
-
* 两种真机文案都认),其余失败抛出——stop/uninstall 对不存在的 unit 幂等,
|
|
37
|
-
* 但真失败不能谎报成功。start 不经这里:unit 缺失是「先 install」
|
|
38
|
-
* 的真错误,与 mac 侧 startCore 查 plist 同口径 */
|
|
39
|
-
export function disableIfInstalled(runner, unit) {
|
|
40
|
-
const r = disableUnit(runner, unit);
|
|
41
|
-
if (r.code !== 0 && !/(not loaded|does not exist)/.test(r.stderr))
|
|
42
|
-
throw new Error(`systemctl disable 失败:${r.stderr.trim()}`);
|
|
37
|
+
export function unitNamesOnDisk(unitDir, prefix, includePending = false) {
|
|
38
|
+
const files = readDirOrEmpty(unitDir);
|
|
39
|
+
const names = includePending ? files.map(f => f.replace(/\.service\.pending$/, '.service')) : files;
|
|
40
|
+
return [...new Set(names.filter(f => f.startsWith(prefix) && f.endsWith('.service')))];
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
/**
|
|
@@ -51,40 +49,45 @@ export function disableIfInstalled(runner, unit) {
|
|
|
51
49
|
* @param {string} unit
|
|
52
50
|
*/
|
|
53
51
|
export function enableStart(runner, unit) {
|
|
54
|
-
|
|
55
|
-
if (e.code !== 0) throw new Error(`systemctl enable 失败:${e.stderr.trim()}`);
|
|
52
|
+
ensureEnabled(runner, unit);
|
|
56
53
|
const r = startUnit(runner, unit);
|
|
57
54
|
if (r.code !== 0) throw new Error(`systemctl start 失败:${r.stderr.trim()}`);
|
|
58
55
|
}
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
export function enableRestart(runner, unit) {
|
|
57
|
+
function ensureEnabled(runner, unit) {
|
|
62
58
|
const e = enableUnit(runner, unit);
|
|
63
59
|
if (e.code !== 0) throw new Error(`systemctl enable 失败:${e.stderr.trim()}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function restart(runner, unit) {
|
|
64
63
|
const r = restartUnit(runner, unit);
|
|
65
64
|
if (r.code !== 0) throw new Error(`systemctl restart 失败:${r.stderr.trim()}`);
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
/** @returns {string} active|inactive|failed|... */
|
|
69
|
-
export
|
|
70
|
-
sc(runner, ['is-active', unit])
|
|
68
|
+
export function isActive(runner, unit) {
|
|
69
|
+
const r = sc(runner, ['is-active', unit]);
|
|
70
|
+
const state = r.stdout.trim();
|
|
71
|
+
// inactive/failed 也有非零退出码;此时 stdout 仍有状态,与无法连接 manager 区分
|
|
72
|
+
if (!state || ![0, 3, 4].includes(r.code))
|
|
73
|
+
throw new Error(`systemctl is-active 失败(${unit}):${r.stderr.trim() || r.error?.message || `exit ${r.code}`}`);
|
|
74
|
+
return state;
|
|
75
|
+
}
|
|
71
76
|
|
|
72
77
|
/**
|
|
73
78
|
* unit 内容校验:写进私有临时目录、**文件名与正式 unit 相同**(verify 要求
|
|
74
79
|
* .service 后缀,basename 参与模板/实例语义),过了才允许落 /etc——坏 unit
|
|
75
80
|
* 绝不进系统目录(否则下次 daemon-reload 就生效)。systemd-analyze 不存在
|
|
76
81
|
* (ENOENT)视为通过:lint 尽力而为,不该让装不了它的机器无法安装。
|
|
77
|
-
* @returns {{ok:boolean, stderr:string}}
|
|
78
82
|
*/
|
|
79
|
-
function verifyUnitContent(runner, unitName, content) {
|
|
83
|
+
function verifyUnitContent(runner, { unitPath, unitName, content }) {
|
|
80
84
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ssh-net-unit-'));
|
|
81
85
|
try {
|
|
82
86
|
const file = path.join(dir, unitName);
|
|
83
87
|
fs.writeFileSync(file, content, { mode: 0o644 });
|
|
84
88
|
const r = runner.run('systemdAnalyze', ['verify', file]);
|
|
85
|
-
if (r.
|
|
86
|
-
|
|
87
|
-
return { ok: r.code === 0, stderr: r.stderr };
|
|
89
|
+
if (r.code !== 0 && r.error?.code !== 'ENOENT')
|
|
90
|
+
throw new Error(`systemd-analyze verify 失败(未写入 ${unitPath}):\n${r.stderr}`);
|
|
88
91
|
} finally {
|
|
89
92
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
90
93
|
}
|
|
@@ -97,57 +100,213 @@ function verifyUnitContent(runner, unitName, content) {
|
|
|
97
100
|
* @param {import('./exec.mjs').Runner} runner
|
|
98
101
|
* @param {string} unit
|
|
99
102
|
*/
|
|
100
|
-
|
|
103
|
+
function stopIfLoaded(runner, unit) {
|
|
101
104
|
const r = stopUnit(runner, unit);
|
|
102
|
-
if (r.code !== 0 &&
|
|
105
|
+
if (r.code !== 0 && !r.stderr.trim().endsWith(`Unit ${unit} not loaded.`))
|
|
103
106
|
throw new Error(`systemctl stop 失败:${r.stderr.trim()}`);
|
|
104
107
|
}
|
|
105
108
|
|
|
109
|
+
/** 停止并取消开机启动。已移除的 unit 无需再操作,其他失败照常报错 */
|
|
110
|
+
export function stopAndDisable(runner, unit) {
|
|
111
|
+
stopIfLoaded(runner, unit);
|
|
112
|
+
disableUnit(runner, unit);
|
|
113
|
+
disableUnit(runner, unit, true);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const pendingPath = unitPath => `${unitPath}.pending`;
|
|
117
|
+
|
|
118
|
+
export const hasPendingUpdate = unitPath => Boolean(fs.lstatSync(pendingPath(unitPath), { throwIfNoEntry: false }));
|
|
119
|
+
|
|
120
|
+
/** 人工停止也覆盖更新中断前保存的自启状态,以免下次安装失败又启动了旧服务 */
|
|
121
|
+
export function stopInstalledUnit(runner, unitDir, unit) {
|
|
122
|
+
stopAndDisable(runner, unit);
|
|
123
|
+
const file = pendingPath(path.join(unitDir, unit));
|
|
124
|
+
const saved = readFileOrNull(file);
|
|
125
|
+
if (saved !== null) {
|
|
126
|
+
const record = JSON.parse(saved);
|
|
127
|
+
record.state = { active: false, fileState: 'disabled', invocation: null };
|
|
128
|
+
writeFileAtomic(file, JSON.stringify(record), { mode: 0o600 });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 趁文件还在时停服并 disable,清掉开机启动的软链。调用方完成所有文件变更后再重载 */
|
|
133
|
+
export function removeUnits(runner, unitDir, units) {
|
|
134
|
+
for (const unit of units) {
|
|
135
|
+
stopAndDisable(runner, unit);
|
|
136
|
+
const unitPath = path.join(unitDir, unit);
|
|
137
|
+
fs.rmSync(pendingPath(unitPath), { force: true });
|
|
138
|
+
fs.rmSync(unitPath, { force: true });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function unitState(runner, unit, withInvocation = false) {
|
|
143
|
+
const props = ['-p', 'ActiveState', '-p', 'UnitFileState'];
|
|
144
|
+
if (withInvocation) props.push('-p', 'InvocationID');
|
|
145
|
+
const state = sc(runner, ['show', ...props, unit]);
|
|
146
|
+
if (state.code !== 0) throw new Error(`systemctl show 失败(${unit}):${state.stderr.trim()}`);
|
|
147
|
+
const activeState = state.stdout.match(/^ActiveState=(\S+)$/m)?.[1];
|
|
148
|
+
if (!activeState) throw new Error(`systemctl show 未返回 ${unit} 的运行状态`);
|
|
149
|
+
const fileState = state.stdout.match(/^UnitFileState=(\S+)$/m)?.[1];
|
|
150
|
+
if (!fileState) throw new Error(`systemctl show 未返回 ${unit} 的自启状态`);
|
|
151
|
+
const active = ['active', 'activating', 'reloading', 'refreshing'].includes(activeState);
|
|
152
|
+
const invocation = state.stdout.match(/^InvocationID=([0-9a-f]{32})$/m)?.[1];
|
|
153
|
+
if (withInvocation && active && (!invocation || /^0+$/.test(invocation)))
|
|
154
|
+
throw new Error(`systemctl show 未返回 ${unit} 的运行实例 ID`);
|
|
155
|
+
return { active, fileState, invocation: active ? invocation : null };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** 各 unit 的运行和自启分别恢复,单步错误在尝试完其他服务后一起报告 */
|
|
159
|
+
function restoreUnits(runner, states, activeCommand = 'start') {
|
|
160
|
+
const failures = [];
|
|
161
|
+
for (const { unit, active, fileState } of states) {
|
|
162
|
+
const commands = [];
|
|
163
|
+
if (fileState === 'enabled') commands.push(['enable', unit]);
|
|
164
|
+
if (fileState === 'enabled-runtime') commands.push(['enable', '--runtime', unit]);
|
|
165
|
+
if (active) commands.push([activeCommand, unit]);
|
|
166
|
+
for (const args of commands) {
|
|
167
|
+
const r = sc(runner, args);
|
|
168
|
+
if (r.code !== 0) failures.push(new Error(`systemctl ${args.join(' ')} 失败:${r.stderr.trim()}`));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (failures.length) throw new AggregateError(failures, failures.map(e => e.message).join(';'));
|
|
172
|
+
}
|
|
173
|
+
|
|
106
174
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* verify → 通过才原子落盘 → daemon-reload → enable → restart;编排失败恢复
|
|
110
|
-
* 旧文件与 manager,首装撤掉 enable/进程,更新用旧 unit 恢复启动。
|
|
175
|
+
* 确保服务在跑。新配置校验通过后先清除占用注册口的旧名字。同名更新只向
|
|
176
|
+
* systemd 提交完整的 restart;没有未完成的更新时,字节相同只 enable+start
|
|
111
177
|
* @param {import('./exec.mjs').Runner} runner
|
|
112
178
|
* @param {{unitPath:string, unitName:string, content:string}} job
|
|
179
|
+
* @param {string[]} [obsolete] 已改名的 unit,不含当前名字
|
|
113
180
|
* @returns {{changed:boolean, restarted?:boolean}} 配置是否变化;restarted
|
|
114
181
|
* 只在更新已存在的 unit 时为真,用于提示可能断连
|
|
115
182
|
*/
|
|
116
|
-
export function syncUnit(runner,
|
|
117
|
-
|
|
118
|
-
|
|
183
|
+
export function syncUnit(runner, job, obsolete = []) {
|
|
184
|
+
const { unitPath, unitName, content } = job;
|
|
185
|
+
const unitDir = path.dirname(unitPath);
|
|
186
|
+
fs.mkdirSync(unitDir, { recursive: true });
|
|
119
187
|
const previous = readFileOrNull(unitPath);
|
|
120
|
-
if (previous
|
|
188
|
+
if (previous !== content) verifyUnitContent(runner, job);
|
|
189
|
+
if (!obsolete.length) return deployUnit(runner, job, previous);
|
|
190
|
+
|
|
191
|
+
// 同时记录运行与自启状态,回滚时才能保留人工停止或临时启用的服务
|
|
192
|
+
const stopped = [];
|
|
193
|
+
let result;
|
|
194
|
+
// 支持启用大小写折叠的 Linux 目录。旧文件能由新拼写读取,但 manager 仍按旧名字识别服务
|
|
195
|
+
const diskNames = previous !== null ? new Set(readDirOrEmpty(unitDir)) : new Set();
|
|
196
|
+
const oldSpelling = !diskNames.has(unitName) && obsolete.find(old => diskNames.has(old) && old.toLowerCase() === unitName.toLowerCase());
|
|
197
|
+
const existingTarget = previous === content && !oldSpelling ? unitState(runner, unitName) : null;
|
|
198
|
+
let deploying = false;
|
|
199
|
+
try {
|
|
200
|
+
for (const unit of obsolete) {
|
|
201
|
+
stopped.push({ unit, ...unitState(runner, unit) });
|
|
202
|
+
stopAndDisable(runner, unit);
|
|
203
|
+
}
|
|
204
|
+
deploying = true;
|
|
205
|
+
result = deployUnit(runner, job, oldSpelling ? null : previous, Boolean(oldSpelling));
|
|
206
|
+
} catch (err) {
|
|
207
|
+
const failures = [];
|
|
208
|
+
if (deploying && oldSpelling) {
|
|
209
|
+
try {
|
|
210
|
+
writeFileAtomic(path.join(unitDir, oldSpelling), previous, { mode: 0o644 });
|
|
211
|
+
daemonReload(runner, '恢复后 ');
|
|
212
|
+
} catch (restore) { failures.push(restore); }
|
|
213
|
+
}
|
|
214
|
+
if (deploying && existingTarget && existingTarget.fileState !== 'enabled') {
|
|
215
|
+
try { disableUnit(runner, unitName); } catch (restore) { failures.push(restore); }
|
|
216
|
+
}
|
|
217
|
+
try { restoreUnits(runner, stopped); } catch (restore) { failures.push(restore); }
|
|
218
|
+
if (failures.length)
|
|
219
|
+
throw new AggregateError([err, ...failures], `${err.message};恢复旧中继失败:${failures.map(e => e.message).join(';')}`);
|
|
220
|
+
throw err;
|
|
221
|
+
}
|
|
222
|
+
for (const old of obsolete) fs.rmSync(pendingPath(path.join(unitDir, old)), { force: true });
|
|
223
|
+
removeObsoleteNames(unitDir, obsolete, [unitName]);
|
|
224
|
+
daemonReload(runner);
|
|
225
|
+
return result;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function restoreDefinition(runner, unitName, state) {
|
|
229
|
+
daemonReload(runner, '恢复后 ');
|
|
230
|
+
if (state.fileState !== 'enabled') disableUnit(runner, unitName);
|
|
231
|
+
let command = 'start';
|
|
232
|
+
if (state.active) {
|
|
233
|
+
const current = unitState(runner, unitName, true);
|
|
234
|
+
if (current.active && current.invocation !== state.invocation) command = 'restart';
|
|
235
|
+
} else {
|
|
236
|
+
// 即使当前已在退出,也要取消 Restart=always 或排队中的启动任务
|
|
237
|
+
stopIfLoaded(runner, unitName);
|
|
238
|
+
}
|
|
239
|
+
restoreUnits(runner, [{ ...state, unit: unitName }], command);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function deployUnit(runner, { unitPath, unitName, content }, previous, renamed = false) {
|
|
243
|
+
const pending = pendingPath(unitPath);
|
|
244
|
+
let saved = renamed ? null : readFileOrNull(pending);
|
|
245
|
+
let resuming = saved !== null;
|
|
246
|
+
if (previous === content && !resuming) {
|
|
121
247
|
enableStart(runner, unitName);
|
|
122
248
|
return { changed: false };
|
|
123
249
|
}
|
|
124
250
|
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
251
|
+
let record = resuming ? JSON.parse(saved) : null;
|
|
252
|
+
if (record && record.target === previous && record.beforeRestart !== undefined) {
|
|
253
|
+
const current = unitState(runner, unitName, true);
|
|
254
|
+
if (current.active && current.invocation !== record.beforeRestart) {
|
|
255
|
+
// 上次的目标已在运行。继续安装其他配置时,失败应恢复到这个实例
|
|
256
|
+
if (previous === content) enableStart(runner, unitName);
|
|
257
|
+
fs.rmSync(pending, { force: true });
|
|
258
|
+
if (previous === content) return { changed: false };
|
|
259
|
+
record = null;
|
|
260
|
+
saved = null;
|
|
261
|
+
resuming = false;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (!record && previous !== null) record = { previous, state: unitState(runner, unitName, true) };
|
|
265
|
+
|
|
266
|
+
// 省略编号表示尚未准备重启,null 表示重启前服务已停
|
|
267
|
+
function savePending(beforeRestart) {
|
|
268
|
+
const text = JSON.stringify({ ...record, target: content, beforeRestart });
|
|
269
|
+
if (saved === text) return;
|
|
270
|
+
writeFileAtomic(pending, text, { mode: 0o600 });
|
|
271
|
+
saved = text;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let restarted = false;
|
|
129
275
|
try {
|
|
276
|
+
if (previous !== content) {
|
|
277
|
+
if (record) savePending(); // 远程会话可能断开,先留下旧定义和原自启状态
|
|
278
|
+
writeFileAtomic(unitPath, content, { mode: 0o644 });
|
|
279
|
+
}
|
|
130
280
|
daemonReload(runner);
|
|
131
|
-
|
|
281
|
+
ensureEnabled(runner, unitName);
|
|
282
|
+
// 只认加载新定义之后的实例变更,不能拿 daemon-reload 本身当作重启
|
|
283
|
+
const current = record ? unitState(runner, unitName, true) : null;
|
|
284
|
+
const originalRunning = current?.active && record.previous === content && current.invocation === record.state.invocation;
|
|
285
|
+
if (!originalRunning) {
|
|
286
|
+
if (record) savePending(current.invocation);
|
|
287
|
+
restart(runner, unitName);
|
|
288
|
+
restarted = previous !== null;
|
|
289
|
+
}
|
|
132
290
|
} catch (err) {
|
|
133
|
-
// 文件相同只能表示部署完成:失败时恢复旧文件并重载 manager;首装撤掉
|
|
134
|
-
// enable/进程,更新用旧 unit 恢复启动,下一次 install 仍能重新对账。
|
|
135
291
|
try {
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
292
|
+
if (record) {
|
|
293
|
+
const replaced = readFileOrNull(unitPath) !== record.previous;
|
|
294
|
+
if (replaced) {
|
|
295
|
+
// 回滚本身也可能中断;新定义的重启记录不能拿来确认旧定义
|
|
296
|
+
savePending();
|
|
297
|
+
writeFileAtomic(unitPath, record.previous, { mode: 0o644 });
|
|
298
|
+
}
|
|
299
|
+
if (replaced || resuming) restoreDefinition(runner, unitName, record.state);
|
|
300
|
+
fs.rmSync(pending, { force: true });
|
|
301
|
+
} else if (readFileOrNull(unitPath) !== null) {
|
|
302
|
+
removeUnits(runner, path.dirname(unitPath), [unitName]);
|
|
303
|
+
daemonReload(runner, '恢复后 ');
|
|
144
304
|
}
|
|
145
|
-
daemonReload(runner, '恢复后 ');
|
|
146
|
-
if (previous !== null) enableRestart(runner, unitName);
|
|
147
305
|
} catch (rollbackError) {
|
|
148
306
|
throw new AggregateError([err, rollbackError], `${err.message};恢复 systemd 状态失败:${rollbackError.message}`);
|
|
149
307
|
}
|
|
150
308
|
throw err;
|
|
151
309
|
}
|
|
152
|
-
|
|
310
|
+
if (record) fs.rmSync(pending, { force: true });
|
|
311
|
+
return { changed: restarted || previous !== content, restarted };
|
|
153
312
|
}
|
package/libexec/sn-ipv6
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
# sn-ipv6:选取本机可注册的公网 v6——默认路由网卡上 2000::/3 全局单播、
|
|
3
|
-
# autoconf secured
|
|
3
|
+
# 选已就绪的 autoconf secured 地址,过滤临时、过期和重复地址(design §6.4)。
|
|
4
4
|
# 无输出 = 没有可注册 v6(v4-only/咖啡厅场景),退出码恒 0。
|
|
5
5
|
# SSH_NET_V6_ALLOW_ULA=1 额外收 fc00::/7 ULA——仅测试注入用的强制开关
|
|
6
6
|
#(喂参测试模拟纯 ULA 网络),生产路径恒不设置、默认只认公网 2000::/3。
|
|
@@ -55,7 +55,7 @@ while IFS= read -r line; do
|
|
|
55
55
|
[ "${1:-}" = "inet6" ] || continue
|
|
56
56
|
# link-local 只有 secured 无 autoconf,故两标记必须同时在
|
|
57
57
|
case "$line" in *autoconf*secured*) ;; *) continue ;; esac
|
|
58
|
-
case "$line" in *deprecated*|*temporary*) continue ;; esac
|
|
58
|
+
case "$line" in *deprecated*|*temporary*|*tentative*|*duplicated*|*detached*) continue ;; esac
|
|
59
59
|
addr=${2%%%*} # 去可能的 scope
|
|
60
60
|
if in_allowed_range "$addr"; then
|
|
61
61
|
printf '%s\n' "$addr"
|