@lob-ox/core-darwin-x64 0.0.13 → 0.0.15
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/core.cjs +166 -188
- package/package.json +1 -1
package/core.cjs
CHANGED
|
@@ -1471,7 +1471,7 @@ var require_version = __commonJS({
|
|
|
1471
1471
|
var fs2 = require("node:fs");
|
|
1472
1472
|
var path2 = require("node:path");
|
|
1473
1473
|
function guardVersion() {
|
|
1474
|
-
if (true) return String("0.0.
|
|
1474
|
+
if (true) return String("0.0.15");
|
|
1475
1475
|
try {
|
|
1476
1476
|
return JSON.parse(fs2.readFileSync(path2.join(__dirname, "..", "..", "package.json"), "utf8")).version || "unknown";
|
|
1477
1477
|
} catch {
|
|
@@ -6648,12 +6648,6 @@ var require_portable = __commonJS({
|
|
|
6648
6648
|
var OUTCOME = require_outcome();
|
|
6649
6649
|
var STOP_WAIT_CAP_MS = 3e3;
|
|
6650
6650
|
var NAP_MS = 150;
|
|
6651
|
-
function nap(ms) {
|
|
6652
|
-
try {
|
|
6653
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
6654
|
-
} catch {
|
|
6655
|
-
}
|
|
6656
|
-
}
|
|
6657
6651
|
function readPidFile(pidFile) {
|
|
6658
6652
|
if (!pidFile) return null;
|
|
6659
6653
|
try {
|
|
@@ -6667,7 +6661,7 @@ var require_portable = __commonJS({
|
|
|
6667
6661
|
if (!pid || !Array.isArray(anchors) || !anchors.length) return false;
|
|
6668
6662
|
const cmd2 = pidlookup.readCmdline(pid);
|
|
6669
6663
|
if (!cmd2) return false;
|
|
6670
|
-
return anchors.
|
|
6664
|
+
return anchors.some((a) => a && cmd2.indexOf(String(a)) !== -1);
|
|
6671
6665
|
}
|
|
6672
6666
|
var portOf = (o) => {
|
|
6673
6667
|
const p = Number(o && o.port);
|
|
@@ -6710,6 +6704,15 @@ var require_portable = __commonJS({
|
|
|
6710
6704
|
kind: "portable",
|
|
6711
6705
|
supportsUnits: false,
|
|
6712
6706
|
supportsTransient: true,
|
|
6707
|
+
/**
|
|
6708
|
+
* 能力协商(根因 B 修法;与 router 域 `supports(cap)` 同一范式,下沉到平台层)。
|
|
6709
|
+
*
|
|
6710
|
+
* 判据来源:capability-profile.js 的 sandboxEnforcement —— 三平台均为 'supervise'
|
|
6711
|
+
* (= 产品自身监控,**无 cgroup 级强制**)。此前该字段全仓 0 处查询,
|
|
6712
|
+
* 于是 governor 在"限额根本无法生效"的前提下仍判违规并重启 ⇒ 永动机(P0)。
|
|
6713
|
+
*
|
|
6714
|
+
* 调用方(governor)必须先问后处置:不支持限额 ⇒ 只观测,绝不重启。
|
|
6715
|
+
*/
|
|
6713
6716
|
supports(cap) {
|
|
6714
6717
|
if (cap === "treeKill") return true;
|
|
6715
6718
|
if (cap === "limits") return false;
|
|
@@ -6790,73 +6793,19 @@ var require_portable = __commonJS({
|
|
|
6790
6793
|
}
|
|
6791
6794
|
return false;
|
|
6792
6795
|
},
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
|
|
6797
|
-
|
|
6798
|
-
|
|
6799
|
-
|
|
6800
|
-
|
|
6801
|
-
|
|
6802
|
-
|
|
6803
|
-
|
|
6804
|
-
|
|
6805
|
-
|
|
6806
|
-
});
|
|
6807
|
-
child.on("error", () => {
|
|
6808
|
-
});
|
|
6809
|
-
if (!child.pid) {
|
|
6810
|
-
try {
|
|
6811
|
-
child.kill();
|
|
6812
|
-
} catch {
|
|
6813
|
-
}
|
|
6814
|
-
throw new Error("portable \u62C9\u8D77\u5931\u8D25\uFF1Aspawn \u672A\u4EA7\u751F\u8FDB\u7A0B");
|
|
6815
|
-
}
|
|
6816
|
-
try {
|
|
6817
|
-
child.unref();
|
|
6818
|
-
} catch {
|
|
6819
|
-
}
|
|
6820
|
-
if (opts.pidFile) {
|
|
6821
|
-
try {
|
|
6822
|
-
fs2.writeFileSync(opts.pidFile, String(child.pid));
|
|
6823
|
-
} catch {
|
|
6824
|
-
}
|
|
6825
|
-
}
|
|
6826
|
-
return true;
|
|
6827
|
-
},
|
|
6828
|
-
stopUnit(unit, o) {
|
|
6829
|
-
const opts = o || {};
|
|
6830
|
-
const ours = findOurs(opts);
|
|
6831
|
-
if (!ours) {
|
|
6832
|
-
removePidFile(opts);
|
|
6833
|
-
return true;
|
|
6834
|
-
}
|
|
6835
|
-
try {
|
|
6836
|
-
procOS.killTree(ours.pid, "SIGTERM", void 0, { ownGroup: ours.ownGroup });
|
|
6837
|
-
} catch {
|
|
6838
|
-
}
|
|
6839
|
-
const budget = Math.max(0, Math.min(typeof opts.timeoutMs === "number" ? opts.timeoutMs : STOP_WAIT_CAP_MS, STOP_WAIT_CAP_MS));
|
|
6840
|
-
const t0 = Date.now();
|
|
6841
|
-
for (; ; ) {
|
|
6842
|
-
if (!findOurs(opts)) {
|
|
6843
|
-
removePidFile(opts);
|
|
6844
|
-
return true;
|
|
6845
|
-
}
|
|
6846
|
-
if (Date.now() - t0 >= budget) break;
|
|
6847
|
-
nap(NAP_MS);
|
|
6848
|
-
}
|
|
6849
|
-
try {
|
|
6850
|
-
procOS.killTree(ours.pid, "SIGKILL", void 0, { ownGroup: ours.ownGroup });
|
|
6851
|
-
} catch {
|
|
6852
|
-
}
|
|
6853
|
-
nap(NAP_MS);
|
|
6854
|
-
if (!findOurs(opts)) {
|
|
6855
|
-
removePidFile(opts);
|
|
6856
|
-
return true;
|
|
6857
|
-
}
|
|
6858
|
-
return false;
|
|
6859
|
-
},
|
|
6796
|
+
/**
|
|
6797
|
+
* 单元是否活跃 —— 返回 Outcome 三态(根因 A 修法)。
|
|
6798
|
+
*
|
|
6799
|
+
* 此前返回 null 表示"未知",而调用方 instance/ops.js:67 用 `active !== false` 判,
|
|
6800
|
+
* 于是 null(未知)被当成"仍活跃" ⇒ removeInstance 把未知报成删除成功(P0)。
|
|
6801
|
+
*
|
|
6802
|
+
* 关键修正:**无 anchors 时不得把"有人在监听"当成"我们的实例在跑"**。
|
|
6803
|
+
* 端口是共享事实、不是身份(与 monitor.js#matchesAnchors 同一条判据);
|
|
6804
|
+
* 缺锚点即无从验证身份 ⇒ 如实返回 unknown,由调用方决定(升级校验须失败并回滚)。
|
|
6805
|
+
*
|
|
6806
|
+
* 兼容:既有调用方若直接判真假,Outcome 对象恒为真值,行为同"true",不会静默反转;
|
|
6807
|
+
* 但显式判据(isOk/isFail/isUnknown)才能区分三态——见 shared/outcome.js。
|
|
6808
|
+
*/
|
|
6860
6809
|
isUnitActive(unit, o) {
|
|
6861
6810
|
const opts = o || {};
|
|
6862
6811
|
if (findOurs(opts)) return OUTCOME.OK;
|
|
@@ -7884,28 +7833,8 @@ var require_bootstrap = __commonJS({
|
|
|
7884
7833
|
const beat = host._beatScheduler;
|
|
7885
7834
|
const tickMs = host.config.tickIntervalMs || 5e3;
|
|
7886
7835
|
beat.unregister("main");
|
|
7887
|
-
beat.unregister("heartbeat");
|
|
7888
|
-
beat.unregister("instance-supervise");
|
|
7889
7836
|
beat.unregister("upgrade-check");
|
|
7890
7837
|
beat.register("main", () => host.tick(), { every: 1 });
|
|
7891
|
-
beat.register("heartbeat", () => {
|
|
7892
|
-
if (host.managedObjects) return host.managedObjects.heartbeat(tickMs);
|
|
7893
|
-
return host.tick();
|
|
7894
|
-
}, { every: 1, timeoutMs: Math.max(3e4, tickMs * 12) });
|
|
7895
|
-
beat.register("instance-supervise", async () => {
|
|
7896
|
-
if (!host.instances) return;
|
|
7897
|
-
try {
|
|
7898
|
-
for (const inst of host.instances.all()) {
|
|
7899
|
-
if (inst.domain === "native") continue;
|
|
7900
|
-
host.instances.supervise && host.instances.supervise(inst.id);
|
|
7901
|
-
}
|
|
7902
|
-
} catch (e) {
|
|
7903
|
-
}
|
|
7904
|
-
try {
|
|
7905
|
-
host.instances.governSweep && host.instances.governSweep();
|
|
7906
|
-
} catch (e) {
|
|
7907
|
-
}
|
|
7908
|
-
}, { every: 1 });
|
|
7909
7838
|
if (host.config.updateCheckEnabled !== false) {
|
|
7910
7839
|
const checkDelayMs2 = host.config.initialCheckDelayMs || 2e4;
|
|
7911
7840
|
const checkIntervalMs2 = Math.max(1, Math.round((host.config.updateCheckIntervalMs || 36e5) / tickMs));
|
|
@@ -7918,13 +7847,6 @@ var require_bootstrap = __commonJS({
|
|
|
7918
7847
|
}
|
|
7919
7848
|
beat.tick();
|
|
7920
7849
|
beat.start(tickMs);
|
|
7921
|
-
host._timer = null;
|
|
7922
|
-
host._heartbeatTimer = null;
|
|
7923
|
-
host._upgradeTimer = null;
|
|
7924
|
-
host._initialCheckTimer = null;
|
|
7925
|
-
host._lastHeartbeatAt = Date.now();
|
|
7926
|
-
host._heartbeatStalls = 0;
|
|
7927
|
-
host._heartbeatBeat = host._heartbeatBeat || 0;
|
|
7928
7850
|
if (host.lanDaemonEnabled()) {
|
|
7929
7851
|
host._syncLanState();
|
|
7930
7852
|
const lrt = host._ensureLanRuntime(true);
|
|
@@ -8052,13 +7974,7 @@ var require_bootstrap = __commonJS({
|
|
|
8052
7974
|
const isBare = policies.isBareCommand(cur);
|
|
8053
7975
|
if (!isBare) return;
|
|
8054
7976
|
const d = execPath.resolveDsh();
|
|
8055
|
-
if (!d || !d.bin)
|
|
8056
|
-
try {
|
|
8057
|
-
host.logger.warn && host.logger.warn("\u539F\u751F DSH \u542F\u52A8\u671F\u7ED1\u5B9A\u8DF3\u8FC7\uFF1A\u672A\u89E3\u6790\u5230\u5165\u53E3\uFF08PATH \u53EF\u80FD\u5C1A\u672A\u767B\u8BB0\uFF09\uFF1Bspawn \u671F\u4F1A\u518D\u6B21\u89E3\u6790");
|
|
8058
|
-
} catch {
|
|
8059
|
-
}
|
|
8060
|
-
return;
|
|
8061
|
-
}
|
|
7977
|
+
if (!d || !d.bin) return;
|
|
8062
7978
|
host.config.command = d.isJs ? [d.runtime || process.execPath, d.bin, ...cmd2.slice(2)] : [d.bin, ...cmd2.slice(2)];
|
|
8063
7979
|
try {
|
|
8064
7980
|
host.events && host.events.append(BRAND2.EVENT_HARNESS_COMMAND_BOUND, { from: cur || null, to: host.config.command[1] });
|
|
@@ -8847,36 +8763,9 @@ var require_registry3 = __commonJS({
|
|
|
8847
8763
|
var policies = require_policies2();
|
|
8848
8764
|
var ref = require_registry_ref();
|
|
8849
8765
|
var config = require_registry_config();
|
|
8850
|
-
var PROBE_MAX_BODY_BYTES = 8 * 1024 * 1024;
|
|
8851
8766
|
function platformTag() {
|
|
8852
8767
|
return matrix.npmTag();
|
|
8853
8768
|
}
|
|
8854
|
-
async function probeRegistry(state, origin) {
|
|
8855
|
-
const spec = state.contract && state.contract.ok && state.contract.probe || null;
|
|
8856
|
-
let tag = null;
|
|
8857
|
-
try {
|
|
8858
|
-
if (matrix.isSupported()) tag = platformTag();
|
|
8859
|
-
} catch {
|
|
8860
|
-
tag = null;
|
|
8861
|
-
}
|
|
8862
|
-
const target = policies.resolveProbe(origin, spec, tag);
|
|
8863
|
-
if (!target.url) {
|
|
8864
|
-
return { ok: false, latencyMs: 0, probe: target.kind, error: target.violation || "\u955C\u50CF\u57FA\u5740\u975E\u6CD5" };
|
|
8865
|
-
}
|
|
8866
|
-
const start = Date.now();
|
|
8867
|
-
const r = await ref.fetchRegistry(target.url, {
|
|
8868
|
-
timeoutMs: target.timeoutMs,
|
|
8869
|
-
expect: "text",
|
|
8870
|
-
maxBytes: PROBE_MAX_BODY_BYTES
|
|
8871
|
-
});
|
|
8872
|
-
return { ok: !!r.ok, latencyMs: Date.now() - start, probe: target.kind, error: r.error || null };
|
|
8873
|
-
}
|
|
8874
|
-
async function probeOrigin(state, origin) {
|
|
8875
|
-
const parsed = ref.parseRegistryBase(origin);
|
|
8876
|
-
if (!parsed.ok) return { origin: ref.normalizeBase(origin), ok: false, latencyMs: null, error: parsed.violation };
|
|
8877
|
-
const p = await probeRegistry(state, parsed.base);
|
|
8878
|
-
return { origin: parsed.base, ok: !!p.ok, latencyMs: p.latencyMs, probe: p.probe, error: p.error || null };
|
|
8879
|
-
}
|
|
8880
8769
|
function registryOrigins(state) {
|
|
8881
8770
|
const seen = /* @__PURE__ */ new Set();
|
|
8882
8771
|
const out = [];
|
|
@@ -8889,21 +8778,13 @@ var require_registry3 = __commonJS({
|
|
|
8889
8778
|
}
|
|
8890
8779
|
return out;
|
|
8891
8780
|
}
|
|
8892
|
-
async function probeAllOrigins(state, origins) {
|
|
8893
|
-
const results = await Promise.all(origins.map(async (origin) => {
|
|
8894
|
-
const p = await probeRegistry(state, origin);
|
|
8895
|
-
return { origin, ok: !!p.ok, latencyMs: p.latencyMs, error: p.error || null };
|
|
8896
|
-
}));
|
|
8897
|
-
results.sort((a, b) => a.ok === b.ok ? a.latencyMs - b.latencyMs : a.ok ? -1 : 1);
|
|
8898
|
-
return results;
|
|
8899
|
-
}
|
|
8900
8781
|
async function probeOrAdopt(state, origins) {
|
|
8901
8782
|
const c = state.contract;
|
|
8902
8783
|
if (c && c.ok) {
|
|
8903
8784
|
const adopted = policies.shellProbeResults(origins, c.measurements, Math.floor(Date.now() / 1e3));
|
|
8904
8785
|
if (adopted) return adopted;
|
|
8905
8786
|
}
|
|
8906
|
-
return
|
|
8787
|
+
return (origins || []).map((origin) => ({ origin, ok: false, latencyMs: null, error: "shell-contract \u672A\u63D0\u4F9B\u6D4B\u901F\u7ED3\u679C\uFF08\u955C\u50CF\u6E90\u5F52\u58F3\u4FA7\u5E95\u5EA7\uFF09", from: "no-contract" }));
|
|
8907
8788
|
}
|
|
8908
8789
|
function orderFor(primary, origins, results) {
|
|
8909
8790
|
const usable = (o) => ref.parseRegistryBase(o).ok;
|
|
@@ -9038,9 +8919,6 @@ var require_registry3 = __commonJS({
|
|
|
9038
8919
|
}
|
|
9039
8920
|
module2.exports = {
|
|
9040
8921
|
platformTag,
|
|
9041
|
-
probeRegistry,
|
|
9042
|
-
probeOrigin,
|
|
9043
|
-
probeAllOrigins,
|
|
9044
8922
|
registryOrigins,
|
|
9045
8923
|
orderFor,
|
|
9046
8924
|
selectRegistry,
|
|
@@ -10123,8 +10001,7 @@ var require_controller = __commonJS({
|
|
|
10123
10001
|
host._crashHalted = v;
|
|
10124
10002
|
},
|
|
10125
10003
|
sessionState() {
|
|
10126
|
-
|
|
10127
|
-
return p === "STARTING" || p === "RUNNING" ? "running" : "stopped";
|
|
10004
|
+
return host.session ? host.session.state() : "running";
|
|
10128
10005
|
},
|
|
10129
10006
|
mChild() {
|
|
10130
10007
|
return host._mChild();
|
|
@@ -10318,7 +10195,7 @@ var require_controller = __commonJS({
|
|
|
10318
10195
|
d.logger().error("tick error: " + (e && e.stack || e));
|
|
10319
10196
|
} finally {
|
|
10320
10197
|
d.writeTicking(false);
|
|
10321
|
-
if (d.sessionState()
|
|
10198
|
+
if (d.sessionState() !== "running") d.session().setState("running");
|
|
10322
10199
|
try {
|
|
10323
10200
|
d.control().syncDshView();
|
|
10324
10201
|
} catch (e) {
|
|
@@ -12248,10 +12125,7 @@ var require_status = __commonJS({
|
|
|
12248
12125
|
desired: host._mDesired(),
|
|
12249
12126
|
phase: host._mPhase(),
|
|
12250
12127
|
state: deriveState(host),
|
|
12251
|
-
sessionState: (
|
|
12252
|
-
const p = String(host._mPhase() || "").toUpperCase();
|
|
12253
|
-
return p === "STARTING" || p === "RUNNING" ? "running" : "stopped";
|
|
12254
|
-
})(),
|
|
12128
|
+
sessionState: host.session ? host.session.state() : "running",
|
|
12255
12129
|
dataDirProtected: Array.isArray(host._fileProtectStatus) ? host._fileProtectStatus.length > 0 && host._fileProtectStatus.every((r) => r.ok) : null,
|
|
12256
12130
|
guardVersion: host.guardVersion,
|
|
12257
12131
|
installId: installId(),
|
|
@@ -12990,37 +12864,27 @@ var require_env = __commonJS({
|
|
|
12990
12864
|
var require_node_lts = __commonJS({
|
|
12991
12865
|
"src/app/settings/node-lts.js"(exports2, module2) {
|
|
12992
12866
|
"use strict";
|
|
12993
|
-
var
|
|
12994
|
-
var path2 = require("node:path");
|
|
12867
|
+
var runtimeContract = require_runtime();
|
|
12995
12868
|
module2.exports = {
|
|
12996
12869
|
methods: {
|
|
12997
12870
|
async nodeLtsStatus() {
|
|
12998
12871
|
try {
|
|
12999
|
-
const cacheFile = path2.join(path2.dirname(this.config.stateFile), "node-lts-cache.json");
|
|
13000
12872
|
const now = Date.now();
|
|
13001
|
-
|
|
13002
|
-
|
|
13003
|
-
|
|
13004
|
-
} catch {
|
|
13005
|
-
}
|
|
13006
|
-
if (cache && now - (cache.fetchedAt || 0) < 6 * 3600 * 1e3) {
|
|
13007
|
-
return { ok: true, ...cache, cached: true };
|
|
13008
|
-
}
|
|
13009
|
-
const ver = process.versions.node || "";
|
|
12873
|
+
const rt = runtimeContract.read ? runtimeContract.read() : null;
|
|
12874
|
+
const shellVer = rt && rt.nodeVersion || null;
|
|
12875
|
+
const ver = shellVer || process.versions.node || "";
|
|
13010
12876
|
const major = parseInt(String(ver).split(".")[0], 10) || 0;
|
|
13011
|
-
const
|
|
13012
|
-
|
|
12877
|
+
const fromShell = !!shellVer;
|
|
12878
|
+
return {
|
|
12879
|
+
ok: true,
|
|
13013
12880
|
current: ver,
|
|
13014
12881
|
major,
|
|
13015
|
-
ltsLine,
|
|
13016
|
-
|
|
13017
|
-
|
|
12882
|
+
ltsLine: fromShell ? rt && rt.ltsLine === true : null,
|
|
12883
|
+
source: fromShell ? "shell-contract" : "process",
|
|
12884
|
+
suggested: fromShell ? "\u5F53\u524D " + ver + (rt && rt.ltsLine === true ? "\uFF08LTS \u7EBF\uFF09" : "") : "shell \u5951\u7EA6\u672A\u63D0\u4F9B Node \u7248\u672C",
|
|
12885
|
+
fetchedAt: now,
|
|
12886
|
+
cached: false
|
|
13018
12887
|
};
|
|
13019
|
-
try {
|
|
13020
|
-
fs2.writeFileSync(cacheFile, JSON.stringify(data));
|
|
13021
|
-
} catch {
|
|
13022
|
-
}
|
|
13023
|
-
return { ok: true, ...data, cached: false };
|
|
13024
12888
|
} catch (e) {
|
|
13025
12889
|
return { ok: false, error: e.message };
|
|
13026
12890
|
}
|
|
@@ -24328,6 +24192,122 @@ var require_managed_object = __commonJS({
|
|
|
24328
24192
|
}
|
|
24329
24193
|
});
|
|
24330
24194
|
|
|
24195
|
+
// src/platform/contract/pm-client.js
|
|
24196
|
+
var require_pm_client = __commonJS({
|
|
24197
|
+
"src/platform/contract/pm-client.js"(exports2, module2) {
|
|
24198
|
+
"use strict";
|
|
24199
|
+
var fs2 = require("node:fs");
|
|
24200
|
+
var path2 = require("node:path");
|
|
24201
|
+
var http2 = require("node:http");
|
|
24202
|
+
var stateRoot2 = require_state_root();
|
|
24203
|
+
var pidlookup = require_pidlookup();
|
|
24204
|
+
var FILE_NAME = "guard-mgmt.json";
|
|
24205
|
+
var SUPPORTED_SCHEMA = 1;
|
|
24206
|
+
var HOST = "127.0.0.1";
|
|
24207
|
+
var TIMEOUT_MS = 1500;
|
|
24208
|
+
var unavailableHook = null;
|
|
24209
|
+
function setUnavailableHook(fn) {
|
|
24210
|
+
unavailableHook = typeof fn === "function" ? fn : null;
|
|
24211
|
+
}
|
|
24212
|
+
function file() {
|
|
24213
|
+
return path2.join(stateRoot2.supervisorDir(), FILE_NAME);
|
|
24214
|
+
}
|
|
24215
|
+
function pidAlive2(pid) {
|
|
24216
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
24217
|
+
return pidlookup.probeAlive(pid) === "alive";
|
|
24218
|
+
}
|
|
24219
|
+
function endpoint() {
|
|
24220
|
+
let text;
|
|
24221
|
+
try {
|
|
24222
|
+
text = fs2.readFileSync(file(), "utf8");
|
|
24223
|
+
} catch {
|
|
24224
|
+
return null;
|
|
24225
|
+
}
|
|
24226
|
+
let j;
|
|
24227
|
+
try {
|
|
24228
|
+
j = JSON.parse(text);
|
|
24229
|
+
} catch {
|
|
24230
|
+
return null;
|
|
24231
|
+
}
|
|
24232
|
+
if (!j || typeof j !== "object" || j.schema !== SUPPORTED_SCHEMA) return null;
|
|
24233
|
+
const port = Number(j.port);
|
|
24234
|
+
if (!Number.isInteger(port) || port <= 0 || port > 65535) return null;
|
|
24235
|
+
if (!pidAlive2(Number(j.pid))) return null;
|
|
24236
|
+
return { port, host: typeof j.host === "string" && j.host ? j.host : HOST };
|
|
24237
|
+
}
|
|
24238
|
+
function post(route, payload) {
|
|
24239
|
+
const ep = endpoint();
|
|
24240
|
+
if (!ep) {
|
|
24241
|
+
if (unavailableHook) {
|
|
24242
|
+
try {
|
|
24243
|
+
unavailableHook(route);
|
|
24244
|
+
} catch {
|
|
24245
|
+
}
|
|
24246
|
+
}
|
|
24247
|
+
return false;
|
|
24248
|
+
}
|
|
24249
|
+
let body;
|
|
24250
|
+
try {
|
|
24251
|
+
body = JSON.stringify(payload || {});
|
|
24252
|
+
} catch {
|
|
24253
|
+
return false;
|
|
24254
|
+
}
|
|
24255
|
+
const req = http2.request(
|
|
24256
|
+
{
|
|
24257
|
+
host: ep.host,
|
|
24258
|
+
port: ep.port,
|
|
24259
|
+
path: route,
|
|
24260
|
+
method: "POST",
|
|
24261
|
+
headers: { "content-type": "application/json", "content-length": Buffer.byteLength(body) },
|
|
24262
|
+
timeout: TIMEOUT_MS
|
|
24263
|
+
},
|
|
24264
|
+
(res) => {
|
|
24265
|
+
res.resume();
|
|
24266
|
+
}
|
|
24267
|
+
);
|
|
24268
|
+
req.on("timeout", () => {
|
|
24269
|
+
try {
|
|
24270
|
+
req.destroy();
|
|
24271
|
+
} catch {
|
|
24272
|
+
}
|
|
24273
|
+
});
|
|
24274
|
+
req.on("error", () => {
|
|
24275
|
+
});
|
|
24276
|
+
try {
|
|
24277
|
+
req.end(body);
|
|
24278
|
+
return true;
|
|
24279
|
+
} catch {
|
|
24280
|
+
return false;
|
|
24281
|
+
}
|
|
24282
|
+
}
|
|
24283
|
+
module2.exports = {
|
|
24284
|
+
FILE_NAME,
|
|
24285
|
+
SUPPORTED_SCHEMA,
|
|
24286
|
+
file,
|
|
24287
|
+
endpoint,
|
|
24288
|
+
setUnavailableHook,
|
|
24289
|
+
register(desc) {
|
|
24290
|
+
return post("/pm/register", desc);
|
|
24291
|
+
},
|
|
24292
|
+
setDesired(id, desired) {
|
|
24293
|
+
return post("/pm/set-desired", { id, desired });
|
|
24294
|
+
},
|
|
24295
|
+
onPhase(id, phase) {
|
|
24296
|
+
return post("/pm/on-phase", { id, phase });
|
|
24297
|
+
},
|
|
24298
|
+
recordExit(id, code, signal, startupFailure) {
|
|
24299
|
+
return post("/pm/record-exit", { id, code, signal, startup_failure: startupFailure === true });
|
|
24300
|
+
},
|
|
24301
|
+
requestRestart(id) {
|
|
24302
|
+
return post("/pm/request-restart", { id });
|
|
24303
|
+
},
|
|
24304
|
+
resetBackoff(id) {
|
|
24305
|
+
return post("/pm/reset-backoff", { id });
|
|
24306
|
+
}
|
|
24307
|
+
};
|
|
24308
|
+
}
|
|
24309
|
+
});
|
|
24310
|
+
|
|
24331
24311
|
// src/app/control/registry.js
|
|
24332
24312
|
var require_registry4 = __commonJS({
|
|
24333
24313
|
"src/app/control/registry.js"(exports2, module2) {
|
|
@@ -24336,15 +24316,11 @@ var require_registry4 = __commonJS({
|
|
|
24336
24316
|
var path2 = require("node:path");
|
|
24337
24317
|
var { writeAtomic } = require_fs();
|
|
24338
24318
|
var { DESIRED, MANAGED_KINDS, kindMeta, registerKind: registerManagedKind, createEntry, normalizeOwnership } = require_managed_object();
|
|
24339
|
-
var { legacyToEntryPhase } = require_phase();
|
|
24340
24319
|
var PHASES = ["stopped", "installing", "starting", "running", "draining", "failed"];
|
|
24341
|
-
var
|
|
24342
|
-
var
|
|
24343
|
-
var
|
|
24344
|
-
|
|
24345
|
-
if (r && Number.isFinite(r.windowMs) && Number.isFinite(r.burst)) return { windowMs: r.windowMs, burst: r.burst };
|
|
24346
|
-
return RESTART_FALLBACK;
|
|
24347
|
-
};
|
|
24320
|
+
var LEGACY_PHASES = { backoff: "failed", restarting: "starting" };
|
|
24321
|
+
var pmClient = require_pm_client();
|
|
24322
|
+
var PM_PHASE = { installing: "starting" };
|
|
24323
|
+
var pmPhase = (p) => PM_PHASE[p] || p;
|
|
24348
24324
|
var ManagedRegistry = class {
|
|
24349
24325
|
constructor(opts) {
|
|
24350
24326
|
this.file = opts && opts.file;
|
|
@@ -24390,8 +24366,7 @@ var require_registry4 = __commonJS({
|
|
|
24390
24366
|
try {
|
|
24391
24367
|
if (!o || !kindMeta(o.kind)) continue;
|
|
24392
24368
|
const e = createEntry({ kind: o.kind, id: o.id, name: o.name, desired: o.desired, ownership: o.ownership });
|
|
24393
|
-
|
|
24394
|
-
if (PHASES.includes(np)) e.phase = np;
|
|
24369
|
+
if (PHASES.includes(LEGACY_PHASES[o.phase] || o.phase)) e.phase = LEGACY_PHASES[o.phase] || o.phase;
|
|
24395
24370
|
if (Number.isInteger(o.restartCount) && o.restartCount >= 0) e.restartCount = o.restartCount;
|
|
24396
24371
|
if (o.startupFailWindowStart === null || typeof o.startupFailWindowStart === "number") e.startupFailWindowStart = o.startupFailWindowStart;
|
|
24397
24372
|
if (Number.isInteger(o.startupFailCount) && o.startupFailCount >= 0) e.startupFailCount = o.startupFailCount;
|
|
@@ -24478,7 +24453,7 @@ var require_registry4 = __commonJS({
|
|
|
24478
24453
|
this._syncPortsOwner(e, true);
|
|
24479
24454
|
this._save();
|
|
24480
24455
|
this._event("managed_object_registered", { kind: e.kind, id: e.id, name: e.name });
|
|
24481
|
-
|
|
24456
|
+
pmClient.register({ id: e.id, spawn_cmd: [] });
|
|
24482
24457
|
return e;
|
|
24483
24458
|
}
|
|
24484
24459
|
update(id, patch) {
|
|
@@ -24488,6 +24463,7 @@ var require_registry4 = __commonJS({
|
|
|
24488
24463
|
if (p.desired !== void 0) {
|
|
24489
24464
|
if (!DESIRED.includes(p.desired)) return { ok: false, error: "\u975E\u6CD5 desired: " + p.desired };
|
|
24490
24465
|
e.desired = p.desired;
|
|
24466
|
+
pmClient.setDesired(e.id, p.desired);
|
|
24491
24467
|
}
|
|
24492
24468
|
if (p.name !== void 0) e.name = String(p.name || e.id);
|
|
24493
24469
|
if (p.ownership !== void 0) {
|
|
@@ -24519,6 +24495,7 @@ var require_registry4 = __commonJS({
|
|
|
24519
24495
|
this._drop(e);
|
|
24520
24496
|
this._save();
|
|
24521
24497
|
this._event("managed_object_removed", { kind: e.kind, id: e.id });
|
|
24498
|
+
pmClient.setDesired(e.id, "stopped");
|
|
24522
24499
|
return { ok: true };
|
|
24523
24500
|
}
|
|
24524
24501
|
_releasePort(port, ownerId) {
|
|
@@ -24580,6 +24557,7 @@ var require_registry4 = __commonJS({
|
|
|
24580
24557
|
e.lastTransitionAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
24581
24558
|
this._event("managed_object_phase", { kind: e.kind, id: e.id, phase: p });
|
|
24582
24559
|
this._save();
|
|
24560
|
+
pmClient.onPhase(e.id, pmPhase(p));
|
|
24583
24561
|
}
|
|
24584
24562
|
return e;
|
|
24585
24563
|
}
|