@zqagent/core 0.2.6 → 0.2.7
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/dist/cli/index.cjs +88 -63
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +88 -63
- package/dist/cli/index.js.map +1 -1
- package/dist/server/index.cjs +67 -42
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +67 -42
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -572,7 +572,7 @@ var import_config = require("dotenv/config");
|
|
|
572
572
|
|
|
573
573
|
// src/server/runtime.ts
|
|
574
574
|
init_cjs_shims();
|
|
575
|
-
var
|
|
575
|
+
var fs29 = __toESM(require("fs"), 1);
|
|
576
576
|
var path33 = __toESM(require("path"), 1);
|
|
577
577
|
|
|
578
578
|
// src/server/store.ts
|
|
@@ -11413,7 +11413,7 @@ function buildNodeInfo(store, opts) {
|
|
|
11413
11413
|
nodeId: opts.nodeId ?? ensureNodeId(store),
|
|
11414
11414
|
platform: process.platform,
|
|
11415
11415
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
11416
|
-
version: "0.2.
|
|
11416
|
+
version: "0.2.7",
|
|
11417
11417
|
admin: opts.admin,
|
|
11418
11418
|
projects: opts.projects
|
|
11419
11419
|
};
|
|
@@ -12406,7 +12406,7 @@ function buildNodeHost(store, manager, diskPath) {
|
|
|
12406
12406
|
arch: process.arch,
|
|
12407
12407
|
release: os6.release(),
|
|
12408
12408
|
uptimeSec: Math.round(os6.uptime()),
|
|
12409
|
-
version: "0.2.
|
|
12409
|
+
version: "0.2.7",
|
|
12410
12410
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
12411
12411
|
cpu: {
|
|
12412
12412
|
count: cpus2.length,
|
|
@@ -13958,7 +13958,7 @@ function createApp(store, manager, opts = {}) {
|
|
|
13958
13958
|
json(res, 200, {
|
|
13959
13959
|
status: "ok",
|
|
13960
13960
|
// 版本让运维/探针能确认线上跑的是哪个构建(更新与回滚据此判断)
|
|
13961
|
-
version: "0.2.
|
|
13961
|
+
version: "0.2.7",
|
|
13962
13962
|
features: { mcp: hasServerMcpConfig() }
|
|
13963
13963
|
});
|
|
13964
13964
|
return;
|
|
@@ -15661,7 +15661,7 @@ var FleetNodeBridge = class {
|
|
|
15661
15661
|
label: this.opts.deps.store.loadNodeLabel() ?? void 0,
|
|
15662
15662
|
platform: process.platform,
|
|
15663
15663
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
15664
|
-
version: "0.2.
|
|
15664
|
+
version: "0.2.7",
|
|
15665
15665
|
ip: primaryIp()
|
|
15666
15666
|
};
|
|
15667
15667
|
}
|
|
@@ -15716,7 +15716,7 @@ var FleetNodeBridge = class {
|
|
|
15716
15716
|
label: this.opts.deps.store.loadNodeLabel() ?? void 0,
|
|
15717
15717
|
platform: process.platform,
|
|
15718
15718
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
15719
|
-
version: "0.2.
|
|
15719
|
+
version: "0.2.7",
|
|
15720
15720
|
ip: primaryIp(),
|
|
15721
15721
|
projects,
|
|
15722
15722
|
totals,
|
|
@@ -17179,7 +17179,7 @@ async function hubEnrollByAccount(baseUrl, input) {
|
|
|
17179
17179
|
|
|
17180
17180
|
// src/update/controller.ts
|
|
17181
17181
|
init_cjs_shims();
|
|
17182
|
-
var
|
|
17182
|
+
var fs28 = __toESM(require("fs"), 1);
|
|
17183
17183
|
var path32 = __toESM(require("path"), 1);
|
|
17184
17184
|
|
|
17185
17185
|
// src/update/downloader.ts
|
|
@@ -17432,10 +17432,11 @@ function selfCheck(binPath, expectedVersion) {
|
|
|
17432
17432
|
|
|
17433
17433
|
// src/update/platform.ts
|
|
17434
17434
|
init_cjs_shims();
|
|
17435
|
+
var fs25 = __toESM(require("fs"), 1);
|
|
17435
17436
|
var path29 = __toESM(require("path"), 1);
|
|
17436
17437
|
var import_node_module3 = require("module");
|
|
17437
17438
|
function currentVersion() {
|
|
17438
|
-
const injected = "0.2.
|
|
17439
|
+
const injected = "0.2.7"?.trim();
|
|
17439
17440
|
if (injected) return injected;
|
|
17440
17441
|
try {
|
|
17441
17442
|
const req2 = (0, import_node_module3.createRequire)(importMetaUrl);
|
|
@@ -17450,9 +17451,33 @@ function isSeaRuntime() {
|
|
|
17450
17451
|
const base = path29.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
|
|
17451
17452
|
return base !== "node" && base !== "nodejs";
|
|
17452
17453
|
}
|
|
17454
|
+
var DEFAULT_SERVICE_NAME = "zqagent";
|
|
17455
|
+
function serviceManagerFromCgroup(cgroup, serviceName = DEFAULT_SERVICE_NAME) {
|
|
17456
|
+
const unitName = `${serviceName}.service`;
|
|
17457
|
+
for (const line of cgroup.split("\n")) {
|
|
17458
|
+
const idx = line.lastIndexOf(":");
|
|
17459
|
+
if (idx < 0) continue;
|
|
17460
|
+
const unitPath = line.slice(idx + 1).trim();
|
|
17461
|
+
if (unitPath.split("/").includes(unitName)) return "systemd";
|
|
17462
|
+
}
|
|
17463
|
+
return null;
|
|
17464
|
+
}
|
|
17465
|
+
function detectServiceManager() {
|
|
17466
|
+
if (process.platform !== "linux") return null;
|
|
17467
|
+
const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
|
|
17468
|
+
try {
|
|
17469
|
+
return serviceManagerFromCgroup(
|
|
17470
|
+
fs25.readFileSync("/proc/self/cgroup", "utf8"),
|
|
17471
|
+
serviceName
|
|
17472
|
+
);
|
|
17473
|
+
} catch {
|
|
17474
|
+
return null;
|
|
17475
|
+
}
|
|
17476
|
+
}
|
|
17453
17477
|
function serviceManager() {
|
|
17454
17478
|
const v = process.env.ZQAGENT_SERVICE_MANAGER?.trim().toLowerCase();
|
|
17455
|
-
|
|
17479
|
+
if (v === "systemd" || v === "launchd") return v;
|
|
17480
|
+
return detectServiceManager();
|
|
17456
17481
|
}
|
|
17457
17482
|
function selfUpdateCapability(hasPublicKey) {
|
|
17458
17483
|
if (!isSeaRuntime()) {
|
|
@@ -17475,12 +17500,12 @@ function selfUpdateCapability(hasPublicKey) {
|
|
|
17475
17500
|
|
|
17476
17501
|
// src/update/installer.ts
|
|
17477
17502
|
init_cjs_shims();
|
|
17478
|
-
var
|
|
17503
|
+
var fs27 = __toESM(require("fs"), 1);
|
|
17479
17504
|
var path31 = __toESM(require("path"), 1);
|
|
17480
17505
|
|
|
17481
17506
|
// src/update/state.ts
|
|
17482
17507
|
init_cjs_shims();
|
|
17483
|
-
var
|
|
17508
|
+
var fs26 = __toESM(require("fs"), 1);
|
|
17484
17509
|
var path30 = __toESM(require("path"), 1);
|
|
17485
17510
|
function updatesDir(dataDir) {
|
|
17486
17511
|
return path30.join(dataDir, "updates");
|
|
@@ -17490,7 +17515,7 @@ function statePath(dataDir) {
|
|
|
17490
17515
|
}
|
|
17491
17516
|
function loadState(dataDir) {
|
|
17492
17517
|
try {
|
|
17493
|
-
const raw =
|
|
17518
|
+
const raw = fs26.readFileSync(statePath(dataDir), "utf-8");
|
|
17494
17519
|
const parsed = JSON.parse(raw);
|
|
17495
17520
|
if (typeof parsed === "object" && parsed !== null) return parsed;
|
|
17496
17521
|
} catch {
|
|
@@ -17499,11 +17524,11 @@ function loadState(dataDir) {
|
|
|
17499
17524
|
}
|
|
17500
17525
|
function saveState(dataDir, state) {
|
|
17501
17526
|
const dir = updatesDir(dataDir);
|
|
17502
|
-
|
|
17527
|
+
fs26.mkdirSync(dir, { recursive: true });
|
|
17503
17528
|
const file = statePath(dataDir);
|
|
17504
17529
|
const tmp = `${file}.tmp`;
|
|
17505
|
-
|
|
17506
|
-
|
|
17530
|
+
fs26.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
|
|
17531
|
+
fs26.renameSync(tmp, file);
|
|
17507
17532
|
}
|
|
17508
17533
|
function patchState(dataDir, patch) {
|
|
17509
17534
|
const next = { ...loadState(dataDir), ...patch };
|
|
@@ -17517,32 +17542,32 @@ function backupDir(dataDir) {
|
|
|
17517
17542
|
}
|
|
17518
17543
|
function backupCurrent(dataDir, execPath, version) {
|
|
17519
17544
|
const dir = backupDir(dataDir);
|
|
17520
|
-
|
|
17545
|
+
fs27.mkdirSync(dir, { recursive: true });
|
|
17521
17546
|
const target = path31.join(dir, `zqagent-${version}${process.platform === "win32" ? ".exe" : ""}`);
|
|
17522
|
-
|
|
17523
|
-
|
|
17547
|
+
fs27.copyFileSync(execPath, target);
|
|
17548
|
+
fs27.chmodSync(target, 493);
|
|
17524
17549
|
return target;
|
|
17525
17550
|
}
|
|
17526
17551
|
function replaceExecutable(execPath, stagedPath) {
|
|
17527
17552
|
if (process.platform === "win32") {
|
|
17528
17553
|
const oldPath = `${execPath}.old`;
|
|
17529
|
-
|
|
17530
|
-
|
|
17531
|
-
|
|
17532
|
-
|
|
17554
|
+
fs27.rmSync(oldPath, { force: true });
|
|
17555
|
+
fs27.renameSync(execPath, oldPath);
|
|
17556
|
+
fs27.copyFileSync(stagedPath, execPath);
|
|
17557
|
+
fs27.chmodSync(execPath, 493);
|
|
17533
17558
|
return;
|
|
17534
17559
|
}
|
|
17535
17560
|
const tmp = `${execPath}.new`;
|
|
17536
|
-
|
|
17561
|
+
fs27.rmSync(tmp, { force: true });
|
|
17537
17562
|
try {
|
|
17538
|
-
|
|
17539
|
-
|
|
17540
|
-
|
|
17563
|
+
fs27.copyFileSync(stagedPath, tmp);
|
|
17564
|
+
fs27.chmodSync(tmp, 493);
|
|
17565
|
+
fs27.renameSync(tmp, execPath);
|
|
17541
17566
|
} catch (err) {
|
|
17542
|
-
|
|
17567
|
+
fs27.rmSync(tmp, { force: true });
|
|
17543
17568
|
throw err;
|
|
17544
17569
|
}
|
|
17545
|
-
|
|
17570
|
+
fs27.rmSync(stagedPath, { force: true });
|
|
17546
17571
|
}
|
|
17547
17572
|
function installStaged(opts) {
|
|
17548
17573
|
const log = opts.log ?? (() => {
|
|
@@ -17569,18 +17594,18 @@ function rollback(dataDir, execPath, log = () => {
|
|
|
17569
17594
|
}) {
|
|
17570
17595
|
const state = readRollbackTarget(dataDir);
|
|
17571
17596
|
if (!state?.backupPath || !state.backupVersion) return null;
|
|
17572
|
-
if (!
|
|
17597
|
+
if (!fs27.existsSync(state.backupPath)) return null;
|
|
17573
17598
|
log(`\u6B63\u5728\u56DE\u6EDA\u5230 v${state.backupVersion}`);
|
|
17574
17599
|
if (process.platform === "win32") {
|
|
17575
|
-
|
|
17576
|
-
|
|
17577
|
-
|
|
17578
|
-
|
|
17600
|
+
fs27.rmSync(`${execPath}.old`, { force: true });
|
|
17601
|
+
fs27.renameSync(execPath, `${execPath}.old`);
|
|
17602
|
+
fs27.copyFileSync(state.backupPath, execPath);
|
|
17603
|
+
fs27.chmodSync(execPath, 493);
|
|
17579
17604
|
} else {
|
|
17580
17605
|
const tmp = `${execPath}.rollback`;
|
|
17581
|
-
|
|
17582
|
-
|
|
17583
|
-
|
|
17606
|
+
fs27.copyFileSync(state.backupPath, tmp);
|
|
17607
|
+
fs27.chmodSync(tmp, 493);
|
|
17608
|
+
fs27.renameSync(tmp, execPath);
|
|
17584
17609
|
}
|
|
17585
17610
|
patchState(dataDir, {
|
|
17586
17611
|
pendingVersion: state.backupVersion,
|
|
@@ -17594,7 +17619,7 @@ function rollback(dataDir, execPath, log = () => {
|
|
|
17594
17619
|
}
|
|
17595
17620
|
function readRollbackTarget(dataDir) {
|
|
17596
17621
|
try {
|
|
17597
|
-
const raw =
|
|
17622
|
+
const raw = fs27.readFileSync(path31.join(updatesDir(dataDir), "state.json"), "utf-8");
|
|
17598
17623
|
const s = JSON.parse(raw);
|
|
17599
17624
|
if (s.backupPath && s.backupVersion) return s;
|
|
17600
17625
|
} catch {
|
|
@@ -17677,7 +17702,7 @@ var UpdateController = class {
|
|
|
17677
17702
|
reconcile() {
|
|
17678
17703
|
const state = loadState(this.opts.dataDir);
|
|
17679
17704
|
const current = this.currentVersion;
|
|
17680
|
-
if (state.stagedPath && !
|
|
17705
|
+
if (state.stagedPath && !fs28.existsSync(state.stagedPath)) {
|
|
17681
17706
|
patchState(this.opts.dataDir, { stagedVersion: void 0, stagedPath: void 0 });
|
|
17682
17707
|
}
|
|
17683
17708
|
const patch = { runningVersion: current };
|
|
@@ -17692,7 +17717,7 @@ var UpdateController = class {
|
|
|
17692
17717
|
}
|
|
17693
17718
|
patchState(this.opts.dataDir, patch);
|
|
17694
17719
|
if (process.platform === "win32") {
|
|
17695
|
-
|
|
17720
|
+
fs28.rmSync(`${process.execPath}.old`, { force: true });
|
|
17696
17721
|
}
|
|
17697
17722
|
}
|
|
17698
17723
|
schedule(delayMs) {
|
|
@@ -17768,7 +17793,7 @@ var UpdateController = class {
|
|
|
17768
17793
|
const bin = manifest.binaries[platformKey()];
|
|
17769
17794
|
if (!bin) return `\u6E05\u5355\u6CA1\u6709\u5F53\u524D\u5E73\u53F0\uFF08${platformKey()}\uFF09\u7684\u4EA7\u7269`;
|
|
17770
17795
|
let stagedPath = state.stagedPath;
|
|
17771
|
-
if (!(state.stagedVersion === manifest.version && stagedPath &&
|
|
17796
|
+
if (!(state.stagedVersion === manifest.version && stagedPath && fs28.existsSync(stagedPath))) {
|
|
17772
17797
|
stagedPath = path32.join(
|
|
17773
17798
|
updatesDir(this.opts.dataDir),
|
|
17774
17799
|
"staged",
|
|
@@ -17781,7 +17806,7 @@ var UpdateController = class {
|
|
|
17781
17806
|
}
|
|
17782
17807
|
const selfTest = selfCheck(stagedPath, manifest.version);
|
|
17783
17808
|
if (!selfTest.ok) {
|
|
17784
|
-
|
|
17809
|
+
fs28.rmSync(stagedPath, { force: true });
|
|
17785
17810
|
this.recordFailure(manifest.version, selfTest.error ?? "\u81EA\u68C0\u5931\u8D25");
|
|
17786
17811
|
return `\u5B89\u88C5\u5305\u81EA\u68C0\u5931\u8D25\uFF1A${selfTest.error}`;
|
|
17787
17812
|
}
|
|
@@ -17922,7 +17947,7 @@ function pemFile(key) {
|
|
|
17922
17947
|
const p = env2(key);
|
|
17923
17948
|
if (!p) return void 0;
|
|
17924
17949
|
try {
|
|
17925
|
-
return
|
|
17950
|
+
return fs29.readFileSync(p);
|
|
17926
17951
|
} catch (e) {
|
|
17927
17952
|
console.warn(`[tls] \u8BFB\u53D6 ${key}=${p} \u5931\u8D25: ${e instanceof Error ? e.message : e}`);
|
|
17928
17953
|
return void 0;
|