hub-runner 0.1.1 → 0.1.2
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/bin/hub-runner.mjs +17 -8
- package/package.json +1 -1
package/bin/hub-runner.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, readFileSync, rmSync } from 'node:fs';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
4
5
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
5
6
|
import { credentialsFile, logFile } from '../lib/paths.mjs';
|
|
6
7
|
import { kickstart, loaded, start, stop } from '../lib/launchd.mjs';
|
|
@@ -17,16 +18,23 @@ const USAGE = `hub-runner login | start [--take-over] | stop | restart | status
|
|
|
17
18
|
logs the runner's log; -f follows it
|
|
18
19
|
logout stop the runner and forget the sign-in`;
|
|
19
20
|
|
|
20
|
-
/** SIGUSR2 drains the runner (open turns finish, nothing new starts) and it exits 6; then launchd starts it again.
|
|
21
|
+
/** SIGUSR2 drains the runner (open turns finish, nothing new starts) and it exits 6; then launchd starts it again.
|
|
22
|
+
* The signal, the wait and the kickstart all run in a detached process: run from a bot the runner hosts, this CLI is
|
|
23
|
+
* in the runner's process group, which launchd kills when the runner exits. */
|
|
21
24
|
async function restart() {
|
|
22
25
|
const runner = live();
|
|
23
|
-
if (runner)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (!runner) return kickstart();
|
|
27
|
+
console.log(`waiting for open turns on pid ${runner.pid} to finish`);
|
|
28
|
+
const relaunch = spawn(process.execPath, [fileURLToPath(import.meta.url), 'relaunch', String(runner.pid)], { detached: true, stdio: ['ignore', 'ignore', 'inherit'] });
|
|
29
|
+
const code = await new Promise((resolve, reject) => relaunch.on('error', reject).on('exit', resolve));
|
|
30
|
+
if (code !== 0) process.exitCode = 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function relaunch(pid) {
|
|
34
|
+
process.kill(pid, 'SIGUSR2');
|
|
35
|
+
while (alive(pid)) await sleep(250);
|
|
36
|
+
const { exitCode } = read(pid);
|
|
37
|
+
if (exitCode !== 6) throw new Error(`the runner ended during the drain with exit code ${exitCode}, not 6: see \`hub-runner logs\`, then run \`hub-runner start\``);
|
|
30
38
|
kickstart();
|
|
31
39
|
}
|
|
32
40
|
|
|
@@ -54,6 +62,7 @@ try {
|
|
|
54
62
|
case 'start': start({ takeOver: args.includes('--take-over') }); console.log('started: see `hub-runner status`'); break;
|
|
55
63
|
case 'stop': stop(); break;
|
|
56
64
|
case 'restart': await restart(); break;
|
|
65
|
+
case 'relaunch': await relaunch(Number(args[0])); break;
|
|
57
66
|
case 'status': status(); break;
|
|
58
67
|
case 'logs': logs(args.includes('-f')); break;
|
|
59
68
|
case 'logout': stop(); rmSync(credentialsFile(), { force: true }); break;
|