engine7 7.1.5 → 7.1.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.mjs +3 -52
- package/dist/engine-startup.mjs +19 -0
- package/dist/main.mjs +19 -0
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -447,7 +447,8 @@ async function main() {
|
|
|
447
447
|
printHelp();
|
|
448
448
|
process.exit(0);
|
|
449
449
|
}
|
|
450
|
-
if (subcommand === "start") {
|
|
450
|
+
if (subcommand === "start" || subcommand === "restart") {
|
|
451
|
+
const label = subcommand === "restart" ? "\u{1F504} engine7 restart" : "\u{1F680} engine7 start";
|
|
451
452
|
let configPath2 = "";
|
|
452
453
|
for (let i = 1; i < args.length; i++) {
|
|
453
454
|
if (args[i] === "--config" && args[i + 1]) {
|
|
@@ -512,7 +513,7 @@ engine7 start \u2014 \u542F\u52A8 Engine
|
|
|
512
513
|
}
|
|
513
514
|
}
|
|
514
515
|
}
|
|
515
|
-
console.log(
|
|
516
|
+
console.log(label);
|
|
516
517
|
console.log(` config: ${configPath2}`);
|
|
517
518
|
console.log(` engine: ${enginePath}`);
|
|
518
519
|
const configName = path.basename(configPath2);
|
|
@@ -539,56 +540,6 @@ engine7 start \u2014 \u542F\u52A8 Engine
|
|
|
539
540
|
child.on("exit", (code) => process.exit(code ?? 1));
|
|
540
541
|
return;
|
|
541
542
|
}
|
|
542
|
-
if (subcommand === "restart") {
|
|
543
|
-
const { execSync } = await import("node:child_process");
|
|
544
|
-
const myPid = process.pid;
|
|
545
|
-
console.log("\u{1F504} engine7 restart");
|
|
546
|
-
try {
|
|
547
|
-
if (process.platform === "win32") {
|
|
548
|
-
execSync(`powershell -Command "Get-WmiObject Win32_Process | Where-Object { $_.Name -eq 'node.exe' -and $_.CommandLine -like '*dist/main.mjs*' -and $_.ProcessId -ne ${myPid} } | ForEach-Object { Write-Host '[restart] Killing PID' $_.ProcessId; Stop-Process -Id $_.ProcessId -Force }"`, { stdio: "inherit" });
|
|
549
|
-
} else {
|
|
550
|
-
const pids = execSync(`pgrep -f "dist/main.mjs" 2>/dev/null || true`, { encoding: "utf-8" }).trim();
|
|
551
|
-
const otherPids = pids.split("\n").filter((p) => p && p.trim() !== String(myPid)).join("\n").trim();
|
|
552
|
-
if (otherPids) {
|
|
553
|
-
console.log(`[restart] Killing existing engine (PID: ${otherPids})...`);
|
|
554
|
-
execSync(`echo "${otherPids}" | xargs kill -9 2>/dev/null || true`);
|
|
555
|
-
await new Promise((r) => setTimeout(r, 2e3));
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
} catch {
|
|
559
|
-
}
|
|
560
|
-
let configPath2 = "";
|
|
561
|
-
for (let i = 1; i < args.length; i++) {
|
|
562
|
-
if (args[i] === "--config" && args[i + 1]) configPath2 = args[++i];
|
|
563
|
-
}
|
|
564
|
-
if (!configPath2) {
|
|
565
|
-
const defaultCfg = path.join("configs", "main7.json");
|
|
566
|
-
const homeCfg = path.join(process.env.HOME || process.env.USERPROFILE || ".", ".engine7", "configs", "main7.json");
|
|
567
|
-
if (fs.existsSync(defaultCfg)) configPath2 = defaultCfg;
|
|
568
|
-
else if (fs.existsSync(homeCfg)) configPath2 = homeCfg;
|
|
569
|
-
else {
|
|
570
|
-
const ptr = readHomePointer();
|
|
571
|
-
if (ptr?.stateDir) {
|
|
572
|
-
const ptrCfg = path.join(ptr.stateDir, "configs", "main7.json");
|
|
573
|
-
if (fs.existsSync(ptrCfg)) configPath2 = ptrCfg;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
if (!configPath2) {
|
|
578
|
-
console.error("\u274C \u627E\u4E0D\u5230 config");
|
|
579
|
-
process.exit(1);
|
|
580
|
-
}
|
|
581
|
-
const cliPath = path.resolve(process.argv[1]);
|
|
582
|
-
const distDir = path.dirname(cliPath);
|
|
583
|
-
const enginePath = fs.existsSync(path.join(distDir, "main.mjs")) ? path.join(distDir, "main.mjs") : path.join(path.dirname(path.dirname(cliPath)), "lib", "node_modules", "engine7", "dist", "main.mjs");
|
|
584
|
-
console.log(` config: ${configPath2}`);
|
|
585
|
-
console.log(` engine: ${enginePath}`);
|
|
586
|
-
console.log("");
|
|
587
|
-
const { spawn } = await import("node:child_process");
|
|
588
|
-
const child = spawn(process.execPath, [enginePath, "--engine-config", configPath2], { stdio: "inherit", shell: false });
|
|
589
|
-
child.on("exit", (code) => process.exit(code ?? 1));
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
543
|
if (subcommand === "service") {
|
|
593
544
|
const action = args[1];
|
|
594
545
|
if (!action || action === "--help" || action === "-h") {
|
package/dist/engine-startup.mjs
CHANGED
|
@@ -29646,8 +29646,27 @@ function killTree(pid) {
|
|
|
29646
29646
|
try {
|
|
29647
29647
|
if (process.platform === "win32") {
|
|
29648
29648
|
execSync(`taskkill /PID ${pid} /T /F`, { stdio: "ignore", timeout: 8e3 });
|
|
29649
|
+
try {
|
|
29650
|
+
const parentPid = execSync(`wmic process where ProcessId=${pid} get ParentProcessId /value`, { encoding: "utf-8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }).match(/ParentProcessId=(\d+)/)?.[1];
|
|
29651
|
+
if (parentPid && parseInt(parentPid) !== process.ppid) {
|
|
29652
|
+
execSync(`taskkill /PID ${parentPid} /F`, { stdio: "ignore", timeout: 3e3 });
|
|
29653
|
+
}
|
|
29654
|
+
} catch {
|
|
29655
|
+
}
|
|
29649
29656
|
} else {
|
|
29650
29657
|
process.kill(pid, "SIGKILL");
|
|
29658
|
+
try {
|
|
29659
|
+
const ppid = parseInt(fs.readFileSync(`/proc/${pid}/status`, "utf-8").match(/PPid:\s+(\d+)/)?.[1] || "0", 10);
|
|
29660
|
+
const macPpid = parseInt(execSync(`ps -p ${pid} -o ppid=`, { encoding: "utf-8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }).trim(), 10);
|
|
29661
|
+
const parentPid = ppid || macPpid;
|
|
29662
|
+
if (parentPid && parentPid > 1) {
|
|
29663
|
+
try {
|
|
29664
|
+
process.kill(parentPid, "SIGKILL");
|
|
29665
|
+
} catch {
|
|
29666
|
+
}
|
|
29667
|
+
}
|
|
29668
|
+
} catch {
|
|
29669
|
+
}
|
|
29651
29670
|
}
|
|
29652
29671
|
} catch (err) {
|
|
29653
29672
|
console.warn(`[pid-lock] kill ${pid} failed: ${err.message}`);
|
package/dist/main.mjs
CHANGED
|
@@ -30004,8 +30004,27 @@ function killTree(pid) {
|
|
|
30004
30004
|
try {
|
|
30005
30005
|
if (process.platform === "win32") {
|
|
30006
30006
|
execSync(`taskkill /PID ${pid} /T /F`, { stdio: "ignore", timeout: 8e3 });
|
|
30007
|
+
try {
|
|
30008
|
+
const parentPid = execSync(`wmic process where ProcessId=${pid} get ParentProcessId /value`, { encoding: "utf-8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }).match(/ParentProcessId=(\d+)/)?.[1];
|
|
30009
|
+
if (parentPid && parseInt(parentPid) !== process.ppid) {
|
|
30010
|
+
execSync(`taskkill /PID ${parentPid} /F`, { stdio: "ignore", timeout: 3e3 });
|
|
30011
|
+
}
|
|
30012
|
+
} catch {
|
|
30013
|
+
}
|
|
30007
30014
|
} else {
|
|
30008
30015
|
process.kill(pid, "SIGKILL");
|
|
30016
|
+
try {
|
|
30017
|
+
const ppid = parseInt(fs2.readFileSync(`/proc/${pid}/status`, "utf-8").match(/PPid:\s+(\d+)/)?.[1] || "0", 10);
|
|
30018
|
+
const macPpid = parseInt(execSync(`ps -p ${pid} -o ppid=`, { encoding: "utf-8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }).trim(), 10);
|
|
30019
|
+
const parentPid = ppid || macPpid;
|
|
30020
|
+
if (parentPid && parentPid > 1) {
|
|
30021
|
+
try {
|
|
30022
|
+
process.kill(parentPid, "SIGKILL");
|
|
30023
|
+
} catch {
|
|
30024
|
+
}
|
|
30025
|
+
}
|
|
30026
|
+
} catch {
|
|
30027
|
+
}
|
|
30009
30028
|
}
|
|
30010
30029
|
} catch (err) {
|
|
30011
30030
|
console.warn(`[pid-lock] kill ${pid} failed: ${err.message}`);
|