@zqagent/core 0.2.6 → 0.2.8
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 +122 -65
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +122 -65
- package/dist/cli/index.js.map +1 -1
- package/dist/server/index.cjs +101 -44
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +101 -44
- 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.8",
|
|
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.8",
|
|
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.8",
|
|
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.8",
|
|
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.8",
|
|
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,12 @@ 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);
|
|
17437
|
+
var import_node_child_process5 = require("child_process");
|
|
17436
17438
|
var import_node_module3 = require("module");
|
|
17437
17439
|
function currentVersion() {
|
|
17438
|
-
const injected = "0.2.
|
|
17440
|
+
const injected = "0.2.8"?.trim();
|
|
17439
17441
|
if (injected) return injected;
|
|
17440
17442
|
try {
|
|
17441
17443
|
const req2 = (0, import_node_module3.createRequire)(importMetaUrl);
|
|
@@ -17450,9 +17452,62 @@ function isSeaRuntime() {
|
|
|
17450
17452
|
const base = path29.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
|
|
17451
17453
|
return base !== "node" && base !== "nodejs";
|
|
17452
17454
|
}
|
|
17455
|
+
var DEFAULT_SERVICE_NAME = "zqagent";
|
|
17456
|
+
function serviceManagerFromCgroup(cgroup, serviceName = DEFAULT_SERVICE_NAME) {
|
|
17457
|
+
const unitName = `${serviceName}.service`;
|
|
17458
|
+
for (const line of cgroup.split("\n")) {
|
|
17459
|
+
const idx = line.lastIndexOf(":");
|
|
17460
|
+
if (idx < 0) continue;
|
|
17461
|
+
const unitPath = line.slice(idx + 1).trim();
|
|
17462
|
+
if (unitPath.split("/").includes(unitName)) return "systemd";
|
|
17463
|
+
}
|
|
17464
|
+
return null;
|
|
17465
|
+
}
|
|
17466
|
+
function detectServiceManager() {
|
|
17467
|
+
if (process.platform !== "linux") return null;
|
|
17468
|
+
const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
|
|
17469
|
+
try {
|
|
17470
|
+
return serviceManagerFromCgroup(
|
|
17471
|
+
fs25.readFileSync("/proc/self/cgroup", "utf8"),
|
|
17472
|
+
serviceName
|
|
17473
|
+
);
|
|
17474
|
+
} catch {
|
|
17475
|
+
return null;
|
|
17476
|
+
}
|
|
17477
|
+
}
|
|
17453
17478
|
function serviceManager() {
|
|
17454
17479
|
const v = process.env.ZQAGENT_SERVICE_MANAGER?.trim().toLowerCase();
|
|
17455
|
-
|
|
17480
|
+
if (v === "systemd" || v === "launchd") return v;
|
|
17481
|
+
return detectServiceManager();
|
|
17482
|
+
}
|
|
17483
|
+
function parseServiceEnvironment(raw) {
|
|
17484
|
+
const out = {};
|
|
17485
|
+
for (const token of raw.trim().split(/\s+/)) {
|
|
17486
|
+
const idx = token.indexOf("=");
|
|
17487
|
+
if (idx > 0) out[token.slice(0, idx)] = token.slice(idx + 1);
|
|
17488
|
+
}
|
|
17489
|
+
return out;
|
|
17490
|
+
}
|
|
17491
|
+
var cachedServiceEnv = null;
|
|
17492
|
+
function readServiceEnvironment() {
|
|
17493
|
+
const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
|
|
17494
|
+
try {
|
|
17495
|
+
const res = (0, import_node_child_process5.spawnSync)(
|
|
17496
|
+
"systemctl",
|
|
17497
|
+
["show", serviceName, "--property=Environment", "--value", "--no-pager"],
|
|
17498
|
+
{ encoding: "utf8", timeout: 3e3 }
|
|
17499
|
+
);
|
|
17500
|
+
if (res.status !== 0 || !res.stdout) return {};
|
|
17501
|
+
return parseServiceEnvironment(res.stdout);
|
|
17502
|
+
} catch {
|
|
17503
|
+
return {};
|
|
17504
|
+
}
|
|
17505
|
+
}
|
|
17506
|
+
function serviceEnvValue(key) {
|
|
17507
|
+
if (process.platform !== "linux") return void 0;
|
|
17508
|
+
if (serviceManager() !== "systemd") return void 0;
|
|
17509
|
+
cachedServiceEnv ??= readServiceEnvironment();
|
|
17510
|
+
return cachedServiceEnv[key];
|
|
17456
17511
|
}
|
|
17457
17512
|
function selfUpdateCapability(hasPublicKey) {
|
|
17458
17513
|
if (!isSeaRuntime()) {
|
|
@@ -17475,12 +17530,12 @@ function selfUpdateCapability(hasPublicKey) {
|
|
|
17475
17530
|
|
|
17476
17531
|
// src/update/installer.ts
|
|
17477
17532
|
init_cjs_shims();
|
|
17478
|
-
var
|
|
17533
|
+
var fs27 = __toESM(require("fs"), 1);
|
|
17479
17534
|
var path31 = __toESM(require("path"), 1);
|
|
17480
17535
|
|
|
17481
17536
|
// src/update/state.ts
|
|
17482
17537
|
init_cjs_shims();
|
|
17483
|
-
var
|
|
17538
|
+
var fs26 = __toESM(require("fs"), 1);
|
|
17484
17539
|
var path30 = __toESM(require("path"), 1);
|
|
17485
17540
|
function updatesDir(dataDir) {
|
|
17486
17541
|
return path30.join(dataDir, "updates");
|
|
@@ -17490,7 +17545,7 @@ function statePath(dataDir) {
|
|
|
17490
17545
|
}
|
|
17491
17546
|
function loadState(dataDir) {
|
|
17492
17547
|
try {
|
|
17493
|
-
const raw =
|
|
17548
|
+
const raw = fs26.readFileSync(statePath(dataDir), "utf-8");
|
|
17494
17549
|
const parsed = JSON.parse(raw);
|
|
17495
17550
|
if (typeof parsed === "object" && parsed !== null) return parsed;
|
|
17496
17551
|
} catch {
|
|
@@ -17499,11 +17554,11 @@ function loadState(dataDir) {
|
|
|
17499
17554
|
}
|
|
17500
17555
|
function saveState(dataDir, state) {
|
|
17501
17556
|
const dir = updatesDir(dataDir);
|
|
17502
|
-
|
|
17557
|
+
fs26.mkdirSync(dir, { recursive: true });
|
|
17503
17558
|
const file = statePath(dataDir);
|
|
17504
17559
|
const tmp = `${file}.tmp`;
|
|
17505
|
-
|
|
17506
|
-
|
|
17560
|
+
fs26.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
|
|
17561
|
+
fs26.renameSync(tmp, file);
|
|
17507
17562
|
}
|
|
17508
17563
|
function patchState(dataDir, patch) {
|
|
17509
17564
|
const next = { ...loadState(dataDir), ...patch };
|
|
@@ -17517,32 +17572,32 @@ function backupDir(dataDir) {
|
|
|
17517
17572
|
}
|
|
17518
17573
|
function backupCurrent(dataDir, execPath, version) {
|
|
17519
17574
|
const dir = backupDir(dataDir);
|
|
17520
|
-
|
|
17575
|
+
fs27.mkdirSync(dir, { recursive: true });
|
|
17521
17576
|
const target = path31.join(dir, `zqagent-${version}${process.platform === "win32" ? ".exe" : ""}`);
|
|
17522
|
-
|
|
17523
|
-
|
|
17577
|
+
fs27.copyFileSync(execPath, target);
|
|
17578
|
+
fs27.chmodSync(target, 493);
|
|
17524
17579
|
return target;
|
|
17525
17580
|
}
|
|
17526
17581
|
function replaceExecutable(execPath, stagedPath) {
|
|
17527
17582
|
if (process.platform === "win32") {
|
|
17528
17583
|
const oldPath = `${execPath}.old`;
|
|
17529
|
-
|
|
17530
|
-
|
|
17531
|
-
|
|
17532
|
-
|
|
17584
|
+
fs27.rmSync(oldPath, { force: true });
|
|
17585
|
+
fs27.renameSync(execPath, oldPath);
|
|
17586
|
+
fs27.copyFileSync(stagedPath, execPath);
|
|
17587
|
+
fs27.chmodSync(execPath, 493);
|
|
17533
17588
|
return;
|
|
17534
17589
|
}
|
|
17535
17590
|
const tmp = `${execPath}.new`;
|
|
17536
|
-
|
|
17591
|
+
fs27.rmSync(tmp, { force: true });
|
|
17537
17592
|
try {
|
|
17538
|
-
|
|
17539
|
-
|
|
17540
|
-
|
|
17593
|
+
fs27.copyFileSync(stagedPath, tmp);
|
|
17594
|
+
fs27.chmodSync(tmp, 493);
|
|
17595
|
+
fs27.renameSync(tmp, execPath);
|
|
17541
17596
|
} catch (err) {
|
|
17542
|
-
|
|
17597
|
+
fs27.rmSync(tmp, { force: true });
|
|
17543
17598
|
throw err;
|
|
17544
17599
|
}
|
|
17545
|
-
|
|
17600
|
+
fs27.rmSync(stagedPath, { force: true });
|
|
17546
17601
|
}
|
|
17547
17602
|
function installStaged(opts) {
|
|
17548
17603
|
const log = opts.log ?? (() => {
|
|
@@ -17569,18 +17624,18 @@ function rollback(dataDir, execPath, log = () => {
|
|
|
17569
17624
|
}) {
|
|
17570
17625
|
const state = readRollbackTarget(dataDir);
|
|
17571
17626
|
if (!state?.backupPath || !state.backupVersion) return null;
|
|
17572
|
-
if (!
|
|
17627
|
+
if (!fs27.existsSync(state.backupPath)) return null;
|
|
17573
17628
|
log(`\u6B63\u5728\u56DE\u6EDA\u5230 v${state.backupVersion}`);
|
|
17574
17629
|
if (process.platform === "win32") {
|
|
17575
|
-
|
|
17576
|
-
|
|
17577
|
-
|
|
17578
|
-
|
|
17630
|
+
fs27.rmSync(`${execPath}.old`, { force: true });
|
|
17631
|
+
fs27.renameSync(execPath, `${execPath}.old`);
|
|
17632
|
+
fs27.copyFileSync(state.backupPath, execPath);
|
|
17633
|
+
fs27.chmodSync(execPath, 493);
|
|
17579
17634
|
} else {
|
|
17580
17635
|
const tmp = `${execPath}.rollback`;
|
|
17581
|
-
|
|
17582
|
-
|
|
17583
|
-
|
|
17636
|
+
fs27.copyFileSync(state.backupPath, tmp);
|
|
17637
|
+
fs27.chmodSync(tmp, 493);
|
|
17638
|
+
fs27.renameSync(tmp, execPath);
|
|
17584
17639
|
}
|
|
17585
17640
|
patchState(dataDir, {
|
|
17586
17641
|
pendingVersion: state.backupVersion,
|
|
@@ -17594,7 +17649,7 @@ function rollback(dataDir, execPath, log = () => {
|
|
|
17594
17649
|
}
|
|
17595
17650
|
function readRollbackTarget(dataDir) {
|
|
17596
17651
|
try {
|
|
17597
|
-
const raw =
|
|
17652
|
+
const raw = fs27.readFileSync(path31.join(updatesDir(dataDir), "state.json"), "utf-8");
|
|
17598
17653
|
const s = JSON.parse(raw);
|
|
17599
17654
|
if (s.backupPath && s.backupVersion) return s;
|
|
17600
17655
|
} catch {
|
|
@@ -17606,7 +17661,9 @@ function readRollbackTarget(dataDir) {
|
|
|
17606
17661
|
var DEFAULT_BASE = "https://agent.cd-zq.com/downloads/zqagent";
|
|
17607
17662
|
function env(key) {
|
|
17608
17663
|
const v = process.env[key]?.trim();
|
|
17609
|
-
|
|
17664
|
+
if (v) return v;
|
|
17665
|
+
const fromService = serviceEnvValue(key)?.trim();
|
|
17666
|
+
return fromService ? fromService : void 0;
|
|
17610
17667
|
}
|
|
17611
17668
|
function num(key, fallback) {
|
|
17612
17669
|
const n = Number(env(key));
|
|
@@ -17643,7 +17700,7 @@ var UpdateController = class {
|
|
|
17643
17700
|
return parsePublicKey(env("ZQAGENT_UPDATE_PUBKEY") ?? "");
|
|
17644
17701
|
}
|
|
17645
17702
|
get autoUpdateOff() {
|
|
17646
|
-
return
|
|
17703
|
+
return env("ZQAGENT_AUTO_UPDATE") === "0";
|
|
17647
17704
|
}
|
|
17648
17705
|
get enabled() {
|
|
17649
17706
|
return !this.autoUpdateOff && selfUpdateCapability(Boolean(this.publicKey)).ok;
|
|
@@ -17677,7 +17734,7 @@ var UpdateController = class {
|
|
|
17677
17734
|
reconcile() {
|
|
17678
17735
|
const state = loadState(this.opts.dataDir);
|
|
17679
17736
|
const current = this.currentVersion;
|
|
17680
|
-
if (state.stagedPath && !
|
|
17737
|
+
if (state.stagedPath && !fs28.existsSync(state.stagedPath)) {
|
|
17681
17738
|
patchState(this.opts.dataDir, { stagedVersion: void 0, stagedPath: void 0 });
|
|
17682
17739
|
}
|
|
17683
17740
|
const patch = { runningVersion: current };
|
|
@@ -17692,7 +17749,7 @@ var UpdateController = class {
|
|
|
17692
17749
|
}
|
|
17693
17750
|
patchState(this.opts.dataDir, patch);
|
|
17694
17751
|
if (process.platform === "win32") {
|
|
17695
|
-
|
|
17752
|
+
fs28.rmSync(`${process.execPath}.old`, { force: true });
|
|
17696
17753
|
}
|
|
17697
17754
|
}
|
|
17698
17755
|
schedule(delayMs) {
|
|
@@ -17768,7 +17825,7 @@ var UpdateController = class {
|
|
|
17768
17825
|
const bin = manifest.binaries[platformKey()];
|
|
17769
17826
|
if (!bin) return `\u6E05\u5355\u6CA1\u6709\u5F53\u524D\u5E73\u53F0\uFF08${platformKey()}\uFF09\u7684\u4EA7\u7269`;
|
|
17770
17827
|
let stagedPath = state.stagedPath;
|
|
17771
|
-
if (!(state.stagedVersion === manifest.version && stagedPath &&
|
|
17828
|
+
if (!(state.stagedVersion === manifest.version && stagedPath && fs28.existsSync(stagedPath))) {
|
|
17772
17829
|
stagedPath = path32.join(
|
|
17773
17830
|
updatesDir(this.opts.dataDir),
|
|
17774
17831
|
"staged",
|
|
@@ -17781,7 +17838,7 @@ var UpdateController = class {
|
|
|
17781
17838
|
}
|
|
17782
17839
|
const selfTest = selfCheck(stagedPath, manifest.version);
|
|
17783
17840
|
if (!selfTest.ok) {
|
|
17784
|
-
|
|
17841
|
+
fs28.rmSync(stagedPath, { force: true });
|
|
17785
17842
|
this.recordFailure(manifest.version, selfTest.error ?? "\u81EA\u68C0\u5931\u8D25");
|
|
17786
17843
|
return `\u5B89\u88C5\u5305\u81EA\u68C0\u5931\u8D25\uFF1A${selfTest.error}`;
|
|
17787
17844
|
}
|
|
@@ -17922,7 +17979,7 @@ function pemFile(key) {
|
|
|
17922
17979
|
const p = env2(key);
|
|
17923
17980
|
if (!p) return void 0;
|
|
17924
17981
|
try {
|
|
17925
|
-
return
|
|
17982
|
+
return fs29.readFileSync(p);
|
|
17926
17983
|
} catch (e) {
|
|
17927
17984
|
console.warn(`[tls] \u8BFB\u53D6 ${key}=${p} \u5931\u8D25: ${e instanceof Error ? e.message : e}`);
|
|
17928
17985
|
return void 0;
|