@dsh-sup/dsh-core-linux-x64 0.1.6-BETA.3 → 0.1.6-BETA.4

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.
Files changed (2) hide show
  1. package/core.cjs +33 -25
  2. package/package.json +1 -1
package/core.cjs CHANGED
@@ -929,7 +929,7 @@ var require_version = __commonJS({
929
929
  var fs2 = require("node:fs");
930
930
  var path2 = require("node:path");
931
931
  function guardVersion() {
932
- if (true) return String("0.1.6-BETA.3");
932
+ if (true) return String("0.1.6-BETA.4");
933
933
  try {
934
934
  return JSON.parse(fs2.readFileSync(path2.join(__dirname, "..", "..", "package.json"), "utf8")).version || "unknown";
935
935
  } catch {
@@ -2038,8 +2038,6 @@ var require_specs = __commonJS({
2038
2038
  }
2039
2039
  function sandboxSpec(inst) {
2040
2040
  if (!inst || !inst.id) return null;
2041
- const phase = inst.state && inst.state.phase;
2042
- const running = phase === "RUNNING" || phase === "STARTING" || phase === "INSTALLING";
2043
2041
  let rootPath = null;
2044
2042
  const im = instances();
2045
2043
  try {
@@ -2050,7 +2048,7 @@ var require_specs = __commonJS({
2050
2048
  kind: "sandbox-instance",
2051
2049
  id: inst.id,
2052
2050
  name: String(inst.name || inst.id),
2053
- desired: running ? "running" : "stopped",
2051
+ desired: inst.state && inst.state.desired === "stopped" ? "stopped" : "running",
2054
2052
  guardian: inst.guardian === true,
2055
2053
  ownership: {
2056
2054
  ports: [{ role: "inst", port: Number(inst.port) }],
@@ -2060,13 +2058,12 @@ var require_specs = __commonJS({
2060
2058
  }
2061
2059
  };
2062
2060
  }
2063
- function upsert(spec, opts) {
2061
+ function upsert(spec) {
2064
2062
  const m = reg();
2065
2063
  if (!m || !spec) return;
2066
- const keepDesired = !!(opts && opts.keepDesired);
2067
2064
  try {
2068
2065
  const existing = m.get(spec.id);
2069
- if (existing) m.update(spec.id, { desired: keepDesired ? void 0 : spec.desired, guardian: spec.guardian, name: spec.name, ownership: spec.ownership });
2066
+ if (existing) m.update(spec.id, { desired: spec.desired, guardian: spec.guardian, name: spec.name, ownership: spec.ownership });
2070
2067
  else m.register(spec);
2071
2068
  } catch (e) {
2072
2069
  const l = logger();
@@ -2092,7 +2089,7 @@ var require_specs = __commonJS({
2092
2089
  const sandboxes = _m && typeof _m.all === "function" && _m.all() || [];
2093
2090
  for (const inst of sandboxes) {
2094
2091
  if (inst.id === "main" || inst.domain === "native") continue;
2095
- upsert(sandboxSpec(inst), { keepDesired: true });
2092
+ upsert(sandboxSpec(inst));
2096
2093
  }
2097
2094
  const c = ctl();
2098
2095
  upsert({
@@ -3872,8 +3869,8 @@ var require_orphan_scan = __commonJS({
3872
3869
  const issues = [];
3873
3870
  try {
3874
3871
  const daemons = [
3875
- { kind: "router-daemon", port: g.getCtl().routerPort(), active: () => g.getDaemons().routerActive(), managed: () => g.getDaemons().managed(), want: () => g.getConfig().routerAutostart === true || !!(reg && reg.get("router-daemon") && reg.get("router-daemon").desired === "running") },
3876
- { kind: "lan-daemon", port: g.getCtl().lanPort(), active: () => g.getDaemons().lanActive(), managed: () => g.getDaemons().lanManaged(), want: () => g.getDaemons().enabled() || !!(reg && reg.get("lan-daemon") && reg.get("lan-daemon").desired === "running") }
3872
+ { kind: "router-daemon", port: g.getCtl().routerPort(), active: () => g.getDaemons().routerActive(), managed: () => g.getDaemons().managed(), want: () => g.getConfig().routerAutostart === true },
3873
+ { kind: "lan-daemon", port: g.getCtl().lanPort(), active: () => g.getDaemons().lanActive(), managed: () => g.getDaemons().lanManaged(), want: () => g.getDaemons().enabled() }
3877
3874
  ];
3878
3875
  for (const d of daemons) {
3879
3876
  if (!d.active()) continue;
@@ -7807,8 +7804,8 @@ var require_instance_adapter = __commonJS({
7807
7804
  return { ok: running, error: running ? null : "\u6C99\u7BB1\u5B9E\u4F8B\u672A\u8FD0\u884C" };
7808
7805
  },
7809
7806
  /** 目录项 <- 实例域状态对齐(监督拍后调用):实例已删 -> 注销(防死登记);存在 -> 经
7810
- * sandboxSpec 同步 name/guardian/ownership + phase 落目录词表。desired 不同步(keepDesired,
7811
- * 契约 M-1:观测推导不得写回应然,崩溃进 BACKOFF 不等于「用户想停」)。 */
7807
+ * sandboxSpec 同步 name/guardian/ownership + phase 落目录词表。desired 走的是实例意图字段的
7808
+ * 投影(不是 phase 推导),所以观测路径写它不会改写任何意图(契约 M-1)。 */
7812
7809
  _syncSandboxRegistryEntry(entry) {
7813
7810
  const d = depsOf(this);
7814
7811
  if (!entry || !d.managedObjects() || !d.instances()) return;
@@ -7819,7 +7816,7 @@ var require_instance_adapter = __commonJS({
7819
7816
  return;
7820
7817
  }
7821
7818
  try {
7822
- d.control().upsert(d.control().sandboxSpec(inst), { keepDesired: true });
7819
+ d.control().upsert(d.control().sandboxSpec(inst));
7823
7820
  } catch (e) {
7824
7821
  d.logger() && d.logger().warn && d.logger().warn("sandbox upsert: " + (e && e.message || e));
7825
7822
  }
@@ -9479,8 +9476,8 @@ var require_supervise = __commonJS({
9479
9476
  if (d.exitIntended()) return { ok: false, error: "exit intended" };
9480
9477
  try {
9481
9478
  if (kind === "router") {
9479
+ const wantRunning = d.config().routerAutostart === true;
9482
9480
  const rlc = d.lifecycleManager() ? d.lifecycleManager().get("router") : null;
9483
- const wantRunning = d.config().routerAutostart === true || rlc && rlc.desired === "running";
9484
9481
  if (!wantRunning) return { ok: d.daemons().routerActive() };
9485
9482
  if (!d.daemons().managed()) return { ok: d.daemons().routerActive() };
9486
9483
  const rlcx = d.daemons().lifecycle("router");
@@ -10897,7 +10894,7 @@ var require_router2 = __commonJS({
10897
10894
  config.routerAutostart = false;
10898
10895
  state.persistConfigPatch({ routerAutostart: false });
10899
10896
  if (rlc) {
10900
- rlc.desired = "stopped";
10897
+ rlc.wantStopped();
10901
10898
  rlc._monitoring = false;
10902
10899
  rlc._setPhase("stopped");
10903
10900
  rlc.healthy = false;
@@ -10908,7 +10905,7 @@ var require_router2 = __commonJS({
10908
10905
  config.routerAutostart = false;
10909
10906
  state.persistConfigPatch({ routerAutostart: false });
10910
10907
  if (rlc) {
10911
- rlc.desired = "stopped";
10908
+ rlc.wantStopped();
10912
10909
  rlc._monitoring = false;
10913
10910
  rlc._setPhase("stopped");
10914
10911
  rlc.healthy = false;
@@ -19237,6 +19234,10 @@ var require_model3 = __commonJS({
19237
19234
  inst.state.lastError = null;
19238
19235
  }
19239
19236
  if (inst.state) inst.state.phase = inst.state.phase || "STOPPED";
19237
+ if (inst.state && inst.state.desired === void 0) {
19238
+ const p = inst.state.phase;
19239
+ inst.state.desired = p === "RUNNING" || p === "STARTING" || p === "INSTALLING" ? "running" : "stopped";
19240
+ }
19240
19241
  return inst;
19241
19242
  }
19242
19243
  function createRecord(payload, id) {
@@ -19261,7 +19262,7 @@ var require_model3 = __commonJS({
19261
19262
  protectHome: payload.protectHome === void 0 ? false : !!payload.protectHome
19262
19263
  // 资源配额不接收户输入:启动时由 governor 按机器预算与活跃实例数推导。
19263
19264
  },
19264
- state: { phase: "STOPPED", restartCount: 0, backoffLevel: 0, lastProbeOk: null },
19265
+ state: { phase: "STOPPED", desired: "stopped", restartCount: 0, backoffLevel: 0, lastProbeOk: null },
19265
19266
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
19266
19267
  };
19267
19268
  }
@@ -19603,6 +19604,10 @@ var require_lifecycle = __commonJS({
19603
19604
  return { ok: false, error: adm.error };
19604
19605
  }
19605
19606
  }
19607
+ if (inst.state.desired !== "running") {
19608
+ inst.state.desired = "running";
19609
+ store.save();
19610
+ }
19606
19611
  store.ensureDirs(inst);
19607
19612
  const dshEntry = sandbox.dshEntry(instancesRoot, inst);
19608
19613
  if (!fs2.existsSync(dshEntry)) {
@@ -19613,7 +19618,8 @@ var require_lifecycle = __commonJS({
19613
19618
  }
19614
19619
  return _systemdStart(inst);
19615
19620
  }
19616
- function stop(id) {
19621
+ function stop(id, opts) {
19622
+ const transient = !!(opts && opts.intent === "transient");
19617
19623
  const inst = store.instances.find((i) => i.id === id);
19618
19624
  if (!inst) return { ok: false, error: "\u5B9E\u4F8B\u4E0D\u5B58\u5728" };
19619
19625
  if (!isSandboxSupported()) return { ok: false, error: "\u5F53\u524D\u5E73\u53F0\u4E0D\u652F\u6301\u6C99\u7BB1\u5B9E\u4F8B\uFF08\u80FD\u529B\u77E9\u9635\u89C1 GET /env/status \u7684 capabilities.sandboxLaunch\uFF1B\u9650\u989D\u6267\u884C\u6863\u4F4D\u89C1 capabilities.sandboxEnforcement\uFF09" };
@@ -19635,6 +19641,7 @@ var require_lifecycle = __commonJS({
19635
19641
  }
19636
19642
  inst.state.phase = "STOPPED";
19637
19643
  inst.state.usage = null;
19644
+ if (!transient) inst.state.desired = "stopped";
19638
19645
  runtime.delete(inst.id);
19639
19646
  store.save();
19640
19647
  if (inst.port && hooks.onInstanceStop) hooks.onInstanceStop(inst);
@@ -20138,7 +20145,7 @@ var require_upgrade = __commonJS({
20138
20145
  tasks.stepState(task.id, tasks.get(task.id).steps.indexOf(s), "running");
20139
20146
  }
20140
20147
  try {
20141
- await lifecycle.stop(id);
20148
+ await lifecycle.stop(id, { intent: "transient" });
20142
20149
  } catch {
20143
20150
  }
20144
20151
  if (task) {
@@ -20186,7 +20193,7 @@ var require_upgrade = __commonJS({
20186
20193
  tasks.log(task.id, "\u81EA\u52A8\u56DE\u6EDA\u5230 " + oldVersion + "\u2026");
20187
20194
  }
20188
20195
  try {
20189
- const rs = await lifecycle.stop(id);
20196
+ const rs = await lifecycle.stop(id, { intent: "transient" });
20190
20197
  if (rs && rs.ok === false && task) tasks.log(task.id, "\u56DE\u6EDA\u524D\u505C\u6B62\u5931\u8D25\uFF08\u7EE7\u7EED\u56DE\u88C5\u65E7\u7248\uFF09\uFF1A" + (rs.error || ""));
20191
20198
  } catch (e) {
20192
20199
  if (task) tasks.log(task.id, "\u56DE\u6EDA\u524D\u505C\u6B62\u5F02\u5E38\uFF08\u7EE7\u7EED\u56DE\u88C5\u65E7\u7248\uFF09\uFF1A" + (e && e.message || e));
@@ -20765,8 +20772,8 @@ var require_instance = __commonJS({
20765
20772
  startInstance(id, opts) {
20766
20773
  return this._lifecycle.start(id, opts);
20767
20774
  }
20768
- stopInstance(id) {
20769
- return this._lifecycle.stop(id);
20775
+ stopInstance(id, opts) {
20776
+ return this._lifecycle.stop(id, opts);
20770
20777
  }
20771
20778
  supervise(id) {
20772
20779
  return this._lifecycle.supervise(id);
@@ -21831,7 +21838,7 @@ var require_restart3 = __commonJS({
21831
21838
  log("\u91CD\u542F\u5B9E\u4F8B\u300C" + (target.name || target.id) + "\u300D\u4F7F\u63D2\u4EF6\u53D8\u66F4\u751F\u6548\u2026");
21832
21839
  if (ctx.events) ctx.events.append("plugin_restart_started", { name: target.name || target.id, target: target.id, kind });
21833
21840
  try {
21834
- ctx.instances.stopInstance(target.id);
21841
+ ctx.instances.stopInstance(target.id, { intent: "transient" });
21835
21842
  } catch (e) {
21836
21843
  log("\u505C\u6B62\u5B9E\u4F8B\u5931\u8D25: " + e.message);
21837
21844
  }
@@ -24066,6 +24073,7 @@ var require_entry = __commonJS({
24066
24073
  } catch (e) {
24067
24074
  this.error = e && e.message || String(e);
24068
24075
  this._setPhase("stopped");
24076
+ this.desired = "stopped";
24069
24077
  if (this.logger && this.logger.warn) this.logger.warn("[lifecycle] " + this.id + " start \u5931\u8D25: " + this.error);
24070
24078
  return { ok: false, error: this.error };
24071
24079
  }
@@ -24375,11 +24383,11 @@ var require_adapters = __commonJS({
24375
24383
  kind: "router",
24376
24384
  name: "\u667A\u80FD\u8DEF\u7531",
24377
24385
  logger,
24378
- start: async () => sup && typeof sup.setRouterRunning === "function" ? sup.setRouterRunning(true) : router.start(),
24386
+ start: async () => sup && typeof sup.setRouterRunning === "function" ? sup.setRouterRunning(true) : { ok: false, error: "\u7F3A setRouterRunning \u5199\u53E3\uFF1A\u542F\u505C\u4E0D\u5F97\u7ED5\u8FC7 config \u6301\u4E45\u5316" },
24379
24387
  // 守卫自身 shutdown(_stopping=true)不得停独立 daemon:守卫退出不影响被管模块,仅显式用户停止才停。
24380
24388
  stop: async () => {
24381
24389
  if (sup && sup._stopping) return { ok: true, already: true, reason: "guard-shutdown \u4E0D\u505C daemon" };
24382
- return sup && typeof sup.setRouterRunning === "function" ? sup.setRouterRunning(false) : router.stop();
24390
+ return sup && typeof sup.setRouterRunning === "function" ? sup.setRouterRunning(false) : { ok: false, error: "\u7F3A setRouterRunning \u5199\u53E3\uFF1A\u505C\u6B62\u987B\u540C\u65F6\u6E05 config \u6301\u4E45\u5316" };
24383
24391
  },
24384
24392
  // detail 走守卫真实 router 状态视图(daemon 模式经 ctl 取实时态)
24385
24393
  status: () => sup && typeof sup.routerStatus === "function" ? sup.routerStatus() : router.status ? router.status() : null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-sup/dsh-core-linux-x64",
3
- "version": "0.1.6-BETA.3",
3
+ "version": "0.1.6-BETA.4",
4
4
  "description": "DSH lifecycle guard core (Node launcher) for linux-x64 — requires Node >=18.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {