remote-agents 0.1.0 → 0.1.1
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/package.json +1 -1
- package/run.js +33 -7
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Launcher: exec the downloaded native `remote-agent` binary, forwarding args,
|
|
3
|
-
// stdin/stdout/stderr, and exit code.
|
|
3
|
+
// stdin/stdout/stderr, termination signals, and exit code.
|
|
4
|
+
// `remote-agents <cmd>` == `remote-agent <cmd>`.
|
|
4
5
|
|
|
5
6
|
const path = require("path");
|
|
6
7
|
const fs = require("fs");
|
|
7
|
-
const
|
|
8
|
+
const os = require("os");
|
|
9
|
+
const { spawn } = require("child_process");
|
|
8
10
|
|
|
9
11
|
const exe = process.platform === "win32" ? ".exe" : "";
|
|
10
12
|
const bin = path.join(__dirname, "bin", `remote-agent${exe}`);
|
|
@@ -17,9 +19,33 @@ if (!fs.existsSync(bin)) {
|
|
|
17
19
|
process.exit(1);
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const child = spawn(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
23
|
+
|
|
24
|
+
// Forward termination signals so stopping this launcher also stops the agent
|
|
25
|
+
// (spawnSync used to orphan the native process).
|
|
26
|
+
const SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP", "SIGQUIT"];
|
|
27
|
+
for (const sig of SIGNALS) {
|
|
28
|
+
process.on(sig, () => {
|
|
29
|
+
if (!child.killed) {
|
|
30
|
+
try {
|
|
31
|
+
child.kill(sig);
|
|
32
|
+
} catch {
|
|
33
|
+
/* child already gone */
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
24
37
|
}
|
|
25
|
-
|
|
38
|
+
|
|
39
|
+
child.on("error", (err) => {
|
|
40
|
+
console.error(`remote-agents: failed to launch binary: ${err.message}`);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
child.on("exit", (code, signal) => {
|
|
45
|
+
if (signal) {
|
|
46
|
+
// Mirror the child's signal in our exit status (128 + signum).
|
|
47
|
+
const num = (os.constants.signals && os.constants.signals[signal]) || 15;
|
|
48
|
+
process.exit(128 + num);
|
|
49
|
+
}
|
|
50
|
+
process.exit(code === null ? 1 : code);
|
|
51
|
+
});
|