@cosmicstack/mercury-agent 1.1.11 → 1.1.12
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/index.js +35 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21481,6 +21481,26 @@ import { existsSync as existsSync25, readFileSync as readFileSync19, writeFileSy
|
|
|
21481
21481
|
import { join as join19 } from "path";
|
|
21482
21482
|
import process2 from "process";
|
|
21483
21483
|
import chalk5 from "chalk";
|
|
21484
|
+
function isStandaloneBinary() {
|
|
21485
|
+
const isBunRuntime = typeof process2.versions.bun === "string";
|
|
21486
|
+
if (!isBunRuntime) return false;
|
|
21487
|
+
const arg1 = process2.argv[1];
|
|
21488
|
+
if (!arg1) return true;
|
|
21489
|
+
if (arg1.includes("$bunfs") || arg1.includes("/~BUN/") || arg1.includes("\\~BUN\\")) return true;
|
|
21490
|
+
const execName = (process2.execPath.split(/[\\/]/).pop() || "").toLowerCase();
|
|
21491
|
+
if (!execName.startsWith("node") && !execName.startsWith("bun")) return true;
|
|
21492
|
+
return false;
|
|
21493
|
+
}
|
|
21494
|
+
function buildDaemonSpawnArgs() {
|
|
21495
|
+
if (isStandaloneBinary()) {
|
|
21496
|
+
return { command: process2.execPath, args: ["start", "--daemon"] };
|
|
21497
|
+
}
|
|
21498
|
+
const script = process2.argv[1];
|
|
21499
|
+
if (!script) {
|
|
21500
|
+
throw new Error("Cannot determine Mercury entry script for daemon spawn");
|
|
21501
|
+
}
|
|
21502
|
+
return { command: process2.execPath, args: [script, "start", "--daemon"] };
|
|
21503
|
+
}
|
|
21484
21504
|
var PID_FILE = "daemon.pid";
|
|
21485
21505
|
var LOG_FILE = "daemon.log";
|
|
21486
21506
|
function pidPath() {
|
|
@@ -21533,7 +21553,8 @@ function ensureDaemonRunning() {
|
|
|
21533
21553
|
const logFile = logPath();
|
|
21534
21554
|
const isWin = process2.platform === "win32";
|
|
21535
21555
|
const outFd = openSync(logFile, "a");
|
|
21536
|
-
const
|
|
21556
|
+
const { command, args } = buildDaemonSpawnArgs();
|
|
21557
|
+
const child = spawn4(command, args, {
|
|
21537
21558
|
detached: true,
|
|
21538
21559
|
stdio: ["ignore", outFd, outFd],
|
|
21539
21560
|
env: { ...process2.env },
|
|
@@ -21669,6 +21690,12 @@ function getDistPath() {
|
|
|
21669
21690
|
}
|
|
21670
21691
|
return join20(process.argv[1], "..", "..", "lib", "node_modules", "@cosmicstack", "mercury-agent", "dist", "index.js");
|
|
21671
21692
|
}
|
|
21693
|
+
function getServiceLaunchArgs() {
|
|
21694
|
+
if (isStandaloneBinary()) {
|
|
21695
|
+
return [process.execPath, "start", "--daemon"];
|
|
21696
|
+
}
|
|
21697
|
+
return [getNodeBinPath(), getDistPath(), "start", "--daemon"];
|
|
21698
|
+
}
|
|
21672
21699
|
function installService() {
|
|
21673
21700
|
const platform2 = process.platform;
|
|
21674
21701
|
if (platform2 === "darwin") {
|
|
@@ -21716,6 +21743,8 @@ function installMac() {
|
|
|
21716
21743
|
const home = getMercuryHome();
|
|
21717
21744
|
const logPath2 = join20(home, "daemon.log");
|
|
21718
21745
|
const errPath = join20(home, "daemon-error.log");
|
|
21746
|
+
const launchArgs = getServiceLaunchArgs();
|
|
21747
|
+
const programArgsXml = launchArgs.map((a) => ` <string>${a}</string>`).join("\n");
|
|
21719
21748
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
21720
21749
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
21721
21750
|
<plist version="1.0">
|
|
@@ -21724,10 +21753,7 @@ function installMac() {
|
|
|
21724
21753
|
<string>com.cosmicstack.mercury</string>
|
|
21725
21754
|
<key>ProgramArguments</key>
|
|
21726
21755
|
<array>
|
|
21727
|
-
|
|
21728
|
-
<string>${scriptPath}</string>
|
|
21729
|
-
<string>start</string>
|
|
21730
|
-
<string>--daemon</string>
|
|
21756
|
+
${programArgsXml}
|
|
21731
21757
|
</array>
|
|
21732
21758
|
<key>RunAtLoad</key>
|
|
21733
21759
|
<true/>
|
|
@@ -21815,13 +21841,14 @@ function installLinux() {
|
|
|
21815
21841
|
const nodeBin = getNodeBinPath();
|
|
21816
21842
|
const scriptPath = getDistPath();
|
|
21817
21843
|
const home = getMercuryHome();
|
|
21844
|
+
const execStart = getServiceLaunchArgs().map((a) => /[\s"]/.test(a) ? `"${a.replace(/"/g, '\\"')}"` : a).join(" ");
|
|
21818
21845
|
const service = `[Unit]
|
|
21819
21846
|
Description=${SERVICE_DESC}
|
|
21820
21847
|
After=network.target
|
|
21821
21848
|
|
|
21822
21849
|
[Service]
|
|
21823
21850
|
Type=simple
|
|
21824
|
-
ExecStart=${
|
|
21851
|
+
ExecStart=${execStart}
|
|
21825
21852
|
Restart=on-failure
|
|
21826
21853
|
RestartSec=5
|
|
21827
21854
|
Environment=PATH=${process.env.PATH || "/usr/local/bin:/usr/bin:/bin"}
|
|
@@ -21906,7 +21933,7 @@ function installWindows() {
|
|
|
21906
21933
|
const scriptPath = getDistPath();
|
|
21907
21934
|
const home = getMercuryHome();
|
|
21908
21935
|
const logPath2 = join20(home, "daemon.log");
|
|
21909
|
-
const cmd = `"${
|
|
21936
|
+
const cmd = getServiceLaunchArgs().map((a) => `"${a}"`).join(" ");
|
|
21910
21937
|
try {
|
|
21911
21938
|
execSync8(
|
|
21912
21939
|
`schtasks /create /tn "${WIN_TASK_NAME}" /tr "${cmd}" /sc onlogon /rl limited /f`,
|
|
@@ -24042,7 +24069,7 @@ var pkgVersion;
|
|
|
24042
24069
|
try {
|
|
24043
24070
|
pkgVersion = JSON.parse(readFileSync28(join29(__dirname2, "..", "package.json"), "utf8")).version;
|
|
24044
24071
|
} catch {
|
|
24045
|
-
pkgVersion = "1.1.
|
|
24072
|
+
pkgVersion = "1.1.12";
|
|
24046
24073
|
}
|
|
24047
24074
|
function hr() {
|
|
24048
24075
|
console.log(chalk7.dim("\u2500".repeat(50)));
|