@infernetprotocol/cli 0.1.62 → 0.1.63

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/commands/setup.js CHANGED
@@ -15,7 +15,7 @@
15
15
  * infernet setup --skip-pull # don't pull a model
16
16
  */
17
17
 
18
- import { execFile, spawn } from "node:child_process";
18
+ import { execFile, spawn, spawnSync } from "node:child_process";
19
19
  import fsSync from "node:fs";
20
20
  import { promisify } from "node:util";
21
21
  import { fileURLToPath } from "node:url";
@@ -33,7 +33,7 @@ import {
33
33
  lastDetectionDiagnostics
34
34
  } from "@infernetprotocol/gpu";
35
35
  import { isDaemonAlive } from "../lib/ipc.js";
36
- import { ensureService } from "./service.js";
36
+ import { ensureService, systemUnitPresent } from "./service.js";
37
37
  import { createNodeClient } from "../lib/node-client.js";
38
38
 
39
39
  const pExec = promisify(execFile);
@@ -827,7 +827,7 @@ export default async function setup(args) {
827
827
  n += 1;
828
828
  step(n, total, "Daemon");
829
829
  const wasAlive = await isDaemonAlive(500);
830
- if (wasAlive) {
830
+ if (wasAlive && !systemUnitPresent()) {
831
831
  process.stdout.write(" daemon was running — restarting so it picks up current CLI code\n");
832
832
  try {
833
833
  await runSubcommand("stop", []);
@@ -842,10 +842,20 @@ export default async function setup(args) {
842
842
  let startCode = 0;
843
843
  const noService = args.has("no-service") || process.env.INFERNET_NO_SERVICE === "1"
844
844
  || fsSync.existsSync("/.dockerenv") || fsSync.existsSync("/run/.containerenv");
845
- const svc = noService ? { ok: false, reason: "disabled" } : await ensureService({ log: (m) => ok(m) });
846
- if (!svc.ok) {
847
- if (!noService) process.stdout.write(` no service unit (${svc.reason}); using the built-in supervisor\n`);
848
- startCode = await runSubcommand("start", []);
845
+ if (systemUnitPresent()) {
846
+ // A system-wide infernet.service owns the daemon (fleet boxes, root
847
+ // installs). Starting another one here is how a second daemon leaked
848
+ // next to it for a week on bbs; restart the unit instead.
849
+ const r = spawnSync("systemctl", ["restart", "infernet.service"], { stdio: "pipe" });
850
+ const viaSudo = r.status === 0 ? r : spawnSync("sudo", ["-n", "systemctl", "restart", "infernet.service"], { stdio: "pipe" });
851
+ if (viaSudo.status === 0) ok("restarted infernet.service");
852
+ else warn("infernet.service manages the daemon; restart it with: sudo systemctl restart infernet");
853
+ } else {
854
+ const svc = noService ? { ok: false, reason: "disabled" } : await ensureService({ log: (m) => ok(m) });
855
+ if (!svc.ok) {
856
+ if (!noService) process.stdout.write(` no service unit (${svc.reason}); using the built-in supervisor\n`);
857
+ startCode = await runSubcommand("start", []);
858
+ }
849
859
  }
850
860
  if (startCode !== 0) {
851
861
  fail(`start exited ${startCode}`);
package/commands/start.js CHANGED
@@ -63,7 +63,7 @@ import { getOrCreateModelKey, getModelPublicKeys } from '../lib/model-key.js';
63
63
  import { pullLatestBinary } from './upgrade.js';
64
64
  import { PROBE_INTERVAL_MS, runProbeRound } from '../lib/aggregator.js';
65
65
  import { nodeTokenLogin } from './login.js';
66
- import { CURRENT_VERSION, fetchLatestVersion, isNewerVersion } from '../lib/version.js';
66
+ import { CURRENT_VERSION, fetchLatestVersion, isNewerVersion, readInstalledVersion } from '../lib/version.js';
67
67
  import { readInferenceState, readInferenceStateSync, isPidAlive } from '../lib/inference/state.js';
68
68
 
69
69
  function readInferenceStateSyncSafe() {
@@ -94,6 +94,7 @@ const DEFAULT_HEARTBEAT_MS = 30_000;
94
94
  const DEFAULT_POLL_MS = 15_000;
95
95
  const UPDATE_CHECK_MS = 5 * 60 * 1000; // 5 minutes
96
96
  const UPDATE_DRAIN_MS = 10 * 60 * 1000; // wait for in-flight jobs before restarting
97
+ const UPDATE_PAUSE_MS = 6 * 60 * 60 * 1000; // after an update that installed nothing newer
97
98
  const SHUTDOWN_DEADLINE_MS = 5_000; // hard exit: a half-shut daemon must never outlive its pidfile
98
99
  const OFFLINE_HEARTBEAT_TIMEOUT_MS = 3_000;
99
100
 
@@ -1624,8 +1625,9 @@ async function runDaemon(args, ctx) {
1624
1625
  // available, pull the installer, re-generate any missing keys + re-register
1625
1626
  // specs (idempotent), then re-exec so the new code is running immediately.
1626
1627
  let isUpgrading = false;
1628
+ let updatePausedUntil = 0;
1627
1629
  const updateTimer = setInterval(async () => {
1628
- if (shuttingDown || isUpgrading) return;
1630
+ if (shuttingDown || isUpgrading || Date.now() < updatePausedUntil) return;
1629
1631
  // Never start an upgrade under a running job; the next check retries.
1630
1632
  if (stats.activeJobIds.size > 0) return;
1631
1633
  const latest = await fetchLatestVersion();
@@ -1639,6 +1641,17 @@ async function runDaemon(args, ctx) {
1639
1641
  isUpgrading = false;
1640
1642
  return;
1641
1643
  }
1644
+ // The installer can succeed without changing this install (a git checkout
1645
+ // whose package.json lagged the release, or npm writing to another
1646
+ // prefix). Restarting then would rerun the same update every 5 minutes
1647
+ // forever, so keep serving and try again much later.
1648
+ const installed = readInstalledVersion();
1649
+ if (!isNewerVersion(CURRENT_VERSION, installed)) {
1650
+ updatePausedUntil = Date.now() + UPDATE_PAUSE_MS;
1651
+ process.stderr.write(`[update] installer left v${installed} here (latest v${latest}); not restarting, next try in ${UPDATE_PAUSE_MS / 3_600_000}h\n`);
1652
+ isUpgrading = false;
1653
+ return;
1654
+ }
1642
1655
 
1643
1656
  // Post-upgrade: run `infernet upgrade --skip-setup` is already done
1644
1657
  // (pullLatestBinary above). Now run setup --yes so keys are regenerated,
@@ -45,7 +45,10 @@ function runShell(cmd) {
45
45
 
46
46
  export async function pullLatestBinary() {
47
47
  process.stdout.write(`\n→ Pulling latest CLI from ${INSTALLER_URL}\n\n`);
48
- const code = await runShell(`curl -fsSL ${INSTALLER_URL} | sh`);
48
+ // INFERNET_AUTOSTART=0: the installer would otherwise run `infernet setup`,
49
+ // which restarts (or, next to infernet.service, duplicates) the daemon from
50
+ // inside its own self-update. Both callers run setup themselves afterwards.
51
+ const code = await runShell(`curl -fsSL ${INSTALLER_URL} | INFERNET_AUTOSTART=0 sh`);
49
52
  if (code !== 0) {
50
53
  process.stderr.write(`\nerror: installer exited ${code}.\n`);
51
54
  return false;
package/lib/version.js CHANGED
@@ -3,9 +3,21 @@ import { join, dirname } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
4
 
5
5
  const _dir = dirname(fileURLToPath(import.meta.url));
6
- export const CURRENT_VERSION = JSON.parse(
7
- readFileSync(join(_dir, '../package.json'), 'utf8')
8
- ).version;
6
+ export const CURRENT_VERSION = readInstalledVersion();
7
+
8
+ /**
9
+ * The version on disk right now, read fresh (CURRENT_VERSION is what this
10
+ * process started with). Self-update compares the two after the installer
11
+ * runs: if nothing newer landed, restarting would only repeat the same update
12
+ * every 5 minutes.
13
+ */
14
+ export function readInstalledVersion() {
15
+ try {
16
+ return JSON.parse(readFileSync(join(_dir, '../package.json'), 'utf8')).version;
17
+ } catch {
18
+ return '0.0.0';
19
+ }
20
+ }
9
21
 
10
22
  export async function fetchLatestVersion() {
11
23
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infernetprotocol/cli",
3
- "version": "0.1.62",
3
+ "version": "0.1.63",
4
4
  "description": "GPU-node CLI / daemon for the Infernet Protocol — register a GPU server with a Supabase control plane and start earning.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,12 +30,12 @@
30
30
  "ora": "^9.4.0",
31
31
  "react": "^17.0.2",
32
32
  "react-blessed": "^0.7.2",
33
- "@infernetprotocol/deploy-providers": "0.1.62",
34
- "@infernetprotocol/gpu": "0.1.62",
35
- "@infernetprotocol/rpc-adapter": "0.1.62",
36
- "@infernetprotocol/engine": "0.1.62",
37
- "@infernetprotocol/auth": "0.1.62",
38
- "@infernetprotocol/config": "0.1.62"
33
+ "@infernetprotocol/config": "0.1.63",
34
+ "@infernetprotocol/rpc-adapter": "0.1.63",
35
+ "@infernetprotocol/engine": "0.1.63",
36
+ "@infernetprotocol/gpu": "0.1.63",
37
+ "@infernetprotocol/auth": "0.1.63",
38
+ "@infernetprotocol/deploy-providers": "0.1.63"
39
39
  },
40
40
  "repository": {
41
41
  "type": "git",