@slayzone/cli 0.36.0-beta.16 → 0.36.0-beta.17

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.
Files changed (2) hide show
  1. package/dist/slay.js +36 -11
  2. package/package.json +1 -1
package/dist/slay.js CHANGED
@@ -35722,7 +35722,7 @@ var import_node_child_process2 = require("node:child_process");
35722
35722
  var import_node_fs6 = require("node:fs");
35723
35723
  var import_node_module = require("node:module");
35724
35724
  var import_node_path6 = require("node:path");
35725
- var CLI_VERSION = true ? "0.36.0-beta.16" : "";
35725
+ var CLI_VERSION = true ? "0.36.0-beta.17" : "";
35726
35726
  function fail(message) {
35727
35727
  console.error(message);
35728
35728
  process.exit(1);
@@ -35873,7 +35873,18 @@ No output was captured in ${shortenPath(logPath)}.
35873
35873
  `)
35874
35874
  );
35875
35875
  }
35876
- function readServiceLogTail(kind, root, lines) {
35876
+ function readServiceLogTail(kind, root, lines, systemdUnit) {
35877
+ if (systemdUnit) {
35878
+ try {
35879
+ return (0, import_node_child_process2.execFileSync)(
35880
+ "journalctl",
35881
+ ["--user", "-u", systemdUnit, "-n", String(lines), "--no-pager", "-o", "cat"],
35882
+ { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], env: userServiceEnv() }
35883
+ ).trim();
35884
+ } catch {
35885
+ return "";
35886
+ }
35887
+ }
35877
35888
  const dir = logDirFor(kind, root);
35878
35889
  let files;
35879
35890
  try {
@@ -36502,6 +36513,12 @@ machines dial, recreate it with \`--public-address <host:port>\`.`
36502
36513
  `The unit for "${name}" does not record a root \u2014 it may be hand-edited. Remove it with \`slay hub rm ${name}\` and create it again.`
36503
36514
  );
36504
36515
  }
36516
+ const occupant = (await discoverAllHubs()).find((h) => h.root === root);
36517
+ if (occupant) {
36518
+ fail(
36519
+ `A hub is already running in ${shortenPath(root)} \u2014 "${occupant.name}" on port ${occupant.port} (pid ${occupant.pid}). Starting "${name}" would put two hubs on the same store.`
36520
+ );
36521
+ }
36505
36522
  await launchHub({ name, root, backend, creating: false });
36506
36523
  });
36507
36524
  cmd.command("stop <name|port>").description("Stop a hub, keeping it registered so `start` can bring it back").action(async (nameOrPort) => {
@@ -36564,7 +36581,14 @@ machines dial, recreate it with \`--public-address <host:port>\`.`
36564
36581
  console.log(`Unit updated to ${HUB_PACKAGE}@${bin.version}.`);
36565
36582
  }
36566
36583
  supervisorStop("hub", backend, name);
36567
- await waitForHubGone(hub.port, 15e3);
36584
+ if (!await waitForHubGone(hub.port, 15e3)) {
36585
+ fail(
36586
+ `Hub "${name}" is still answering on port ${hub.port} after 15s, so restarting would leave TWO hubs sharing ${shortenPath(root)} \u2014 refusing.
36587
+ It is not owned by ${backend} (started by hand, docker, or before it was registered). Stop that process first:
36588
+ kill ${hub.pid}
36589
+ then \`slay hub start ${name}\`.`
36590
+ );
36591
+ }
36568
36592
  supervisorStart("hub", backend, name, unitPath("hub", name, backend));
36569
36593
  const back = await waitForHub(() => findHub(name), 2e4);
36570
36594
  if (!back) fail(`Hub "${name}" did not come back within 20s. Check ${shortenPath(logDir)}.`);
@@ -36869,10 +36893,11 @@ function requireRegistered(name, backend) {
36869
36893
  }
36870
36894
  return { root };
36871
36895
  }
36872
- async function waitForConnected(root, timeoutMs) {
36896
+ async function waitForConnected(root, timeoutMs, backend, name) {
36897
+ const unit = backend === "systemd" ? systemdUnitName("runner", name) : void 0;
36873
36898
  const deadline = Date.now() + timeoutMs;
36874
36899
  for (; ; ) {
36875
- if (CONNECTED_RE.test(readServiceLogTail("runner", root, 200))) return true;
36900
+ if (CONNECTED_RE.test(readServiceLogTail("runner", root, 200, unit))) return true;
36876
36901
  if (Date.now() >= deadline) return false;
36877
36902
  await new Promise((r) => setTimeout(r, 300));
36878
36903
  }
@@ -36900,7 +36925,7 @@ async function launchRunner(args) {
36900
36925
  }
36901
36926
  });
36902
36927
  child.unref();
36903
- if (!await waitForConnected(root, ENROLL_TIMEOUT_MS)) {
36928
+ if (!await waitForConnected(root, ENROLL_TIMEOUT_MS, backend, name)) {
36904
36929
  if (creating) runCreateRollback();
36905
36930
  failWithLog(
36906
36931
  "runner",
@@ -36953,7 +36978,7 @@ then log out and back in, and retry. If this account is not meant to have one (a
36953
36978
  ` : "")
36954
36979
  );
36955
36980
  }
36956
- if (!await waitForConnected(root, ENROLL_TIMEOUT_MS)) {
36981
+ if (!await waitForConnected(root, ENROLL_TIMEOUT_MS, backend, name)) {
36957
36982
  if (creating) {
36958
36983
  supervisorStop("runner", backend, name);
36959
36984
  removeUnit("runner", name, backend);
@@ -37058,10 +37083,10 @@ ${explainNoBackend(detectBackendWithReason().reason)}`);
37058
37083
  `${r.name.padEnd(nameW)} ${state(r).padEnd(9)} ${(r.root ? shortenPath(r.root) : "?").padEnd(rootW)} ${(r.hubUrl ?? "-").padEnd(hubW)} ${enrolled(r)}`
37059
37084
  );
37060
37085
  }
37061
- if (!hubReachable) {
37086
+ if (!hubReachable && runners.some((r) => enrolled(r) === "?")) {
37062
37087
  console.log(
37063
37088
  `
37064
- No hub could be reached, so ENROLLED is unknown ("?") for runners this machine has no local record of.`
37089
+ No hub could be reached, so ENROLLED is "?" for runners with no local credentials \u2014 they may or may not be enrolled.`
37065
37090
  );
37066
37091
  }
37067
37092
  const unmanaged = runners.filter((r) => state(r) === "unmanaged");
@@ -37230,7 +37255,7 @@ Start it with \`slay runner start ${name}\`, or remove it with \`slay runner rm
37230
37255
  supervisorStop("runner", backend, name);
37231
37256
  await waitForStopped(name, backend, 15e3);
37232
37257
  supervisorStart("runner", backend, name, unitPath("runner", name, backend));
37233
- if (!await waitForConnected(root, ENROLL_TIMEOUT_MS)) {
37258
+ if (!await waitForConnected(root, ENROLL_TIMEOUT_MS, backend, name)) {
37234
37259
  fail(
37235
37260
  `Runner "${name}" did not reconnect within ${ENROLL_TIMEOUT_MS / 1e3}s. Check \`slay runner logs ${name}\`.`
37236
37261
  );
@@ -37437,7 +37462,7 @@ function updateCommand() {
37437
37462
  }
37438
37463
 
37439
37464
  // src/index.ts
37440
- var program2 = new Command().name("slay").description("SlayZone CLI").version("0.36.0-beta.16").option("--dev", "Use development database (slayzone.dev.sqlite)").option("--hub <name|port>", "Target a specific hub on this machine (see `slay hub ls`)").showSuggestionAfterError(true).showHelpAfterError(true).hook("preAction", async (thisCommand) => {
37465
+ var program2 = new Command().name("slay").description("SlayZone CLI").version("0.36.0-beta.17").option("--dev", "Use development database (slayzone.dev.sqlite)").option("--hub <name|port>", "Target a specific hub on this machine (see `slay hub ls`)").showSuggestionAfterError(true).showHelpAfterError(true).hook("preAction", async (thisCommand) => {
37441
37466
  const root = thisCommand.parent ?? thisCommand;
37442
37467
  const opts = root.opts();
37443
37468
  if (opts.dev) process.env.SLAYZONE_DEV = "1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slayzone/cli",
3
- "version": "0.36.0-beta.16",
3
+ "version": "0.36.0-beta.17",
4
4
  "description": "SlayZone CLI — run, list and target SlayZone hubs; drive tasks, ptys and projects",
5
5
  "license": "GPL-3.0-only",
6
6
  "private": false,