@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.js
CHANGED
|
@@ -555,7 +555,7 @@ import "dotenv/config";
|
|
|
555
555
|
|
|
556
556
|
// src/server/runtime.ts
|
|
557
557
|
init_esm_shims();
|
|
558
|
-
import * as
|
|
558
|
+
import * as fs29 from "fs";
|
|
559
559
|
import * as path34 from "path";
|
|
560
560
|
|
|
561
561
|
// src/server/store.ts
|
|
@@ -11396,7 +11396,7 @@ function buildNodeInfo(store, opts) {
|
|
|
11396
11396
|
nodeId: opts.nodeId ?? ensureNodeId(store),
|
|
11397
11397
|
platform: process.platform,
|
|
11398
11398
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
11399
|
-
version: "0.2.
|
|
11399
|
+
version: "0.2.8",
|
|
11400
11400
|
admin: opts.admin,
|
|
11401
11401
|
projects: opts.projects
|
|
11402
11402
|
};
|
|
@@ -12389,7 +12389,7 @@ function buildNodeHost(store, manager, diskPath) {
|
|
|
12389
12389
|
arch: process.arch,
|
|
12390
12390
|
release: os6.release(),
|
|
12391
12391
|
uptimeSec: Math.round(os6.uptime()),
|
|
12392
|
-
version: "0.2.
|
|
12392
|
+
version: "0.2.8",
|
|
12393
12393
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
12394
12394
|
cpu: {
|
|
12395
12395
|
count: cpus2.length,
|
|
@@ -13941,7 +13941,7 @@ function createApp(store, manager, opts = {}) {
|
|
|
13941
13941
|
json(res, 200, {
|
|
13942
13942
|
status: "ok",
|
|
13943
13943
|
// 版本让运维/探针能确认线上跑的是哪个构建(更新与回滚据此判断)
|
|
13944
|
-
version: "0.2.
|
|
13944
|
+
version: "0.2.8",
|
|
13945
13945
|
features: { mcp: hasServerMcpConfig() }
|
|
13946
13946
|
});
|
|
13947
13947
|
return;
|
|
@@ -15644,7 +15644,7 @@ var FleetNodeBridge = class {
|
|
|
15644
15644
|
label: this.opts.deps.store.loadNodeLabel() ?? void 0,
|
|
15645
15645
|
platform: process.platform,
|
|
15646
15646
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
15647
|
-
version: "0.2.
|
|
15647
|
+
version: "0.2.8",
|
|
15648
15648
|
ip: primaryIp()
|
|
15649
15649
|
};
|
|
15650
15650
|
}
|
|
@@ -15699,7 +15699,7 @@ var FleetNodeBridge = class {
|
|
|
15699
15699
|
label: this.opts.deps.store.loadNodeLabel() ?? void 0,
|
|
15700
15700
|
platform: process.platform,
|
|
15701
15701
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
15702
|
-
version: "0.2.
|
|
15702
|
+
version: "0.2.8",
|
|
15703
15703
|
ip: primaryIp(),
|
|
15704
15704
|
projects,
|
|
15705
15705
|
totals,
|
|
@@ -17162,7 +17162,7 @@ async function hubEnrollByAccount(baseUrl, input) {
|
|
|
17162
17162
|
|
|
17163
17163
|
// src/update/controller.ts
|
|
17164
17164
|
init_esm_shims();
|
|
17165
|
-
import * as
|
|
17165
|
+
import * as fs28 from "fs";
|
|
17166
17166
|
import * as path33 from "path";
|
|
17167
17167
|
|
|
17168
17168
|
// src/update/downloader.ts
|
|
@@ -17415,10 +17415,12 @@ function selfCheck(binPath, expectedVersion) {
|
|
|
17415
17415
|
|
|
17416
17416
|
// src/update/platform.ts
|
|
17417
17417
|
init_esm_shims();
|
|
17418
|
+
import * as fs25 from "fs";
|
|
17418
17419
|
import * as path30 from "path";
|
|
17420
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
17419
17421
|
import { createRequire as createRequire3 } from "module";
|
|
17420
17422
|
function currentVersion() {
|
|
17421
|
-
const injected = "0.2.
|
|
17423
|
+
const injected = "0.2.8"?.trim();
|
|
17422
17424
|
if (injected) return injected;
|
|
17423
17425
|
try {
|
|
17424
17426
|
const req2 = createRequire3(import.meta.url);
|
|
@@ -17433,9 +17435,62 @@ function isSeaRuntime() {
|
|
|
17433
17435
|
const base = path30.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
|
|
17434
17436
|
return base !== "node" && base !== "nodejs";
|
|
17435
17437
|
}
|
|
17438
|
+
var DEFAULT_SERVICE_NAME = "zqagent";
|
|
17439
|
+
function serviceManagerFromCgroup(cgroup, serviceName = DEFAULT_SERVICE_NAME) {
|
|
17440
|
+
const unitName = `${serviceName}.service`;
|
|
17441
|
+
for (const line of cgroup.split("\n")) {
|
|
17442
|
+
const idx = line.lastIndexOf(":");
|
|
17443
|
+
if (idx < 0) continue;
|
|
17444
|
+
const unitPath = line.slice(idx + 1).trim();
|
|
17445
|
+
if (unitPath.split("/").includes(unitName)) return "systemd";
|
|
17446
|
+
}
|
|
17447
|
+
return null;
|
|
17448
|
+
}
|
|
17449
|
+
function detectServiceManager() {
|
|
17450
|
+
if (process.platform !== "linux") return null;
|
|
17451
|
+
const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
|
|
17452
|
+
try {
|
|
17453
|
+
return serviceManagerFromCgroup(
|
|
17454
|
+
fs25.readFileSync("/proc/self/cgroup", "utf8"),
|
|
17455
|
+
serviceName
|
|
17456
|
+
);
|
|
17457
|
+
} catch {
|
|
17458
|
+
return null;
|
|
17459
|
+
}
|
|
17460
|
+
}
|
|
17436
17461
|
function serviceManager() {
|
|
17437
17462
|
const v = process.env.ZQAGENT_SERVICE_MANAGER?.trim().toLowerCase();
|
|
17438
|
-
|
|
17463
|
+
if (v === "systemd" || v === "launchd") return v;
|
|
17464
|
+
return detectServiceManager();
|
|
17465
|
+
}
|
|
17466
|
+
function parseServiceEnvironment(raw) {
|
|
17467
|
+
const out = {};
|
|
17468
|
+
for (const token of raw.trim().split(/\s+/)) {
|
|
17469
|
+
const idx = token.indexOf("=");
|
|
17470
|
+
if (idx > 0) out[token.slice(0, idx)] = token.slice(idx + 1);
|
|
17471
|
+
}
|
|
17472
|
+
return out;
|
|
17473
|
+
}
|
|
17474
|
+
var cachedServiceEnv = null;
|
|
17475
|
+
function readServiceEnvironment() {
|
|
17476
|
+
const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
|
|
17477
|
+
try {
|
|
17478
|
+
const res = spawnSync3(
|
|
17479
|
+
"systemctl",
|
|
17480
|
+
["show", serviceName, "--property=Environment", "--value", "--no-pager"],
|
|
17481
|
+
{ encoding: "utf8", timeout: 3e3 }
|
|
17482
|
+
);
|
|
17483
|
+
if (res.status !== 0 || !res.stdout) return {};
|
|
17484
|
+
return parseServiceEnvironment(res.stdout);
|
|
17485
|
+
} catch {
|
|
17486
|
+
return {};
|
|
17487
|
+
}
|
|
17488
|
+
}
|
|
17489
|
+
function serviceEnvValue(key) {
|
|
17490
|
+
if (process.platform !== "linux") return void 0;
|
|
17491
|
+
if (serviceManager() !== "systemd") return void 0;
|
|
17492
|
+
cachedServiceEnv ??= readServiceEnvironment();
|
|
17493
|
+
return cachedServiceEnv[key];
|
|
17439
17494
|
}
|
|
17440
17495
|
function selfUpdateCapability(hasPublicKey) {
|
|
17441
17496
|
if (!isSeaRuntime()) {
|
|
@@ -17458,12 +17513,12 @@ function selfUpdateCapability(hasPublicKey) {
|
|
|
17458
17513
|
|
|
17459
17514
|
// src/update/installer.ts
|
|
17460
17515
|
init_esm_shims();
|
|
17461
|
-
import * as
|
|
17516
|
+
import * as fs27 from "fs";
|
|
17462
17517
|
import * as path32 from "path";
|
|
17463
17518
|
|
|
17464
17519
|
// src/update/state.ts
|
|
17465
17520
|
init_esm_shims();
|
|
17466
|
-
import * as
|
|
17521
|
+
import * as fs26 from "fs";
|
|
17467
17522
|
import * as path31 from "path";
|
|
17468
17523
|
function updatesDir(dataDir) {
|
|
17469
17524
|
return path31.join(dataDir, "updates");
|
|
@@ -17473,7 +17528,7 @@ function statePath(dataDir) {
|
|
|
17473
17528
|
}
|
|
17474
17529
|
function loadState(dataDir) {
|
|
17475
17530
|
try {
|
|
17476
|
-
const raw =
|
|
17531
|
+
const raw = fs26.readFileSync(statePath(dataDir), "utf-8");
|
|
17477
17532
|
const parsed = JSON.parse(raw);
|
|
17478
17533
|
if (typeof parsed === "object" && parsed !== null) return parsed;
|
|
17479
17534
|
} catch {
|
|
@@ -17482,11 +17537,11 @@ function loadState(dataDir) {
|
|
|
17482
17537
|
}
|
|
17483
17538
|
function saveState(dataDir, state) {
|
|
17484
17539
|
const dir = updatesDir(dataDir);
|
|
17485
|
-
|
|
17540
|
+
fs26.mkdirSync(dir, { recursive: true });
|
|
17486
17541
|
const file = statePath(dataDir);
|
|
17487
17542
|
const tmp = `${file}.tmp`;
|
|
17488
|
-
|
|
17489
|
-
|
|
17543
|
+
fs26.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
|
|
17544
|
+
fs26.renameSync(tmp, file);
|
|
17490
17545
|
}
|
|
17491
17546
|
function patchState(dataDir, patch) {
|
|
17492
17547
|
const next = { ...loadState(dataDir), ...patch };
|
|
@@ -17500,32 +17555,32 @@ function backupDir(dataDir) {
|
|
|
17500
17555
|
}
|
|
17501
17556
|
function backupCurrent(dataDir, execPath, version) {
|
|
17502
17557
|
const dir = backupDir(dataDir);
|
|
17503
|
-
|
|
17558
|
+
fs27.mkdirSync(dir, { recursive: true });
|
|
17504
17559
|
const target = path32.join(dir, `zqagent-${version}${process.platform === "win32" ? ".exe" : ""}`);
|
|
17505
|
-
|
|
17506
|
-
|
|
17560
|
+
fs27.copyFileSync(execPath, target);
|
|
17561
|
+
fs27.chmodSync(target, 493);
|
|
17507
17562
|
return target;
|
|
17508
17563
|
}
|
|
17509
17564
|
function replaceExecutable(execPath, stagedPath) {
|
|
17510
17565
|
if (process.platform === "win32") {
|
|
17511
17566
|
const oldPath = `${execPath}.old`;
|
|
17512
|
-
|
|
17513
|
-
|
|
17514
|
-
|
|
17515
|
-
|
|
17567
|
+
fs27.rmSync(oldPath, { force: true });
|
|
17568
|
+
fs27.renameSync(execPath, oldPath);
|
|
17569
|
+
fs27.copyFileSync(stagedPath, execPath);
|
|
17570
|
+
fs27.chmodSync(execPath, 493);
|
|
17516
17571
|
return;
|
|
17517
17572
|
}
|
|
17518
17573
|
const tmp = `${execPath}.new`;
|
|
17519
|
-
|
|
17574
|
+
fs27.rmSync(tmp, { force: true });
|
|
17520
17575
|
try {
|
|
17521
|
-
|
|
17522
|
-
|
|
17523
|
-
|
|
17576
|
+
fs27.copyFileSync(stagedPath, tmp);
|
|
17577
|
+
fs27.chmodSync(tmp, 493);
|
|
17578
|
+
fs27.renameSync(tmp, execPath);
|
|
17524
17579
|
} catch (err) {
|
|
17525
|
-
|
|
17580
|
+
fs27.rmSync(tmp, { force: true });
|
|
17526
17581
|
throw err;
|
|
17527
17582
|
}
|
|
17528
|
-
|
|
17583
|
+
fs27.rmSync(stagedPath, { force: true });
|
|
17529
17584
|
}
|
|
17530
17585
|
function installStaged(opts) {
|
|
17531
17586
|
const log = opts.log ?? (() => {
|
|
@@ -17552,18 +17607,18 @@ function rollback(dataDir, execPath, log = () => {
|
|
|
17552
17607
|
}) {
|
|
17553
17608
|
const state = readRollbackTarget(dataDir);
|
|
17554
17609
|
if (!state?.backupPath || !state.backupVersion) return null;
|
|
17555
|
-
if (!
|
|
17610
|
+
if (!fs27.existsSync(state.backupPath)) return null;
|
|
17556
17611
|
log(`\u6B63\u5728\u56DE\u6EDA\u5230 v${state.backupVersion}`);
|
|
17557
17612
|
if (process.platform === "win32") {
|
|
17558
|
-
|
|
17559
|
-
|
|
17560
|
-
|
|
17561
|
-
|
|
17613
|
+
fs27.rmSync(`${execPath}.old`, { force: true });
|
|
17614
|
+
fs27.renameSync(execPath, `${execPath}.old`);
|
|
17615
|
+
fs27.copyFileSync(state.backupPath, execPath);
|
|
17616
|
+
fs27.chmodSync(execPath, 493);
|
|
17562
17617
|
} else {
|
|
17563
17618
|
const tmp = `${execPath}.rollback`;
|
|
17564
|
-
|
|
17565
|
-
|
|
17566
|
-
|
|
17619
|
+
fs27.copyFileSync(state.backupPath, tmp);
|
|
17620
|
+
fs27.chmodSync(tmp, 493);
|
|
17621
|
+
fs27.renameSync(tmp, execPath);
|
|
17567
17622
|
}
|
|
17568
17623
|
patchState(dataDir, {
|
|
17569
17624
|
pendingVersion: state.backupVersion,
|
|
@@ -17577,7 +17632,7 @@ function rollback(dataDir, execPath, log = () => {
|
|
|
17577
17632
|
}
|
|
17578
17633
|
function readRollbackTarget(dataDir) {
|
|
17579
17634
|
try {
|
|
17580
|
-
const raw =
|
|
17635
|
+
const raw = fs27.readFileSync(path32.join(updatesDir(dataDir), "state.json"), "utf-8");
|
|
17581
17636
|
const s = JSON.parse(raw);
|
|
17582
17637
|
if (s.backupPath && s.backupVersion) return s;
|
|
17583
17638
|
} catch {
|
|
@@ -17589,7 +17644,9 @@ function readRollbackTarget(dataDir) {
|
|
|
17589
17644
|
var DEFAULT_BASE = "https://agent.cd-zq.com/downloads/zqagent";
|
|
17590
17645
|
function env(key) {
|
|
17591
17646
|
const v = process.env[key]?.trim();
|
|
17592
|
-
|
|
17647
|
+
if (v) return v;
|
|
17648
|
+
const fromService = serviceEnvValue(key)?.trim();
|
|
17649
|
+
return fromService ? fromService : void 0;
|
|
17593
17650
|
}
|
|
17594
17651
|
function num(key, fallback) {
|
|
17595
17652
|
const n = Number(env(key));
|
|
@@ -17626,7 +17683,7 @@ var UpdateController = class {
|
|
|
17626
17683
|
return parsePublicKey(env("ZQAGENT_UPDATE_PUBKEY") ?? "");
|
|
17627
17684
|
}
|
|
17628
17685
|
get autoUpdateOff() {
|
|
17629
|
-
return
|
|
17686
|
+
return env("ZQAGENT_AUTO_UPDATE") === "0";
|
|
17630
17687
|
}
|
|
17631
17688
|
get enabled() {
|
|
17632
17689
|
return !this.autoUpdateOff && selfUpdateCapability(Boolean(this.publicKey)).ok;
|
|
@@ -17660,7 +17717,7 @@ var UpdateController = class {
|
|
|
17660
17717
|
reconcile() {
|
|
17661
17718
|
const state = loadState(this.opts.dataDir);
|
|
17662
17719
|
const current = this.currentVersion;
|
|
17663
|
-
if (state.stagedPath && !
|
|
17720
|
+
if (state.stagedPath && !fs28.existsSync(state.stagedPath)) {
|
|
17664
17721
|
patchState(this.opts.dataDir, { stagedVersion: void 0, stagedPath: void 0 });
|
|
17665
17722
|
}
|
|
17666
17723
|
const patch = { runningVersion: current };
|
|
@@ -17675,7 +17732,7 @@ var UpdateController = class {
|
|
|
17675
17732
|
}
|
|
17676
17733
|
patchState(this.opts.dataDir, patch);
|
|
17677
17734
|
if (process.platform === "win32") {
|
|
17678
|
-
|
|
17735
|
+
fs28.rmSync(`${process.execPath}.old`, { force: true });
|
|
17679
17736
|
}
|
|
17680
17737
|
}
|
|
17681
17738
|
schedule(delayMs) {
|
|
@@ -17751,7 +17808,7 @@ var UpdateController = class {
|
|
|
17751
17808
|
const bin = manifest.binaries[platformKey()];
|
|
17752
17809
|
if (!bin) return `\u6E05\u5355\u6CA1\u6709\u5F53\u524D\u5E73\u53F0\uFF08${platformKey()}\uFF09\u7684\u4EA7\u7269`;
|
|
17753
17810
|
let stagedPath = state.stagedPath;
|
|
17754
|
-
if (!(state.stagedVersion === manifest.version && stagedPath &&
|
|
17811
|
+
if (!(state.stagedVersion === manifest.version && stagedPath && fs28.existsSync(stagedPath))) {
|
|
17755
17812
|
stagedPath = path33.join(
|
|
17756
17813
|
updatesDir(this.opts.dataDir),
|
|
17757
17814
|
"staged",
|
|
@@ -17764,7 +17821,7 @@ var UpdateController = class {
|
|
|
17764
17821
|
}
|
|
17765
17822
|
const selfTest = selfCheck(stagedPath, manifest.version);
|
|
17766
17823
|
if (!selfTest.ok) {
|
|
17767
|
-
|
|
17824
|
+
fs28.rmSync(stagedPath, { force: true });
|
|
17768
17825
|
this.recordFailure(manifest.version, selfTest.error ?? "\u81EA\u68C0\u5931\u8D25");
|
|
17769
17826
|
return `\u5B89\u88C5\u5305\u81EA\u68C0\u5931\u8D25\uFF1A${selfTest.error}`;
|
|
17770
17827
|
}
|
|
@@ -17905,7 +17962,7 @@ function pemFile(key) {
|
|
|
17905
17962
|
const p = env2(key);
|
|
17906
17963
|
if (!p) return void 0;
|
|
17907
17964
|
try {
|
|
17908
|
-
return
|
|
17965
|
+
return fs29.readFileSync(p);
|
|
17909
17966
|
} catch (e) {
|
|
17910
17967
|
console.warn(`[tls] \u8BFB\u53D6 ${key}=${p} \u5931\u8D25: ${e instanceof Error ? e.message : e}`);
|
|
17911
17968
|
return void 0;
|