@lob-ox/core-darwin-x64 0.0.12 → 0.0.13
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 +162 -762
- 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.13");
|
|
1475
1475
|
try {
|
|
1476
1476
|
return JSON.parse(fs2.readFileSync(path2.join(__dirname, "..", "..", "package.json"), "utf8")).version || "unknown";
|
|
1477
1477
|
} catch {
|
|
@@ -1994,7 +1994,6 @@ var require_store = __commonJS({
|
|
|
1994
1994
|
const record = g.record;
|
|
1995
1995
|
const fields = g.fields;
|
|
1996
1996
|
const mainStore = g.mainStore;
|
|
1997
|
-
const upgradeHold = g.upgradeHold;
|
|
1998
1997
|
const config = () => typeof g.getConfig === "function" ? g.getConfig() || {} : {};
|
|
1999
1998
|
const logger = () => typeof g.getLogger === "function" ? g.getLogger() : null;
|
|
2000
1999
|
const events = () => typeof g.getEvents === "function" ? g.getEvents() : null;
|
|
@@ -2040,7 +2039,6 @@ var require_store = __commonJS({
|
|
|
2040
2039
|
if (typeof raw.startupFailCount === "number") record.fieldOf("startupFailCount", raw.startupFailCount, true);
|
|
2041
2040
|
if (typeof raw.lastFailure === "string" || raw.lastFailure === null) record.procFieldOf("lastFailure", raw.lastFailure, true);
|
|
2042
2041
|
if (typeof raw.lastRestartAt === "string" || raw.lastRestartAt === null) record.procFieldOf("lastRestartAt", raw.lastRestartAt, true);
|
|
2043
|
-
if (raw.upgradeHold === true) upgradeHold.enter();
|
|
2044
2042
|
if (raw.shellHalted === true && typeof g.setShellHalted === "function") g.setShellHalted(true);
|
|
2045
2043
|
} catch (e) {
|
|
2046
2044
|
const l = logger();
|
|
@@ -2200,203 +2198,6 @@ var require_desired = __commonJS({
|
|
|
2200
2198
|
}
|
|
2201
2199
|
});
|
|
2202
2200
|
|
|
2203
|
-
// src/app/main/decide.js
|
|
2204
|
-
var require_decide = __commonJS({
|
|
2205
|
-
"src/app/main/decide.js"(exports2, module2) {
|
|
2206
|
-
"use strict";
|
|
2207
|
-
var pidlook = require_pidlookup();
|
|
2208
|
-
function startDeadlinePassed(deadline, now) {
|
|
2209
|
-
return !!(deadline && now > deadline);
|
|
2210
|
-
}
|
|
2211
|
-
function childAlive(child) {
|
|
2212
|
-
return !!(child && child.exitCode === null && child.signalCode === null);
|
|
2213
|
-
}
|
|
2214
|
-
function adoptedAlive(adoptPid) {
|
|
2215
|
-
return adoptPid !== null && adoptPid !== void 0 && pidlook.isAlive(adoptPid);
|
|
2216
|
-
}
|
|
2217
|
-
function targetAlive(child, adoptPid) {
|
|
2218
|
-
return childAlive(child) || adoptedAlive(adoptPid);
|
|
2219
|
-
}
|
|
2220
|
-
var DEPS = /* @__PURE__ */ new WeakMap();
|
|
2221
|
-
function depsOf(host) {
|
|
2222
|
-
let d = DEPS.get(host);
|
|
2223
|
-
if (!d) {
|
|
2224
|
-
d = {
|
|
2225
|
-
state() {
|
|
2226
|
-
return host.state;
|
|
2227
|
-
},
|
|
2228
|
-
session() {
|
|
2229
|
-
return host.session;
|
|
2230
|
-
},
|
|
2231
|
-
upgradeHold() {
|
|
2232
|
-
return host._upgradeHold;
|
|
2233
|
-
},
|
|
2234
|
-
manualRestart() {
|
|
2235
|
-
return host.manualRestart;
|
|
2236
|
-
},
|
|
2237
|
-
crashHalted() {
|
|
2238
|
-
return host._crashHalted;
|
|
2239
|
-
},
|
|
2240
|
-
portUp() {
|
|
2241
|
-
return host._lastPortUp === true;
|
|
2242
|
-
},
|
|
2243
|
-
mChild() {
|
|
2244
|
-
return host._mChild();
|
|
2245
|
-
},
|
|
2246
|
-
mAdoptPid() {
|
|
2247
|
-
return host._mAdoptPid();
|
|
2248
|
-
},
|
|
2249
|
-
mAdopted() {
|
|
2250
|
-
return host._mAdopted();
|
|
2251
|
-
},
|
|
2252
|
-
mObservedOnly() {
|
|
2253
|
-
return host._mObservedOnly();
|
|
2254
|
-
},
|
|
2255
|
-
mSpawnBlockedUntil() {
|
|
2256
|
-
return host._mSpawnBlockedUntil();
|
|
2257
|
-
},
|
|
2258
|
-
mStartDeadline() {
|
|
2259
|
-
return host._mStartDeadline();
|
|
2260
|
-
},
|
|
2261
|
-
mRestartAt() {
|
|
2262
|
-
return host._mRestartAt();
|
|
2263
|
-
},
|
|
2264
|
-
mStartupFailWindowStart() {
|
|
2265
|
-
return host._mStartupFailWindowStart();
|
|
2266
|
-
},
|
|
2267
|
-
mStartupFailCount() {
|
|
2268
|
-
return host._mStartupFailCount();
|
|
2269
|
-
}
|
|
2270
|
-
};
|
|
2271
|
-
DEPS.set(host, d);
|
|
2272
|
-
}
|
|
2273
|
-
return d;
|
|
2274
|
-
}
|
|
2275
|
-
module2.exports = {
|
|
2276
|
-
methods: {
|
|
2277
|
-
_mainStateSnapshot() {
|
|
2278
|
-
const d = depsOf(this);
|
|
2279
|
-
const now = Date.now();
|
|
2280
|
-
const phase = d.state().phase();
|
|
2281
|
-
const startDeadline = d.mStartDeadline();
|
|
2282
|
-
return {
|
|
2283
|
-
phase,
|
|
2284
|
-
desired: d.state().desired(),
|
|
2285
|
-
portUp: d.portUp() === true,
|
|
2286
|
-
childAlive: childAlive(d.mChild()),
|
|
2287
|
-
adoptedAlive: adoptedAlive(d.mAdoptPid()),
|
|
2288
|
-
adoptedPidSet: d.mAdoptPid() !== null,
|
|
2289
|
-
childPresent: d.mChild() !== null,
|
|
2290
|
-
adopted: d.mAdopted() === true,
|
|
2291
|
-
observedOnly: d.mObservedOnly() === true,
|
|
2292
|
-
upgradeHold: d.upgradeHold() === true,
|
|
2293
|
-
manualRestart: d.manualRestart() === true,
|
|
2294
|
-
spawnBlocked: !!(d.mSpawnBlockedUntil() && now < d.mSpawnBlockedUntil()),
|
|
2295
|
-
startDeadlinePassed: startDeadlinePassed(startDeadline, now),
|
|
2296
|
-
restartInFlight: phase === "STARTING" && startDeadline === null,
|
|
2297
|
-
restartDue: d.mRestartAt() === null || now >= d.mRestartAt(),
|
|
2298
|
-
crashHalted: d.crashHalted() === true,
|
|
2299
|
-
sessionHalting: d.session().halting() === true,
|
|
2300
|
-
startupFailWindowStart: d.mStartupFailWindowStart(),
|
|
2301
|
-
startupFailCount: d.mStartupFailCount()
|
|
2302
|
-
};
|
|
2303
|
-
}
|
|
2304
|
-
},
|
|
2305
|
-
startDeadlinePassed,
|
|
2306
|
-
childAlive,
|
|
2307
|
-
adoptedAlive,
|
|
2308
|
-
targetAlive
|
|
2309
|
-
};
|
|
2310
|
-
}
|
|
2311
|
-
});
|
|
2312
|
-
|
|
2313
|
-
// src/app/state/upgrade-hold.js
|
|
2314
|
-
var require_upgrade_hold = __commonJS({
|
|
2315
|
-
"src/app/state/upgrade-hold.js"(exports2, module2) {
|
|
2316
|
-
"use strict";
|
|
2317
|
-
var pidlook = require_pidlookup();
|
|
2318
|
-
var { childAlive: childAliveOf, adoptedAlive: adoptedAliveOf } = require_decide();
|
|
2319
|
-
function createUpgradeHold(deps) {
|
|
2320
|
-
const g = deps || {};
|
|
2321
|
-
const fields = g.fields;
|
|
2322
|
-
const store = () => typeof g.getStore === "function" ? g.getStore() : null;
|
|
2323
|
-
const config = () => typeof g.getConfig === "function" ? g.getConfig() || {} : {};
|
|
2324
|
-
const intents = () => typeof g.getIntents === "function" ? g.getIntents() : null;
|
|
2325
|
-
const tick = () => {
|
|
2326
|
-
if (typeof g.tick === "function") g.tick();
|
|
2327
|
-
};
|
|
2328
|
-
const stopProcess = (why) => {
|
|
2329
|
-
if (typeof g.stopProcess === "function") g.stopProcess(why);
|
|
2330
|
-
};
|
|
2331
|
-
const setHold = typeof g.setHold === "function" ? g.setHold : () => {
|
|
2332
|
-
};
|
|
2333
|
-
const setSince = typeof g.setSince === "function" ? g.setSince : () => {
|
|
2334
|
-
};
|
|
2335
|
-
function enter() {
|
|
2336
|
-
setHold(true);
|
|
2337
|
-
setSince(Date.now());
|
|
2338
|
-
const child = fields.child();
|
|
2339
|
-
const adoptPid = fields.adoptPid();
|
|
2340
|
-
const targetAlive = childAliveOf(child) || adoptedAliveOf(adoptPid);
|
|
2341
|
-
if (targetAlive) {
|
|
2342
|
-
stopProcess("upgrade");
|
|
2343
|
-
} else if (fields.phase() !== "STOPPED") {
|
|
2344
|
-
fields.setPhase("STOPPED");
|
|
2345
|
-
const s = store();
|
|
2346
|
-
if (s) s.writeState();
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
async function enterAsync() {
|
|
2350
|
-
const refs = { child: fields.child(), adoptedPid: fields.adoptPid() };
|
|
2351
|
-
enter();
|
|
2352
|
-
if (childAliveOf(refs.child)) {
|
|
2353
|
-
await new Promise((resolve) => {
|
|
2354
|
-
let settled = false;
|
|
2355
|
-
const done = () => {
|
|
2356
|
-
if (!settled) {
|
|
2357
|
-
settled = true;
|
|
2358
|
-
resolve();
|
|
2359
|
-
}
|
|
2360
|
-
};
|
|
2361
|
-
refs.child.once("exit", done);
|
|
2362
|
-
setTimeout(done, config().stopGraceMs + 5e3);
|
|
2363
|
-
});
|
|
2364
|
-
return;
|
|
2365
|
-
}
|
|
2366
|
-
if (refs.adoptedPid && pidlook.isAlive(refs.adoptedPid)) {
|
|
2367
|
-
await new Promise((resolve) => {
|
|
2368
|
-
let settled = false;
|
|
2369
|
-
const done = () => {
|
|
2370
|
-
if (!settled) {
|
|
2371
|
-
settled = true;
|
|
2372
|
-
resolve();
|
|
2373
|
-
}
|
|
2374
|
-
};
|
|
2375
|
-
const start = Date.now();
|
|
2376
|
-
const check = () => {
|
|
2377
|
-
if (!pidlook.isAlive(refs.adoptedPid)) return done();
|
|
2378
|
-
if (Date.now() > start + config().stopGraceMs + 5e3) return done();
|
|
2379
|
-
setTimeout(check, 200);
|
|
2380
|
-
};
|
|
2381
|
-
check();
|
|
2382
|
-
});
|
|
2383
|
-
}
|
|
2384
|
-
}
|
|
2385
|
-
function exit(explicit) {
|
|
2386
|
-
setHold(false);
|
|
2387
|
-
setSince(null);
|
|
2388
|
-
if (explicit) {
|
|
2389
|
-
const it = intents();
|
|
2390
|
-
if (it) it.register("upgrade-resume");
|
|
2391
|
-
}
|
|
2392
|
-
tick();
|
|
2393
|
-
}
|
|
2394
|
-
return { enter, enterAsync, exit };
|
|
2395
|
-
}
|
|
2396
|
-
module2.exports = { createUpgradeHold };
|
|
2397
|
-
}
|
|
2398
|
-
});
|
|
2399
|
-
|
|
2400
2201
|
// src/app/state/collaborator.js
|
|
2401
2202
|
var require_collaborator = __commonJS({
|
|
2402
2203
|
"src/app/state/collaborator.js"(exports2, module2) {
|
|
@@ -2406,7 +2207,6 @@ var require_collaborator = __commonJS({
|
|
|
2406
2207
|
var { createFields } = require_fields();
|
|
2407
2208
|
var { createStore } = require_store();
|
|
2408
2209
|
var { createDesired } = require_desired();
|
|
2409
|
-
var { createUpgradeHold } = require_upgrade_hold();
|
|
2410
2210
|
function createStateStore(deps) {
|
|
2411
2211
|
const g = deps || {};
|
|
2412
2212
|
const logger = () => typeof g.getLogger === "function" ? g.getLogger() : null;
|
|
@@ -2414,21 +2214,10 @@ var require_collaborator = __commonJS({
|
|
|
2414
2214
|
const mainStore = createMainStore({ getConfig: g.getConfig, getLogger: logger });
|
|
2415
2215
|
const fields = createFields({ record, mainStore, getManagedObjects: g.getManagedObjects, getLogger: logger });
|
|
2416
2216
|
const holder = {};
|
|
2417
|
-
const upgradeHold = createUpgradeHold({
|
|
2418
|
-
fields,
|
|
2419
|
-
getStore: () => holder.store,
|
|
2420
|
-
getConfig: g.getConfig,
|
|
2421
|
-
getIntents: g.getIntents,
|
|
2422
|
-
tick: g.tick,
|
|
2423
|
-
stopProcess: g.stopProcess,
|
|
2424
|
-
setHold: g.setHold,
|
|
2425
|
-
setSince: g.setSince
|
|
2426
|
-
});
|
|
2427
2217
|
const store = createStore({
|
|
2428
2218
|
record,
|
|
2429
2219
|
fields,
|
|
2430
2220
|
mainStore,
|
|
2431
|
-
upgradeHold,
|
|
2432
2221
|
getConfig: g.getConfig,
|
|
2433
2222
|
getLogger: logger,
|
|
2434
2223
|
getEvents: g.getEvents,
|
|
@@ -2474,10 +2263,7 @@ var require_collaborator = __commonJS({
|
|
|
2474
2263
|
loadState: store.loadState,
|
|
2475
2264
|
migrateMainRecord: store.migrateMainRecord,
|
|
2476
2265
|
setDesiredPublic: desired.setDesired,
|
|
2477
|
-
requestRestart: desired.requestRestart
|
|
2478
|
-
enterUpgradeHold: upgradeHold.enter,
|
|
2479
|
-
enterUpgradeHoldAsync: upgradeHold.enterAsync,
|
|
2480
|
-
exitUpgradeHold: upgradeHold.exit
|
|
2266
|
+
requestRestart: desired.requestRestart
|
|
2481
2267
|
};
|
|
2482
2268
|
}
|
|
2483
2269
|
module2.exports = { createStateStore };
|
|
@@ -4704,8 +4490,6 @@ var require_collaborators = __commonJS({
|
|
|
4704
4490
|
},
|
|
4705
4491
|
main: {
|
|
4706
4492
|
converge: "_dshConverge",
|
|
4707
|
-
noteStartupFailure: "_noteStartupFailure",
|
|
4708
|
-
retryStartupFailure: "_retryStartupFailure",
|
|
4709
4493
|
startWindowMs: "startWindowMs",
|
|
4710
4494
|
adopt: "_adopt",
|
|
4711
4495
|
adoptObserved: "_adoptObserved",
|
|
@@ -4776,14 +4560,6 @@ var require_collaborators = __commonJS({
|
|
|
4776
4560
|
setManualRestart: (v) => {
|
|
4777
4561
|
host.manualRestart = v;
|
|
4778
4562
|
},
|
|
4779
|
-
getHold: () => host._upgradeHold,
|
|
4780
|
-
setHold: (v) => {
|
|
4781
|
-
host._upgradeHold = v;
|
|
4782
|
-
},
|
|
4783
|
-
getSince: () => host._upgradeHoldSince,
|
|
4784
|
-
setSince: (v) => {
|
|
4785
|
-
host._upgradeHoldSince = v;
|
|
4786
|
-
},
|
|
4787
4563
|
getShellHalted: () => host._shellHalted,
|
|
4788
4564
|
setShellHalted: (v) => {
|
|
4789
4565
|
host._shellHalted = v;
|
|
@@ -4811,9 +4587,6 @@ var require_collaborators = __commonJS({
|
|
|
4811
4587
|
host.setDesired = (v) => state.setDesiredPublic(v);
|
|
4812
4588
|
host.requestRestart = () => state.requestRestart();
|
|
4813
4589
|
host.persistConfigPatch = (patch) => state.persistConfigPatch(patch);
|
|
4814
|
-
host._enterUpgradeHold = () => state.enterUpgradeHold();
|
|
4815
|
-
host._enterUpgradeHoldAsync = () => state.enterUpgradeHoldAsync();
|
|
4816
|
-
host._exitUpgradeHold = (explicit) => state.exitUpgradeHold(explicit);
|
|
4817
4590
|
installFieldHelpers(host, state);
|
|
4818
4591
|
for (const name of Object.keys(state.accessors)) Object.defineProperty(host, name, state.accessors[name]);
|
|
4819
4592
|
}
|
|
@@ -8068,122 +7841,6 @@ var require_os = __commonJS({
|
|
|
8068
7841
|
}
|
|
8069
7842
|
});
|
|
8070
7843
|
|
|
8071
|
-
// src/platform/contract/pm-client.js
|
|
8072
|
-
var require_pm_client = __commonJS({
|
|
8073
|
-
"src/platform/contract/pm-client.js"(exports2, module2) {
|
|
8074
|
-
"use strict";
|
|
8075
|
-
var fs2 = require("node:fs");
|
|
8076
|
-
var path2 = require("node:path");
|
|
8077
|
-
var http2 = require("node:http");
|
|
8078
|
-
var stateRoot2 = require_state_root();
|
|
8079
|
-
var pidlookup = require_pidlookup();
|
|
8080
|
-
var FILE_NAME = "guard-mgmt.json";
|
|
8081
|
-
var SUPPORTED_SCHEMA = 1;
|
|
8082
|
-
var HOST = "127.0.0.1";
|
|
8083
|
-
var TIMEOUT_MS = 1500;
|
|
8084
|
-
var unavailableHook = null;
|
|
8085
|
-
function setUnavailableHook(fn) {
|
|
8086
|
-
unavailableHook = typeof fn === "function" ? fn : null;
|
|
8087
|
-
}
|
|
8088
|
-
function file() {
|
|
8089
|
-
return path2.join(stateRoot2.supervisorDir(), FILE_NAME);
|
|
8090
|
-
}
|
|
8091
|
-
function pidAlive2(pid) {
|
|
8092
|
-
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
8093
|
-
return pidlookup.probeAlive(pid) === "alive";
|
|
8094
|
-
}
|
|
8095
|
-
function endpoint() {
|
|
8096
|
-
let text;
|
|
8097
|
-
try {
|
|
8098
|
-
text = fs2.readFileSync(file(), "utf8");
|
|
8099
|
-
} catch {
|
|
8100
|
-
return null;
|
|
8101
|
-
}
|
|
8102
|
-
let j;
|
|
8103
|
-
try {
|
|
8104
|
-
j = JSON.parse(text);
|
|
8105
|
-
} catch {
|
|
8106
|
-
return null;
|
|
8107
|
-
}
|
|
8108
|
-
if (!j || typeof j !== "object" || j.schema !== SUPPORTED_SCHEMA) return null;
|
|
8109
|
-
const port = Number(j.port);
|
|
8110
|
-
if (!Number.isInteger(port) || port <= 0 || port > 65535) return null;
|
|
8111
|
-
if (!pidAlive2(Number(j.pid))) return null;
|
|
8112
|
-
return { port, host: typeof j.host === "string" && j.host ? j.host : HOST };
|
|
8113
|
-
}
|
|
8114
|
-
function post(route, payload) {
|
|
8115
|
-
const ep = endpoint();
|
|
8116
|
-
if (!ep) {
|
|
8117
|
-
if (unavailableHook) {
|
|
8118
|
-
try {
|
|
8119
|
-
unavailableHook(route);
|
|
8120
|
-
} catch {
|
|
8121
|
-
}
|
|
8122
|
-
}
|
|
8123
|
-
return false;
|
|
8124
|
-
}
|
|
8125
|
-
let body;
|
|
8126
|
-
try {
|
|
8127
|
-
body = JSON.stringify(payload || {});
|
|
8128
|
-
} catch {
|
|
8129
|
-
return false;
|
|
8130
|
-
}
|
|
8131
|
-
const req = http2.request(
|
|
8132
|
-
{
|
|
8133
|
-
host: ep.host,
|
|
8134
|
-
port: ep.port,
|
|
8135
|
-
path: route,
|
|
8136
|
-
method: "POST",
|
|
8137
|
-
headers: { "content-type": "application/json", "content-length": Buffer.byteLength(body) },
|
|
8138
|
-
timeout: TIMEOUT_MS
|
|
8139
|
-
},
|
|
8140
|
-
(res) => {
|
|
8141
|
-
res.resume();
|
|
8142
|
-
}
|
|
8143
|
-
);
|
|
8144
|
-
req.on("timeout", () => {
|
|
8145
|
-
try {
|
|
8146
|
-
req.destroy();
|
|
8147
|
-
} catch {
|
|
8148
|
-
}
|
|
8149
|
-
});
|
|
8150
|
-
req.on("error", () => {
|
|
8151
|
-
});
|
|
8152
|
-
try {
|
|
8153
|
-
req.end(body);
|
|
8154
|
-
return true;
|
|
8155
|
-
} catch {
|
|
8156
|
-
return false;
|
|
8157
|
-
}
|
|
8158
|
-
}
|
|
8159
|
-
module2.exports = {
|
|
8160
|
-
FILE_NAME,
|
|
8161
|
-
SUPPORTED_SCHEMA,
|
|
8162
|
-
file,
|
|
8163
|
-
endpoint,
|
|
8164
|
-
setUnavailableHook,
|
|
8165
|
-
register(desc) {
|
|
8166
|
-
return post("/pm/register", desc);
|
|
8167
|
-
},
|
|
8168
|
-
setDesired(id, desired) {
|
|
8169
|
-
return post("/pm/set-desired", { id, desired });
|
|
8170
|
-
},
|
|
8171
|
-
onPhase(id, phase) {
|
|
8172
|
-
return post("/pm/on-phase", { id, phase });
|
|
8173
|
-
},
|
|
8174
|
-
recordExit(id, code, signal, startupFailure) {
|
|
8175
|
-
return post("/pm/record-exit", { id, code, signal, startup_failure: startupFailure === true });
|
|
8176
|
-
},
|
|
8177
|
-
requestRestart(id) {
|
|
8178
|
-
return post("/pm/request-restart", { id });
|
|
8179
|
-
},
|
|
8180
|
-
resetBackoff(id) {
|
|
8181
|
-
return post("/pm/reset-backoff", { id });
|
|
8182
|
-
}
|
|
8183
|
-
};
|
|
8184
|
-
}
|
|
8185
|
-
});
|
|
8186
|
-
|
|
8187
7844
|
// src/app/assembly/bootstrap.js
|
|
8188
7845
|
var require_bootstrap = __commonJS({
|
|
8189
7846
|
"src/app/assembly/bootstrap.js"(exports2, module2) {
|
|
@@ -8199,15 +7856,6 @@ var require_bootstrap = __commonJS({
|
|
|
8199
7856
|
var platform = require_os();
|
|
8200
7857
|
var ENV_FORM_STARTUP_DELAY_MS = 3e3;
|
|
8201
7858
|
function _bootstrap(host) {
|
|
8202
|
-
try {
|
|
8203
|
-
require_pm_client().setUnavailableHook((route) => {
|
|
8204
|
-
try {
|
|
8205
|
-
host.events.append("pm_endpoint_unavailable", { route });
|
|
8206
|
-
} catch {
|
|
8207
|
-
}
|
|
8208
|
-
});
|
|
8209
|
-
} catch {
|
|
8210
|
-
}
|
|
8211
7859
|
try {
|
|
8212
7860
|
host.events.append("guard_started", {
|
|
8213
7861
|
pid: process.pid,
|
|
@@ -10140,44 +9788,6 @@ var require_scheduler = __commonJS({
|
|
|
10140
9788
|
async tick() {
|
|
10141
9789
|
const d = depsOf(this);
|
|
10142
9790
|
return d.main().converge();
|
|
10143
|
-
},
|
|
10144
|
-
async _dshSuperviseOnce() {
|
|
10145
|
-
const d = depsOf(this);
|
|
10146
|
-
try {
|
|
10147
|
-
if (d.stopping()) return { ok: false, error: "guard stopping" };
|
|
10148
|
-
if (d.exitIntended()) return { ok: false, error: "exit intended" };
|
|
10149
|
-
await d.main().converge();
|
|
10150
|
-
try {
|
|
10151
|
-
d.control().syncInstancesView();
|
|
10152
|
-
} catch (e) {
|
|
10153
|
-
d.logger() && d.logger().warn && d.logger().warn("instances view sync: " + (e && e.message || e));
|
|
10154
|
-
}
|
|
10155
|
-
} catch (e) {
|
|
10156
|
-
d.logger() && d.logger().warn && d.logger().warn("[dsh] supervise \u5F02\u5E38: " + (e && e.message || e));
|
|
10157
|
-
}
|
|
10158
|
-
try {
|
|
10159
|
-
const now = Date.now();
|
|
10160
|
-
if (!d.readLastOrphanAuditAt() || now - d.readLastOrphanAuditAt() > 6e4) {
|
|
10161
|
-
d.writeLastOrphanAuditAt(now);
|
|
10162
|
-
d.audit().orphan();
|
|
10163
|
-
}
|
|
10164
|
-
} catch (e) {
|
|
10165
|
-
d.logger() && d.logger().debug && d.logger().debug("orphan audit: " + (e && e.message || e));
|
|
10166
|
-
}
|
|
10167
|
-
if (d.eventHub()) {
|
|
10168
|
-
try {
|
|
10169
|
-
await d.eventHub().sync();
|
|
10170
|
-
} catch (e) {
|
|
10171
|
-
d.logger() && d.logger().debug && d.logger().debug("eventHub sync: " + (e && e.message || e));
|
|
10172
|
-
}
|
|
10173
|
-
}
|
|
10174
|
-
const snap = d.mainSnapshot();
|
|
10175
|
-
const alive = !!(snap && (snap.childAlive || snap.adoptedAlive));
|
|
10176
|
-
const ph = d.state().phase();
|
|
10177
|
-
return {
|
|
10178
|
-
ok: alive,
|
|
10179
|
-
error: alive ? null : ph === "FAILED" ? "\u542F\u52A8\u53CD\u590D\u5931\u8D25\uFF1A\u5DF2\u505C\u6B62\u81EA\u52A8\u91CD\u542F\uFF0C\u7B49\u5F85\u4EBA\u5DE5\u91CD\u8BD5" : ph === "STARTING" ? "\u542F\u52A8\u7A97\u53E3\u5185\u8FDB\u7A0B\u5DF2\u9000\u51FA\uFF0C\u7B49\u5F85\u91CD\u542F" : "\u8FDB\u7A0B\u672A\u8FD0\u884C"
|
|
10180
|
-
};
|
|
10181
9791
|
}
|
|
10182
9792
|
}
|
|
10183
9793
|
};
|
|
@@ -10266,7 +9876,113 @@ var require_instance_adapter = __commonJS({
|
|
|
10266
9876
|
d.logger() && d.logger().warn && d.logger().warn("sandbox setRestartCount: " + (e && e.message || e));
|
|
10267
9877
|
}
|
|
10268
9878
|
}
|
|
10269
|
-
}
|
|
9879
|
+
}
|
|
9880
|
+
};
|
|
9881
|
+
}
|
|
9882
|
+
});
|
|
9883
|
+
|
|
9884
|
+
// src/app/main/decide.js
|
|
9885
|
+
var require_decide = __commonJS({
|
|
9886
|
+
"src/app/main/decide.js"(exports2, module2) {
|
|
9887
|
+
"use strict";
|
|
9888
|
+
var pidlook = require_pidlookup();
|
|
9889
|
+
function startDeadlinePassed(deadline, now) {
|
|
9890
|
+
return !!(deadline && now > deadline);
|
|
9891
|
+
}
|
|
9892
|
+
function childAlive(child) {
|
|
9893
|
+
return !!(child && child.exitCode === null && child.signalCode === null);
|
|
9894
|
+
}
|
|
9895
|
+
function adoptedAlive(adoptPid) {
|
|
9896
|
+
return adoptPid !== null && adoptPid !== void 0 && pidlook.isAlive(adoptPid);
|
|
9897
|
+
}
|
|
9898
|
+
function targetAlive(child, adoptPid) {
|
|
9899
|
+
return childAlive(child) || adoptedAlive(adoptPid);
|
|
9900
|
+
}
|
|
9901
|
+
var DEPS = /* @__PURE__ */ new WeakMap();
|
|
9902
|
+
function depsOf(host) {
|
|
9903
|
+
let d = DEPS.get(host);
|
|
9904
|
+
if (!d) {
|
|
9905
|
+
d = {
|
|
9906
|
+
state() {
|
|
9907
|
+
return host.state;
|
|
9908
|
+
},
|
|
9909
|
+
session() {
|
|
9910
|
+
return host.session;
|
|
9911
|
+
},
|
|
9912
|
+
manualRestart() {
|
|
9913
|
+
return host.manualRestart;
|
|
9914
|
+
},
|
|
9915
|
+
crashHalted() {
|
|
9916
|
+
return host._crashHalted;
|
|
9917
|
+
},
|
|
9918
|
+
portUp() {
|
|
9919
|
+
return host._lastPortUp === true;
|
|
9920
|
+
},
|
|
9921
|
+
mChild() {
|
|
9922
|
+
return host._mChild();
|
|
9923
|
+
},
|
|
9924
|
+
mAdoptPid() {
|
|
9925
|
+
return host._mAdoptPid();
|
|
9926
|
+
},
|
|
9927
|
+
mAdopted() {
|
|
9928
|
+
return host._mAdopted();
|
|
9929
|
+
},
|
|
9930
|
+
mObservedOnly() {
|
|
9931
|
+
return host._mObservedOnly();
|
|
9932
|
+
},
|
|
9933
|
+
mSpawnBlockedUntil() {
|
|
9934
|
+
return host._mSpawnBlockedUntil();
|
|
9935
|
+
},
|
|
9936
|
+
mStartDeadline() {
|
|
9937
|
+
return host._mStartDeadline();
|
|
9938
|
+
},
|
|
9939
|
+
mRestartAt() {
|
|
9940
|
+
return host._mRestartAt();
|
|
9941
|
+
},
|
|
9942
|
+
mStartupFailWindowStart() {
|
|
9943
|
+
return host._mStartupFailWindowStart();
|
|
9944
|
+
},
|
|
9945
|
+
mStartupFailCount() {
|
|
9946
|
+
return host._mStartupFailCount();
|
|
9947
|
+
}
|
|
9948
|
+
};
|
|
9949
|
+
DEPS.set(host, d);
|
|
9950
|
+
}
|
|
9951
|
+
return d;
|
|
9952
|
+
}
|
|
9953
|
+
module2.exports = {
|
|
9954
|
+
methods: {
|
|
9955
|
+
_mainStateSnapshot() {
|
|
9956
|
+
const d = depsOf(this);
|
|
9957
|
+
const now = Date.now();
|
|
9958
|
+
const phase = d.state().phase();
|
|
9959
|
+
const startDeadline = d.mStartDeadline();
|
|
9960
|
+
return {
|
|
9961
|
+
phase,
|
|
9962
|
+
desired: d.state().desired(),
|
|
9963
|
+
portUp: d.portUp() === true,
|
|
9964
|
+
childAlive: childAlive(d.mChild()),
|
|
9965
|
+
adoptedAlive: adoptedAlive(d.mAdoptPid()),
|
|
9966
|
+
adoptedPidSet: d.mAdoptPid() !== null,
|
|
9967
|
+
childPresent: d.mChild() !== null,
|
|
9968
|
+
adopted: d.mAdopted() === true,
|
|
9969
|
+
observedOnly: d.mObservedOnly() === true,
|
|
9970
|
+
manualRestart: d.manualRestart() === true,
|
|
9971
|
+
spawnBlocked: !!(d.mSpawnBlockedUntil() && now < d.mSpawnBlockedUntil()),
|
|
9972
|
+
startDeadlinePassed: startDeadlinePassed(startDeadline, now),
|
|
9973
|
+
restartInFlight: phase === "STARTING" && startDeadline === null,
|
|
9974
|
+
restartDue: d.mRestartAt() === null || now >= d.mRestartAt(),
|
|
9975
|
+
crashHalted: d.crashHalted() === true,
|
|
9976
|
+
sessionHalting: d.session().halting() === true,
|
|
9977
|
+
startupFailWindowStart: d.mStartupFailWindowStart(),
|
|
9978
|
+
startupFailCount: d.mStartupFailCount()
|
|
9979
|
+
};
|
|
9980
|
+
}
|
|
9981
|
+
},
|
|
9982
|
+
startDeadlinePassed,
|
|
9983
|
+
childAlive,
|
|
9984
|
+
adoptedAlive,
|
|
9985
|
+
targetAlive
|
|
10270
9986
|
};
|
|
10271
9987
|
}
|
|
10272
9988
|
});
|
|
@@ -10397,18 +10113,6 @@ var require_controller = __commonJS({
|
|
|
10397
10113
|
writeLastPortUp(v) {
|
|
10398
10114
|
host._lastPortUp = v;
|
|
10399
10115
|
},
|
|
10400
|
-
upgradeHold() {
|
|
10401
|
-
return host._upgradeHold;
|
|
10402
|
-
},
|
|
10403
|
-
writeUpgradeHold(v) {
|
|
10404
|
-
host._upgradeHold = v;
|
|
10405
|
-
},
|
|
10406
|
-
upgradeHoldSince() {
|
|
10407
|
-
return host._upgradeHoldSince;
|
|
10408
|
-
},
|
|
10409
|
-
writeUpgradeHoldSince(v) {
|
|
10410
|
-
host._upgradeHoldSince = v;
|
|
10411
|
-
},
|
|
10412
10116
|
manualRestart() {
|
|
10413
10117
|
return host.manualRestart;
|
|
10414
10118
|
},
|
|
@@ -10512,22 +10216,6 @@ var require_controller = __commonJS({
|
|
|
10512
10216
|
d.state().write();
|
|
10513
10217
|
return;
|
|
10514
10218
|
}
|
|
10515
|
-
if (d.upgradeHold()) {
|
|
10516
|
-
if (targetAlive) {
|
|
10517
|
-
d.main().stopProcess("upgrade_hold");
|
|
10518
|
-
} else {
|
|
10519
|
-
if (d.state().phase() !== "STOPPED") d.state().setPhase("STOPPED");
|
|
10520
|
-
const maxHold = (d.config().upgradeTimeoutMs || 6e5) + 12e4;
|
|
10521
|
-
if (d.upgradeHoldSince() && Date.now() - d.upgradeHoldSince() > maxHold) {
|
|
10522
|
-
d.events().append("upgrade_hold_timeout", {});
|
|
10523
|
-
d.ui().notify("\u5347\u7EA7\u6D41\u7A0B\u5F02\u5E38", "\u5347\u7EA7 hold \u8D85\u65F6\u5DF2\u81EA\u52A8\u91CA\u653E\uFF0C\u8BF7\u68C0\u67E5\u5347\u7EA7\u72B6\u6001");
|
|
10524
|
-
d.writeUpgradeHold(false);
|
|
10525
|
-
d.writeUpgradeHoldSince(null);
|
|
10526
|
-
}
|
|
10527
|
-
}
|
|
10528
|
-
d.state().write();
|
|
10529
|
-
return;
|
|
10530
|
-
}
|
|
10531
10219
|
const manual = d.manualRestart();
|
|
10532
10220
|
if (manual) {
|
|
10533
10221
|
d.writeManualRestart(false);
|
|
@@ -10611,7 +10299,6 @@ var require_controller = __commonJS({
|
|
|
10611
10299
|
const wantsRetry = manual || startIntent !== void 0 || restartIntent !== void 0;
|
|
10612
10300
|
if (!wantsRetry) break;
|
|
10613
10301
|
if (d.state().desired() === "stopped") break;
|
|
10614
|
-
d.main().retryStartupFailure();
|
|
10615
10302
|
d.mSetStartDeadline(null);
|
|
10616
10303
|
d.mSetRestartAt(null);
|
|
10617
10304
|
if (targetAlive) d.main().beginRestart("manual", { manual: true, startupFailure: false });
|
|
@@ -10905,7 +10592,6 @@ var require_process2 = __commonJS({
|
|
|
10905
10592
|
var native = require_command();
|
|
10906
10593
|
var BRAND2 = require_brand();
|
|
10907
10594
|
var { findManagedDshPort, applyMainPort } = require_port_rederive();
|
|
10908
|
-
var pmClient = require_pm_client();
|
|
10909
10595
|
var DEPS = /* @__PURE__ */ new WeakMap();
|
|
10910
10596
|
var HELPERS = [
|
|
10911
10597
|
"MissingNotified",
|
|
@@ -11040,7 +10726,6 @@ var require_process2 = __commonJS({
|
|
|
11040
10726
|
errBuf.flush();
|
|
11041
10727
|
if (d.mChild() !== child) return;
|
|
11042
10728
|
d.events().append(BRAND2.EVENT_HARNESS_EXITED, { code, signal, phase: d.state().phase() });
|
|
11043
|
-
pmClient.recordExit("main", code, signal, d.state().phase() === "STARTING");
|
|
11044
10729
|
d.mSetChild(null);
|
|
11045
10730
|
if (d.stopping()) return;
|
|
11046
10731
|
if (d.state().desired() !== "running") return;
|
|
@@ -11050,7 +10735,6 @@ var require_process2 = __commonJS({
|
|
|
11050
10735
|
const why = code !== null ? String(code) : "sig" + signal;
|
|
11051
10736
|
const inStartup = phase === "STARTING";
|
|
11052
10737
|
if (inStartup || d.state().guardian()) {
|
|
11053
|
-
pmClient.requestRestart("main");
|
|
11054
10738
|
d.beginRestart("exit:" + why, { startupFailure: inStartup });
|
|
11055
10739
|
} else {
|
|
11056
10740
|
d.writeCrashHalted(true);
|
|
@@ -11139,7 +10823,7 @@ var require_process2 = __commonJS({
|
|
|
11139
10823
|
d.logger().warn("restart triggered: " + reason + (startupFailure ? "\uFF08\u542F\u52A8\u7A97\u53E3\u5185\u9000\u51FA\uFF0C\u8BA1\u4E00\u6B21\u542F\u52A8\u5931\u8D25\uFF09" : "\uFF08\u6B63\u5E38\u91CD\u542F\uFF09"));
|
|
11140
10824
|
d.tokenService().clear("main");
|
|
11141
10825
|
if (!manual) d.mSetRestartCount(d.mRestartCount() + 1);
|
|
11142
|
-
const throttle =
|
|
10826
|
+
const throttle = null;
|
|
11143
10827
|
if (throttle && throttle.failed) {
|
|
11144
10828
|
d.mSetRestartAt(null);
|
|
11145
10829
|
} else {
|
|
@@ -11367,247 +11051,6 @@ var require_signals = __commonJS({
|
|
|
11367
11051
|
}
|
|
11368
11052
|
});
|
|
11369
11053
|
|
|
11370
|
-
// src/shared/guardian.js
|
|
11371
|
-
var require_guardian = __commonJS({
|
|
11372
|
-
"src/shared/guardian.js"(exports2, module2) {
|
|
11373
|
-
"use strict";
|
|
11374
|
-
function shouldGuard(inst) {
|
|
11375
|
-
return !!(inst && inst.guardian === true);
|
|
11376
|
-
}
|
|
11377
|
-
function bumpStartupFailure(w, now, cfg) {
|
|
11378
|
-
const windowMs = cfg && Number(cfg.windowMs) > 0 ? Number(cfg.windowMs) : 6e4;
|
|
11379
|
-
const burst = cfg && Number(cfg.burst) >= 1 ? Number(cfg.burst) : 5;
|
|
11380
|
-
let start = w.start;
|
|
11381
|
-
let count = w.count;
|
|
11382
|
-
if (start === null || start === void 0 || now - start > windowMs) {
|
|
11383
|
-
start = now;
|
|
11384
|
-
count = 1;
|
|
11385
|
-
} else {
|
|
11386
|
-
count += 1;
|
|
11387
|
-
}
|
|
11388
|
-
return { start, count, tripped: count >= burst };
|
|
11389
|
-
}
|
|
11390
|
-
function makeBudget(cfg) {
|
|
11391
|
-
const windowMs = cfg && Number(cfg.windowMs) > 0 ? Number(cfg.windowMs) : 6e4;
|
|
11392
|
-
const burst = cfg && Number(cfg.burst) >= 1 ? Number(cfg.burst) : 5;
|
|
11393
|
-
let state = { start: null, count: 0 };
|
|
11394
|
-
const self = {
|
|
11395
|
-
windowMs,
|
|
11396
|
-
burst,
|
|
11397
|
-
get count() {
|
|
11398
|
-
return state.count;
|
|
11399
|
-
},
|
|
11400
|
-
get tripped() {
|
|
11401
|
-
return state.count >= burst;
|
|
11402
|
-
},
|
|
11403
|
-
note(startupFailure) {
|
|
11404
|
-
if (startupFailure === false || startupFailure == null) {
|
|
11405
|
-
return { tripped: false, count: state.count, halted: false };
|
|
11406
|
-
}
|
|
11407
|
-
const dec = bumpStartupFailure(state, Date.now(), { windowMs, burst });
|
|
11408
|
-
state.start = dec.start;
|
|
11409
|
-
state.count = dec.count;
|
|
11410
|
-
return { tripped: dec.tripped, count: state.count, halted: dec.tripped };
|
|
11411
|
-
},
|
|
11412
|
-
reset() {
|
|
11413
|
-
state = { start: null, count: 0 };
|
|
11414
|
-
}
|
|
11415
|
-
};
|
|
11416
|
-
return self;
|
|
11417
|
-
}
|
|
11418
|
-
module2.exports = { shouldGuard, bumpStartupFailure, makeBudget };
|
|
11419
|
-
}
|
|
11420
|
-
});
|
|
11421
|
-
|
|
11422
|
-
// src/app/main/startup-throttle.js
|
|
11423
|
-
var require_startup_throttle = __commonJS({
|
|
11424
|
-
"src/app/main/startup-throttle.js"(exports2, module2) {
|
|
11425
|
-
"use strict";
|
|
11426
|
-
var guardian = require_guardian();
|
|
11427
|
-
var pmClient = require_pm_client();
|
|
11428
|
-
var DEPS = /* @__PURE__ */ new WeakMap();
|
|
11429
|
-
function depsOf(host) {
|
|
11430
|
-
let d = DEPS.get(host);
|
|
11431
|
-
if (!d) {
|
|
11432
|
-
d = {
|
|
11433
|
-
config() {
|
|
11434
|
-
return host.config;
|
|
11435
|
-
},
|
|
11436
|
-
state() {
|
|
11437
|
-
return host.state;
|
|
11438
|
-
},
|
|
11439
|
-
events() {
|
|
11440
|
-
return host.events;
|
|
11441
|
-
},
|
|
11442
|
-
logger() {
|
|
11443
|
-
return host.logger;
|
|
11444
|
-
},
|
|
11445
|
-
ui() {
|
|
11446
|
-
return host.ui;
|
|
11447
|
-
},
|
|
11448
|
-
mStartupFailWindowStart() {
|
|
11449
|
-
return host._mStartupFailWindowStart();
|
|
11450
|
-
},
|
|
11451
|
-
mStartupFailCount() {
|
|
11452
|
-
return host._mStartupFailCount();
|
|
11453
|
-
},
|
|
11454
|
-
mSetStartupFailWindowStart(v) {
|
|
11455
|
-
return host._mSetStartupFailWindowStart(v);
|
|
11456
|
-
},
|
|
11457
|
-
mSetStartupFailCount(v) {
|
|
11458
|
-
return host._mSetStartupFailCount(v);
|
|
11459
|
-
}
|
|
11460
|
-
};
|
|
11461
|
-
DEPS.set(host, d);
|
|
11462
|
-
}
|
|
11463
|
-
return d;
|
|
11464
|
-
}
|
|
11465
|
-
module2.exports = {
|
|
11466
|
-
methods: {
|
|
11467
|
-
_noteStartupFailure() {
|
|
11468
|
-
const d = depsOf(this);
|
|
11469
|
-
const windowMs = d.config().startupFailWindowMs || 6e4;
|
|
11470
|
-
const dec = guardian.bumpStartupFailure(
|
|
11471
|
-
{ start: d.mStartupFailWindowStart(), count: d.mStartupFailCount() },
|
|
11472
|
-
Date.now(),
|
|
11473
|
-
{ windowMs, burst: d.config().startupFailBurst }
|
|
11474
|
-
);
|
|
11475
|
-
d.mSetStartupFailWindowStart(dec.start);
|
|
11476
|
-
d.mSetStartupFailCount(dec.count);
|
|
11477
|
-
if (!dec.tripped) return { failed: false, count: dec.count };
|
|
11478
|
-
d.state().setPhase("FAILED");
|
|
11479
|
-
d.events().append("startup_failed", {
|
|
11480
|
-
count: dec.count,
|
|
11481
|
-
windowMs,
|
|
11482
|
-
retry: "/lifecycle/dsh/restart"
|
|
11483
|
-
});
|
|
11484
|
-
d.logger().error("\u542F\u52A8\u5931\u8D25 " + dec.count + " \u6B21\uFF08\u7A97\u53E3 " + Math.round(windowMs / 1e3) + "s\uFF09\u2192 FAILED\uFF1A\u505C\u6B62\u81EA\u52A8\u91CD\u542F\uFF0C\u7B49\u5F85\u4EBA\u5DE5\u91CD\u8BD5\uFF08/lifecycle/dsh/restart\uFF09");
|
|
11485
|
-
d.ui().notify(
|
|
11486
|
-
"DSH \u542F\u52A8\u53CD\u590D\u5931\u8D25",
|
|
11487
|
-
dec.count + " \u6B21\u542F\u52A8\u5931\u8D25\uFF08" + Math.round(windowMs / 1e3) + "s \u5185\uFF09\uFF0C\u5DF2\u505C\u6B62\u81EA\u52A8\u91CD\u542F\uFF1B\u8BF7\u5728\u9762\u677F\u70B9\u300C\u91CD\u542F\u300D\u91CD\u8BD5"
|
|
11488
|
-
);
|
|
11489
|
-
return { failed: true, count: dec.count };
|
|
11490
|
-
},
|
|
11491
|
-
_retryStartupFailure() {
|
|
11492
|
-
const d = depsOf(this);
|
|
11493
|
-
d.mSetStartupFailWindowStart(null);
|
|
11494
|
-
d.mSetStartupFailCount(0);
|
|
11495
|
-
pmClient.resetBackoff("main");
|
|
11496
|
-
d.events().append("startup_retry", {});
|
|
11497
|
-
d.logger().warn("\u542F\u52A8\u5931\u8D25\u8BA1\u6570\u5DF2\u6E05\u96F6\uFF1A\u4EBA\u5DE5\u91CD\u8BD5\uFF0C\u56DE\u5230 STARTING");
|
|
11498
|
-
return { ok: true };
|
|
11499
|
-
}
|
|
11500
|
-
}
|
|
11501
|
-
};
|
|
11502
|
-
}
|
|
11503
|
-
});
|
|
11504
|
-
|
|
11505
|
-
// src/app/daemons/supervise.js
|
|
11506
|
-
var require_supervise = __commonJS({
|
|
11507
|
-
"src/app/daemons/supervise.js"(exports2, module2) {
|
|
11508
|
-
"use strict";
|
|
11509
|
-
var pidlook = require_pidlookup();
|
|
11510
|
-
var ROUTER_SUMMARY_TIMEOUT_MS = 5e3;
|
|
11511
|
-
var DEPS = /* @__PURE__ */ new WeakMap();
|
|
11512
|
-
function depsOf(host) {
|
|
11513
|
-
let d = DEPS.get(host);
|
|
11514
|
-
if (!d) {
|
|
11515
|
-
d = {
|
|
11516
|
-
stopping: () => host._stopping,
|
|
11517
|
-
exitIntended: () => host._exitIntended(),
|
|
11518
|
-
lifecycleManager: () => host.lifecycleManager,
|
|
11519
|
-
config: () => host.config,
|
|
11520
|
-
daemons: () => host.daemons,
|
|
11521
|
-
control: () => host.control,
|
|
11522
|
-
views: () => host.views,
|
|
11523
|
-
managedObjects: () => host.managedObjects,
|
|
11524
|
-
ctl: () => host.ctl,
|
|
11525
|
-
events: () => host.events,
|
|
11526
|
-
logger: () => host.logger
|
|
11527
|
-
};
|
|
11528
|
-
DEPS.set(host, d);
|
|
11529
|
-
}
|
|
11530
|
-
return d;
|
|
11531
|
-
}
|
|
11532
|
-
module2.exports = {
|
|
11533
|
-
methods: {
|
|
11534
|
-
async _daemonSuperviseOnce(kind) {
|
|
11535
|
-
const d = depsOf(this);
|
|
11536
|
-
if (d.stopping()) return { ok: false };
|
|
11537
|
-
if (d.exitIntended()) return { ok: false, error: "exit intended" };
|
|
11538
|
-
try {
|
|
11539
|
-
if (kind === "router") {
|
|
11540
|
-
const wantRunning = d.config().routerAutostart === true;
|
|
11541
|
-
const rlc = d.lifecycleManager() ? d.lifecycleManager().get("router") : null;
|
|
11542
|
-
if (!wantRunning) return { ok: d.daemons().routerActive() };
|
|
11543
|
-
if (!d.daemons().managed()) return { ok: d.daemons().routerActive() };
|
|
11544
|
-
const rlcx = d.daemons().lifecycle("router");
|
|
11545
|
-
if (rlcx && typeof rlcx.classify === "function") {
|
|
11546
|
-
const c = rlcx.classify();
|
|
11547
|
-
if (c && c.mode === "external") {
|
|
11548
|
-
d.logger() && d.logger().warn && d.logger().warn("[router] \u76D1\u7763\uFF1Actl " + d.ctl().routerPort() + " \u88AB\u5916\u90E8\u8FDB\u7A0B\u5360\u7528\uFF08pid=" + c.owner + "\uFF09\uFF0C\u4E0D\u63A5\u7BA1\u4E0D\u62C9\u8D77");
|
|
11549
|
-
return { ok: false };
|
|
11550
|
-
}
|
|
11551
|
-
}
|
|
11552
|
-
if (d.daemons().routerActive()) {
|
|
11553
|
-
try {
|
|
11554
|
-
d.control().syncRouterView({ ok: true });
|
|
11555
|
-
} catch (e) {
|
|
11556
|
-
d.logger() && d.logger().warn && d.logger().warn("router view sync: " + (e && e.message));
|
|
11557
|
-
}
|
|
11558
|
-
try {
|
|
11559
|
-
if (d.views().routerDaemonActive() && d.managedObjects()) {
|
|
11560
|
-
const s = await d.ctl().call(d.ctl().routerPort(), "domainSummary", [], ROUTER_SUMMARY_TIMEOUT_MS);
|
|
11561
|
-
const e = d.managedObjects().get("router-daemon");
|
|
11562
|
-
if (e && s && typeof s === "object") {
|
|
11563
|
-
e.domainSummary = Object.assign({ fetchedAt: Date.now() }, s);
|
|
11564
|
-
}
|
|
11565
|
-
}
|
|
11566
|
-
} catch (e2) {
|
|
11567
|
-
d.logger() && d.logger().debug && d.logger().debug("router \u57DF\u6458\u8981\u62C9\u53D6\u5931\u8D25: " + (e2 && e2.message || e2));
|
|
11568
|
-
}
|
|
11569
|
-
return { ok: true };
|
|
11570
|
-
}
|
|
11571
|
-
const rt2 = d.daemons().ensureRouterRuntime(true);
|
|
11572
|
-
if (rt2.mode === "daemon" && rt2.spawned) {
|
|
11573
|
-
d.events().append("router_daemon_supervised", { pid: rt2.spawned });
|
|
11574
|
-
if (d.logger() && d.logger().warn) d.logger().warn("[router] \u76D1\u7763\uFF1Arouter-daemon \u5931\u8054\uFF0C\u5DF2\u91CD\u65B0\u62C9\u8D77 pid=" + rt2.spawned);
|
|
11575
|
-
if (rlc) {
|
|
11576
|
-
rlc._setPhase("starting");
|
|
11577
|
-
}
|
|
11578
|
-
setTimeout(() => {
|
|
11579
|
-
const up = pidlook.findListeningPid(d.ctl().routerPort());
|
|
11580
|
-
try {
|
|
11581
|
-
d.control().syncRouterView({ ok: !!up, error: up ? null : "router-daemon \u62C9\u8D77\u540E\u672A\u5C31\u7EEA" });
|
|
11582
|
-
} catch (e) {
|
|
11583
|
-
d.logger() && d.logger().warn && d.logger().warn("router view sync: " + (e && e.message));
|
|
11584
|
-
}
|
|
11585
|
-
}, 3e3);
|
|
11586
|
-
} else if (rt2.mode === "error") {
|
|
11587
|
-
if (d.logger() && d.logger().warn) d.logger().warn("[router] \u76D1\u7763\u62C9\u8D77\u5931\u8D25: " + (rt2.error || "\u672A\u77E5"));
|
|
11588
|
-
}
|
|
11589
|
-
return { ok: false };
|
|
11590
|
-
}
|
|
11591
|
-
if (!d.daemons().enabled()) return { ok: d.daemons().lanActive() };
|
|
11592
|
-
d.daemons().syncLanState();
|
|
11593
|
-
if (d.daemons().lanActive()) return { ok: true };
|
|
11594
|
-
const rt = d.daemons().ensureLanRuntime(true);
|
|
11595
|
-
if (rt.mode === "daemon" && rt.spawned) {
|
|
11596
|
-
if (d.logger() && d.logger().warn) d.logger().warn("[lan] \u76D1\u7763\uFF1Alan-daemon \u5931\u8054\uFF0C\u5DF2\u91CD\u65B0\u62C9\u8D77 pid=" + rt.spawned);
|
|
11597
|
-
} else if (rt.mode === "error") {
|
|
11598
|
-
if (d.logger() && d.logger().warn) d.logger().warn("[lan] \u76D1\u7763\u62C9\u8D77\u5931\u8D25: " + (rt.error || "\u672A\u77E5"));
|
|
11599
|
-
}
|
|
11600
|
-
return { ok: false };
|
|
11601
|
-
} catch (e) {
|
|
11602
|
-
if (d.logger() && d.logger().warn) d.logger().warn("[" + kind + "] \u76D1\u7763\u5F02\u5E38: " + (e && e.message));
|
|
11603
|
-
return { ok: false };
|
|
11604
|
-
}
|
|
11605
|
-
}
|
|
11606
|
-
}
|
|
11607
|
-
};
|
|
11608
|
-
}
|
|
11609
|
-
});
|
|
11610
|
-
|
|
11611
11054
|
// src/app/daemons/process-wait.js
|
|
11612
11055
|
var require_process_wait = __commonJS({
|
|
11613
11056
|
"src/app/daemons/process-wait.js"(exports2, module2) {
|
|
@@ -12821,7 +12264,6 @@ var require_status = __commonJS({
|
|
|
12821
12264
|
startupFailCount: host._mStartupFailCount(),
|
|
12822
12265
|
lastFailure: host._mLastFailure(),
|
|
12823
12266
|
lastRestartAt: host._mLastRestartAt(),
|
|
12824
|
-
upgradeHold: host._upgradeHold,
|
|
12825
12267
|
shellHalted: host._shellHalted === true,
|
|
12826
12268
|
commandMissing: !!(host._mMissingNotified && host._mMissingNotified()),
|
|
12827
12269
|
dshTokenCaptured: !!(host.tokenService && host.tokenService.get("main")),
|
|
@@ -14081,8 +13523,6 @@ var require_facets = __commonJS({
|
|
|
14081
13523
|
{ name: "main/process", mod: require_process2() },
|
|
14082
13524
|
{ name: "main/port-rederive", mod: require_port_rederive() },
|
|
14083
13525
|
{ name: "main/signals", mod: require_signals() },
|
|
14084
|
-
{ name: "main/startup-throttle", mod: require_startup_throttle() },
|
|
14085
|
-
{ name: "daemons/supervise", mod: require_supervise() },
|
|
14086
13526
|
{ name: "daemons/runtime", mod: require_runtime2() },
|
|
14087
13527
|
{ name: "daemons/identity", mod: require_identity() },
|
|
14088
13528
|
{ name: "daemons/probe", mod: require_probe4() },
|
|
@@ -15688,8 +15128,6 @@ var require_core5 = __commonJS({
|
|
|
15688
15128
|
host._stopping = false;
|
|
15689
15129
|
host._crashHalted = false;
|
|
15690
15130
|
host._shellHalted = false;
|
|
15691
|
-
host._upgradeHold = false;
|
|
15692
|
-
host._upgradeHoldSince = null;
|
|
15693
15131
|
host._timer = null;
|
|
15694
15132
|
host._beatScheduler = null;
|
|
15695
15133
|
host._heartbeatBusy = false;
|
|
@@ -16951,6 +16389,58 @@ var require_instance_lifecycle = __commonJS({
|
|
|
16951
16389
|
}
|
|
16952
16390
|
});
|
|
16953
16391
|
|
|
16392
|
+
// src/shared/guardian.js
|
|
16393
|
+
var require_guardian = __commonJS({
|
|
16394
|
+
"src/shared/guardian.js"(exports2, module2) {
|
|
16395
|
+
"use strict";
|
|
16396
|
+
function shouldGuard(inst) {
|
|
16397
|
+
return !!(inst && inst.guardian === true);
|
|
16398
|
+
}
|
|
16399
|
+
function bumpStartupFailure(w, now, cfg) {
|
|
16400
|
+
const windowMs = cfg && Number(cfg.windowMs) > 0 ? Number(cfg.windowMs) : 6e4;
|
|
16401
|
+
const burst = cfg && Number(cfg.burst) >= 1 ? Number(cfg.burst) : 5;
|
|
16402
|
+
let start = w.start;
|
|
16403
|
+
let count = w.count;
|
|
16404
|
+
if (start === null || start === void 0 || now - start > windowMs) {
|
|
16405
|
+
start = now;
|
|
16406
|
+
count = 1;
|
|
16407
|
+
} else {
|
|
16408
|
+
count += 1;
|
|
16409
|
+
}
|
|
16410
|
+
return { start, count, tripped: count >= burst };
|
|
16411
|
+
}
|
|
16412
|
+
function makeBudget(cfg) {
|
|
16413
|
+
const windowMs = cfg && Number(cfg.windowMs) > 0 ? Number(cfg.windowMs) : 6e4;
|
|
16414
|
+
const burst = cfg && Number(cfg.burst) >= 1 ? Number(cfg.burst) : 5;
|
|
16415
|
+
let state = { start: null, count: 0 };
|
|
16416
|
+
const self = {
|
|
16417
|
+
windowMs,
|
|
16418
|
+
burst,
|
|
16419
|
+
get count() {
|
|
16420
|
+
return state.count;
|
|
16421
|
+
},
|
|
16422
|
+
get tripped() {
|
|
16423
|
+
return state.count >= burst;
|
|
16424
|
+
},
|
|
16425
|
+
note(startupFailure) {
|
|
16426
|
+
if (startupFailure === false || startupFailure == null) {
|
|
16427
|
+
return { tripped: false, count: state.count, halted: false };
|
|
16428
|
+
}
|
|
16429
|
+
const dec = bumpStartupFailure(state, Date.now(), { windowMs, burst });
|
|
16430
|
+
state.start = dec.start;
|
|
16431
|
+
state.count = dec.count;
|
|
16432
|
+
return { tripped: dec.tripped, count: state.count, halted: dec.tripped };
|
|
16433
|
+
},
|
|
16434
|
+
reset() {
|
|
16435
|
+
state = { start: null, count: 0 };
|
|
16436
|
+
}
|
|
16437
|
+
};
|
|
16438
|
+
return self;
|
|
16439
|
+
}
|
|
16440
|
+
module2.exports = { shouldGuard, bumpStartupFailure, makeBudget };
|
|
16441
|
+
}
|
|
16442
|
+
});
|
|
16443
|
+
|
|
16954
16444
|
// src/domains/router/providers/restart.js
|
|
16955
16445
|
var require_restart = __commonJS({
|
|
16956
16446
|
"src/domains/router/providers/restart.js"(exports2, module2) {
|
|
@@ -24838,82 +24328,6 @@ var require_managed_object = __commonJS({
|
|
|
24838
24328
|
}
|
|
24839
24329
|
});
|
|
24840
24330
|
|
|
24841
|
-
// src/app/control/heartbeat.js
|
|
24842
|
-
var require_heartbeat = __commonJS({
|
|
24843
|
-
"src/app/control/heartbeat.js"(exports2, module2) {
|
|
24844
|
-
"use strict";
|
|
24845
|
-
var ADAPTER_TIMEOUT_TICKS = 6;
|
|
24846
|
-
function withTimeout(registry, p, ms, id) {
|
|
24847
|
-
let t = null;
|
|
24848
|
-
const timeout = new Promise((resolve) => {
|
|
24849
|
-
t = setTimeout(() => resolve({ __timedOut: true, ok: false, error: "\u76D1\u7763\u8D85\u65F6(" + ms + "ms)" }), ms);
|
|
24850
|
-
if (t && typeof t.unref === "function") t.unref();
|
|
24851
|
-
});
|
|
24852
|
-
return Promise.race([Promise.resolve(p).finally(() => {
|
|
24853
|
-
if (t) clearTimeout(t);
|
|
24854
|
-
}), timeout]).catch((e) => ({ ok: false, error: e && e.message || String(e) })).then((res) => {
|
|
24855
|
-
if (res && res.__timedOut) {
|
|
24856
|
-
registry._log("warn", "heartbeat \u76D1\u7763\u8D85\u65F6(" + id + ")\uFF1A\u5DF2\u8DF3\u8FC7\u672C\u62CD\uFF08\u9632\u5FC3\u8DF3\u505C\u6446\uFF09");
|
|
24857
|
-
}
|
|
24858
|
-
return res;
|
|
24859
|
-
});
|
|
24860
|
-
}
|
|
24861
|
-
async function runHeartbeat(registry, intervalMs) {
|
|
24862
|
-
if (registry._heartbeatInFlight) return registry._heartbeatInFlight;
|
|
24863
|
-
const beat = runBeat(registry, intervalMs);
|
|
24864
|
-
registry._heartbeatInFlight = beat;
|
|
24865
|
-
try {
|
|
24866
|
-
return await beat;
|
|
24867
|
-
} finally {
|
|
24868
|
-
if (registry._heartbeatInFlight === beat) registry._heartbeatInFlight = null;
|
|
24869
|
-
}
|
|
24870
|
-
}
|
|
24871
|
-
async function runBeat(registry, intervalMs) {
|
|
24872
|
-
const iv = intervalMs || 5e3;
|
|
24873
|
-
const now = Date.now();
|
|
24874
|
-
const observed = [];
|
|
24875
|
-
const errors = [];
|
|
24876
|
-
for (const e of registry._objects.slice()) {
|
|
24877
|
-
const ad = registry._adapters[e.kind];
|
|
24878
|
-
if (!ad) continue;
|
|
24879
|
-
const fn = typeof ad.supervise === "function" ? ad.supervise : typeof ad.observe === "function" ? ad.observe : null;
|
|
24880
|
-
if (!fn) continue;
|
|
24881
|
-
const tickEvery = ad.tickEvery || e.ownership && e.ownership.meta && e.ownership.meta.tickEvery || 1;
|
|
24882
|
-
if (tickEvery > 1) {
|
|
24883
|
-
if (e._nextTickAt && now < e._nextTickAt) continue;
|
|
24884
|
-
e._nextTickAt = Date.now() + tickEvery * iv;
|
|
24885
|
-
}
|
|
24886
|
-
try {
|
|
24887
|
-
const res = await withTimeout(registry, fn(e), iv * ADAPTER_TIMEOUT_TICKS, e.id);
|
|
24888
|
-
if (res && res.__timedOut) errors.push(e.id + ":" + (res.error || "\u76D1\u7763\u8D85\u65F6"));
|
|
24889
|
-
if (res && typeof res.ok === "boolean") {
|
|
24890
|
-
if (registry.get(e.id) !== e) continue;
|
|
24891
|
-
registry.applyObservation(e.id, res);
|
|
24892
|
-
if (ad.derivePhase === true) {
|
|
24893
|
-
const want = e.desired === "running";
|
|
24894
|
-
const p = want && res.ok ? "running" : "stopped";
|
|
24895
|
-
if (e.phase !== p) registry.setPhase(e.id, p);
|
|
24896
|
-
}
|
|
24897
|
-
}
|
|
24898
|
-
observed.push(e.id);
|
|
24899
|
-
} catch (err) {
|
|
24900
|
-
errors.push(e.id + ":" + (err && err.message || err));
|
|
24901
|
-
registry._log("warn", "heartbeat " + (ad.supervise ? "supervise" : "observe") + "(" + e.kind + ":" + e.id + "): " + (err && err.message || err));
|
|
24902
|
-
}
|
|
24903
|
-
}
|
|
24904
|
-
if (typeof registry.onBeatDone === "function") {
|
|
24905
|
-
try {
|
|
24906
|
-
await registry.onBeatDone({ observed, errors });
|
|
24907
|
-
} catch (err) {
|
|
24908
|
-
registry._log("warn", "heartbeat onBeatDone: " + (err && err.message || err));
|
|
24909
|
-
}
|
|
24910
|
-
}
|
|
24911
|
-
return { observed, errors };
|
|
24912
|
-
}
|
|
24913
|
-
module2.exports = { runHeartbeat, withTimeout, ADAPTER_TIMEOUT_TICKS };
|
|
24914
|
-
}
|
|
24915
|
-
});
|
|
24916
|
-
|
|
24917
24331
|
// src/app/control/registry.js
|
|
24918
24332
|
var require_registry4 = __commonJS({
|
|
24919
24333
|
"src/app/control/registry.js"(exports2, module2) {
|
|
@@ -24924,8 +24338,6 @@ var require_registry4 = __commonJS({
|
|
|
24924
24338
|
var { DESIRED, MANAGED_KINDS, kindMeta, registerKind: registerManagedKind, createEntry, normalizeOwnership } = require_managed_object();
|
|
24925
24339
|
var { legacyToEntryPhase } = require_phase();
|
|
24926
24340
|
var PHASES = ["stopped", "installing", "starting", "running", "draining", "failed"];
|
|
24927
|
-
var { runHeartbeat } = require_heartbeat();
|
|
24928
|
-
var pmClient = require_pm_client();
|
|
24929
24341
|
var configDefaults = require_config();
|
|
24930
24342
|
var RESTART_FALLBACK = { windowMs: 6e4, burst: 5 };
|
|
24931
24343
|
var restartDefaults = () => {
|
|
@@ -25067,7 +24479,6 @@ var require_registry4 = __commonJS({
|
|
|
25067
24479
|
this._save();
|
|
25068
24480
|
this._event("managed_object_registered", { kind: e.kind, id: e.id, name: e.name });
|
|
25069
24481
|
const rd = restartDefaults();
|
|
25070
|
-
pmClient.register({ id: e.id, spawn_cmd: [], restart_window_ms: rd.windowMs, restart_burst: rd.burst });
|
|
25071
24482
|
return e;
|
|
25072
24483
|
}
|
|
25073
24484
|
update(id, patch) {
|
|
@@ -25077,7 +24488,6 @@ var require_registry4 = __commonJS({
|
|
|
25077
24488
|
if (p.desired !== void 0) {
|
|
25078
24489
|
if (!DESIRED.includes(p.desired)) return { ok: false, error: "\u975E\u6CD5 desired: " + p.desired };
|
|
25079
24490
|
e.desired = p.desired;
|
|
25080
|
-
pmClient.setDesired(e.id, p.desired);
|
|
25081
24491
|
}
|
|
25082
24492
|
if (p.name !== void 0) e.name = String(p.name || e.id);
|
|
25083
24493
|
if (p.ownership !== void 0) {
|
|
@@ -25109,7 +24519,6 @@ var require_registry4 = __commonJS({
|
|
|
25109
24519
|
this._drop(e);
|
|
25110
24520
|
this._save();
|
|
25111
24521
|
this._event("managed_object_removed", { kind: e.kind, id: e.id });
|
|
25112
|
-
pmClient.setDesired(e.id, "stopped");
|
|
25113
24522
|
return { ok: true };
|
|
25114
24523
|
}
|
|
25115
24524
|
_releasePort(port, ownerId) {
|
|
@@ -25141,9 +24550,6 @@ var require_registry4 = __commonJS({
|
|
|
25141
24550
|
count() {
|
|
25142
24551
|
return this._objects.length;
|
|
25143
24552
|
}
|
|
25144
|
-
heartbeat(intervalMs) {
|
|
25145
|
-
return runHeartbeat(this, intervalMs);
|
|
25146
|
-
}
|
|
25147
24553
|
applyObservation(id, obs) {
|
|
25148
24554
|
const e = this.get(id);
|
|
25149
24555
|
if (!e) return null;
|
|
@@ -25174,7 +24580,6 @@ var require_registry4 = __commonJS({
|
|
|
25174
24580
|
e.lastTransitionAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
25175
24581
|
this._event("managed_object_phase", { kind: e.kind, id: e.id, phase: p });
|
|
25176
24582
|
this._save();
|
|
25177
|
-
pmClient.onPhase(e.id, p);
|
|
25178
24583
|
}
|
|
25179
24584
|
return e;
|
|
25180
24585
|
}
|
|
@@ -26369,9 +25774,6 @@ var require_domains = __commonJS({
|
|
|
26369
25774
|
});
|
|
26370
25775
|
host._syncManagedRegistry();
|
|
26371
25776
|
if (host.managedObjects && typeof host.managedObjects.registerAdapter === "function") {
|
|
26372
|
-
host.managedObjects.registerAdapter("router-daemon", { supervise: () => host._daemonSuperviseOnce("router"), tickEvery: 6, derivePhase: true });
|
|
26373
|
-
host.managedObjects.registerAdapter("lan-daemon", { supervise: () => host._daemonSuperviseOnce("lan"), tickEvery: 6, derivePhase: true });
|
|
26374
|
-
host.managedObjects.registerAdapter("dsh", { supervise: () => host._dshSuperviseOnce(), tickEvery: 1 });
|
|
26375
25777
|
host.managedObjects.registerAdapter("sandbox-instance", { supervise: (entry) => host._sandboxSuperviseOnce(entry), tickEvery: 1 });
|
|
26376
25778
|
}
|
|
26377
25779
|
if (host.managedObjects) host.managedObjects.onBeatDone = () => host.instances.governSweep();
|
|
@@ -26422,8 +25824,6 @@ var require_domains = __commonJS({
|
|
|
26422
25824
|
hooks: {
|
|
26423
25825
|
isDshActive: () => ["STARTING", "RUNNING"].includes(host._mPhase()),
|
|
26424
25826
|
desiredRunning: () => host._mDesired() === "running",
|
|
26425
|
-
stopForUpgrade: () => host._enterUpgradeHoldAsync(),
|
|
26426
|
-
resumeAfterUpgrade: () => host._exitUpgradeHold(true),
|
|
26427
25827
|
verifyDeadlineMs: () => Math.max(2 * host.config.startsecs * 1e3, 12e4),
|
|
26428
25828
|
notify: (t, b) => host.notify(t, b)
|
|
26429
25829
|
}
|