| 509 | }; |
| 510 | |
| 511 | const down = async (targetName: string) => { |
| 512 | const state = readState(targetName); |
| 513 | if (!state) return console.log(`${targetName}: nothing recorded`); |
| 514 | if (alive(state.runnerPid)) { |
| 515 | process.kill(state.runnerPid, "SIGTERM"); |
| 516 | const deadline = Date.now() + 10_000; |
| 517 | while (alive(state.runnerPid) && Date.now() < deadline) { |
| 518 | await new Promise((resolve) => setTimeout(resolve, 200)); |
| 519 | } |
| 520 | } |
| 521 | // Runner gone (or was already): make sure the children are too. |
| 522 | for (const pid of state.childPids ?? []) { |
| 523 | try { |
| 524 | process.kill(-pid, "SIGKILL"); |
| 525 | } catch { |
| 526 | try { |
| 527 | process.kill(pid, "SIGKILL"); |
| 528 | } catch { |
| 529 | // already gone |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | if (state.servePorts) { |
| 534 | const ts = await findTailscale(); |
| 535 | if (ts) for (const port of state.servePorts) await sh(ts, ["serve", `--https=${port}`, "off"]); |
| 536 | } |
| 537 | rmSync(statePath(targetName), { force: true }); |
| 538 | console.log(`${targetName}: down`); |
| 539 | }; |
| 540 | |
| 541 | const logs = (targetName: string) => { |
| 542 | const state = readState(targetName); |