@infernetprotocol/cli 0.1.62 → 0.1.64

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,32 +1625,53 @@ 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;
1629
+ // INFERNET_AUTO_UPDATE=follow: never run the installer here, only restart
1630
+ // once something else (the box's provider daemon) has installed a newer
1631
+ // version. For a second daemon on the same install, e.g. an aggregator, so
1632
+ // two daemons never run the installer at once.
1633
+ const followOnly = process.env.INFERNET_AUTO_UPDATE === 'follow';
1627
1634
  const updateTimer = setInterval(async () => {
1628
- if (shuttingDown || isUpgrading) return;
1635
+ if (shuttingDown || isUpgrading || Date.now() < updatePausedUntil) return;
1629
1636
  // Never start an upgrade under a running job; the next check retries.
1630
1637
  if (stats.activeJobIds.size > 0) return;
1631
- const latest = await fetchLatestVersion();
1638
+ const latest = followOnly ? readInstalledVersion() : await fetchLatestVersion();
1632
1639
  if (!latest || !isNewerVersion(CURRENT_VERSION, latest)) return;
1633
1640
  isUpgrading = true;
1634
1641
 
1635
- process.stdout.write(`[update] v${latest} available (running v${CURRENT_VERSION}) — upgrading\n`);
1636
- const ok = await pullLatestBinary();
1637
- if (!ok) {
1638
- process.stderr.write('[update] installer failed — will retry next check\n');
1639
- isUpgrading = false;
1640
- return;
1641
- }
1642
+ if (followOnly) {
1643
+ process.stdout.write(`[update] v${latest} installed on this machine (running v${CURRENT_VERSION}) — restarting into it\n`);
1644
+ } else {
1645
+ process.stdout.write(`[update] v${latest} available (running v${CURRENT_VERSION}) — upgrading\n`);
1646
+ const ok = await pullLatestBinary();
1647
+ if (!ok) {
1648
+ process.stderr.write('[update] installer failed — will retry next check\n');
1649
+ isUpgrading = false;
1650
+ return;
1651
+ }
1652
+ // The installer can succeed without changing this install (a git checkout
1653
+ // whose package.json lagged the release, or npm writing to another
1654
+ // prefix). Restarting then would rerun the same update every 5 minutes
1655
+ // forever, so keep serving and try again much later.
1656
+ const installed = readInstalledVersion();
1657
+ if (!isNewerVersion(CURRENT_VERSION, installed)) {
1658
+ updatePausedUntil = Date.now() + UPDATE_PAUSE_MS;
1659
+ 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`);
1660
+ isUpgrading = false;
1661
+ return;
1662
+ }
1642
1663
 
1643
- // Post-upgrade: run `infernet upgrade --skip-setup` is already done
1644
- // (pullLatestBinary above). Now run setup --yes so keys are regenerated,
1645
- // specs re-registered, and the daemon restarts cleanly via re-exec below.
1646
- process.stdout.write('[update] re-initializing keys and specs\n');
1647
- try {
1648
- const { default: setup } = await import('./setup.js');
1649
- const setupArgs = new Map([['yes', true], ['confirm', true], ['skip-pull', true], ['skip-daemon', true]]);
1650
- await setup(setupArgs, { config, client, configPath });
1651
- } catch (err) {
1652
- process.stderr.write(`[update] post-upgrade setup: ${err?.message ?? err}\n`);
1664
+ // Post-upgrade: run `infernet upgrade --skip-setup` is already done
1665
+ // (pullLatestBinary above). Now run setup --yes so keys are regenerated,
1666
+ // specs re-registered, and the daemon restarts cleanly via re-exec below.
1667
+ process.stdout.write('[update] re-initializing keys and specs\n');
1668
+ try {
1669
+ const { default: setup } = await import('./setup.js');
1670
+ const setupArgs = new Map([['yes', true], ['confirm', true], ['skip-pull', true], ['skip-daemon', true]]);
1671
+ await setup(setupArgs, { config, client, configPath });
1672
+ } catch (err) {
1673
+ process.stderr.write(`[update] post-upgrade setup: ${err?.message ?? err}\n`);
1674
+ }
1653
1675
  }
1654
1676
 
1655
1677
  // Jobs that arrived while the installer ran get to finish: stop taking
@@ -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.64",
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/auth": "0.1.64",
34
+ "@infernetprotocol/deploy-providers": "0.1.64",
35
+ "@infernetprotocol/config": "0.1.64",
36
+ "@infernetprotocol/engine": "0.1.64",
37
+ "@infernetprotocol/gpu": "0.1.64",
38
+ "@infernetprotocol/rpc-adapter": "0.1.64"
39
39
  },
40
40
  "repository": {
41
41
  "type": "git",