feat: add relay:tmux:attach to join existing session

This commit is contained in:
Peter Steinberger
2025-11-25 05:53:21 +01:00
parent 072998a6ab
commit 071786fe16
2 changed files with 27 additions and 11 deletions

View File

@@ -270,5 +270,18 @@ With Tailscale:
}
});
program
.command("relay:tmux:attach")
.description("Attach to the existing warelay-relay tmux session (no restart)")
.action(async () => {
try {
await spawnRelayTmux("pnpm warelay relay --verbose", true, false);
defaultRuntime.log(info("Attached to warelay-relay session."));
} catch (err) {
defaultRuntime.error(danger(`Failed to attach to warelay-relay: ${String(err)}`));
defaultRuntime.exit(1);
}
});
return program;
}

View File

@@ -5,19 +5,22 @@ const SESSION = "warelay-relay";
export async function spawnRelayTmux(
cmd = "pnpm warelay relay --verbose",
attach = true,
restart = true,
) {
await killSession(SESSION);
await new Promise<void>((resolve, reject) => {
const child = spawn("tmux", ["new", "-d", "-s", SESSION, cmd], {
stdio: "inherit",
shell: false,
if (restart) {
await killSession(SESSION);
await new Promise<void>((resolve, reject) => {
const child = spawn("tmux", ["new", "-d", "-s", SESSION, cmd], {
stdio: "inherit",
shell: false,
});
child.on("error", reject);
child.on("exit", (code) => {
if (code === 0) resolve();
else reject(new Error(`tmux exited with code ${code}`));
});
});
child.on("error", reject);
child.on("exit", (code) => {
if (code === 0) resolve();
else reject(new Error(`tmux exited with code ${code}`));
});
});
}
if (attach) {
await new Promise<void>((resolve, reject) => {