@infernetprotocol/cli 0.1.22
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/LICENSE +15 -0
- package/commands/chat.js +268 -0
- package/commands/console.js +229 -0
- package/commands/debug.js +222 -0
- package/commands/deploy.js +524 -0
- package/commands/doctor.js +501 -0
- package/commands/firewall.js +39 -0
- package/commands/gpu.js +130 -0
- package/commands/help.js +54 -0
- package/commands/init.js +304 -0
- package/commands/login.js +305 -0
- package/commands/logs.js +93 -0
- package/commands/model.js +359 -0
- package/commands/payments.js +92 -0
- package/commands/payout.js +128 -0
- package/commands/pubkey.js +116 -0
- package/commands/register.js +304 -0
- package/commands/remove.js +230 -0
- package/commands/service.js +255 -0
- package/commands/setup.js +869 -0
- package/commands/start.js +903 -0
- package/commands/stats.js +85 -0
- package/commands/status.js +116 -0
- package/commands/stop.js +81 -0
- package/commands/train.js +563 -0
- package/commands/tui.js +285 -0
- package/commands/uncensored.js +222 -0
- package/commands/update.js +80 -0
- package/commands/upgrade.js +2 -0
- package/examples/app.js +153 -0
- package/index.js +207 -0
- package/lib/chat-executor.js +232 -0
- package/lib/config.js +148 -0
- package/lib/daemonize.js +46 -0
- package/lib/firewall.js +190 -0
- package/lib/hf-model.js +166 -0
- package/lib/identity.js +18 -0
- package/lib/ipc.js +114 -0
- package/lib/model-fit.js +67 -0
- package/lib/model-key.js +52 -0
- package/lib/network.js +240 -0
- package/lib/nip44.js +130 -0
- package/lib/node-client.js +152 -0
- package/lib/peers.js +133 -0
- package/lib/prompt.js +49 -0
- package/lib/remote-chat.js +115 -0
- package/lib/route.js +44 -0
- package/lib/runtime-config.js +130 -0
- package/lib/version.js +32 -0
- package/package.json +57 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `infernet service` — userland systemd integration for the daemon.
|
|
3
|
+
*
|
|
4
|
+
* An optional alternative to running `infernet start` directly /
|
|
5
|
+
* `infernet start` (detached). When installed, systemd manages the
|
|
6
|
+
* daemon: auto-restart on crash, optional auto-start at boot, logs
|
|
7
|
+
* to journald. Runs as the unprivileged user — never touches /etc
|
|
8
|
+
* or anything system-wide. Service file lives under
|
|
9
|
+
* ~/.config/systemd/user/infernet.service.
|
|
10
|
+
*
|
|
11
|
+
* Linux-only (uses systemd --user). macOS / Windows users continue
|
|
12
|
+
* to run `infernet start` directly or wire their own supervisor.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* infernet service install write the unit file + daemon-reload
|
|
16
|
+
* infernet service uninstall stop / disable / delete the unit file
|
|
17
|
+
* infernet service enable systemctl --user enable --now infernet
|
|
18
|
+
* infernet service disable systemctl --user disable --now infernet
|
|
19
|
+
* infernet service status systemctl --user status infernet
|
|
20
|
+
* infernet service logs journalctl --user -u infernet -f
|
|
21
|
+
* infernet service unit print the unit file we'd write (no side effects)
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import fs from "node:fs/promises";
|
|
25
|
+
import path from "node:path";
|
|
26
|
+
import os from "node:os";
|
|
27
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
28
|
+
import { fileURLToPath } from "node:url";
|
|
29
|
+
import { question } from "../lib/prompt.js";
|
|
30
|
+
|
|
31
|
+
export const SERVICE_NAME = "infernet";
|
|
32
|
+
|
|
33
|
+
const HELP = `infernet service — manage the userland systemd unit
|
|
34
|
+
|
|
35
|
+
Usage:
|
|
36
|
+
infernet service <subcommand> [flags]
|
|
37
|
+
|
|
38
|
+
Subcommands:
|
|
39
|
+
install Write ~/.config/systemd/user/${SERVICE_NAME}.service and daemon-reload
|
|
40
|
+
uninstall Stop, disable, and remove the unit file
|
|
41
|
+
enable systemctl --user enable --now ${SERVICE_NAME}
|
|
42
|
+
disable systemctl --user disable --now ${SERVICE_NAME}
|
|
43
|
+
status systemctl --user status ${SERVICE_NAME}
|
|
44
|
+
logs journalctl --user -u ${SERVICE_NAME} -f
|
|
45
|
+
unit Print the unit file that would be written (no side effects)
|
|
46
|
+
|
|
47
|
+
Flags:
|
|
48
|
+
--confirm Skip the install / uninstall confirmation prompt.
|
|
49
|
+
--enable-after After install, also enable + start. Default: no.
|
|
50
|
+
-h, --help Show this help.
|
|
51
|
+
|
|
52
|
+
Notes:
|
|
53
|
+
- Linux-only (uses systemd --user). Skip on macOS / Windows.
|
|
54
|
+
- Type=simple. ExecStart calls 'infernet start --foreground' so
|
|
55
|
+
systemd owns the process (no double-fork).
|
|
56
|
+
- Logs go to journald; tail with 'journalctl --user -u ${SERVICE_NAME} -f'
|
|
57
|
+
or 'infernet service logs'.
|
|
58
|
+
- For boot persistence on a system without a logged-in user
|
|
59
|
+
session, run 'loginctl enable-linger $USER' once.
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
export function getServicePath() {
|
|
63
|
+
return path.join(os.homedir(), ".config", "systemd", "user", `${SERVICE_NAME}.service`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Render the unit file contents from inputs. Pure function — easy to
|
|
68
|
+
* unit-test, no side effects, no environment lookups.
|
|
69
|
+
*
|
|
70
|
+
* @param {{ nodeBin: string, cliEntry: string, environment?: Record<string,string>, description?: string }} args
|
|
71
|
+
*/
|
|
72
|
+
export function buildServiceUnit({ nodeBin, cliEntry, environment = {}, description } = {}) {
|
|
73
|
+
if (!nodeBin) throw new Error("buildServiceUnit: nodeBin is required");
|
|
74
|
+
if (!cliEntry) throw new Error("buildServiceUnit: cliEntry is required");
|
|
75
|
+
|
|
76
|
+
const desc = description ?? "Infernet Protocol provider daemon";
|
|
77
|
+
const envLines = Object.entries(environment)
|
|
78
|
+
.filter(([, v]) => v !== undefined && v !== null && v !== "")
|
|
79
|
+
.map(([k, v]) => `Environment=${k}=${v}`);
|
|
80
|
+
|
|
81
|
+
return [
|
|
82
|
+
"[Unit]",
|
|
83
|
+
`Description=${desc}`,
|
|
84
|
+
"Documentation=https://infernetprotocol.com",
|
|
85
|
+
"After=network-online.target",
|
|
86
|
+
"Wants=network-online.target",
|
|
87
|
+
"",
|
|
88
|
+
"[Service]",
|
|
89
|
+
"Type=simple",
|
|
90
|
+
`ExecStart=${nodeBin} ${cliEntry} start --foreground`,
|
|
91
|
+
"Restart=on-failure",
|
|
92
|
+
"RestartSec=10",
|
|
93
|
+
"Environment=NODE_ENV=production",
|
|
94
|
+
...envLines,
|
|
95
|
+
"",
|
|
96
|
+
"[Install]",
|
|
97
|
+
"WantedBy=default.target",
|
|
98
|
+
""
|
|
99
|
+
].join("\n");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function resolveCliEntry() {
|
|
103
|
+
// service.js lives at apps/cli/commands/service.js. The CLI entry
|
|
104
|
+
// is one directory up at apps/cli/index.js.
|
|
105
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
106
|
+
return path.resolve(here, "..", "index.js");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function ensureLinux() {
|
|
110
|
+
if (process.platform !== "linux") {
|
|
111
|
+
process.stderr.write(
|
|
112
|
+
`error: 'infernet service' is Linux-only (your platform: ${process.platform}).\n` +
|
|
113
|
+
` use 'infernet start' directly, or wire your own supervisor (launchd, sc, etc.)\n`
|
|
114
|
+
);
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function runSystemctl(args, { inherit = true } = {}) {
|
|
121
|
+
const opts = inherit ? { stdio: "inherit" } : { stdio: "pipe" };
|
|
122
|
+
return spawnSync("systemctl", ["--user", ...args], opts);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function installCmd(args) {
|
|
126
|
+
if (!ensureLinux()) return 2;
|
|
127
|
+
const yes = args.has("confirm") || args.has("yes");
|
|
128
|
+
const enableAfter = args.has("enable-after");
|
|
129
|
+
|
|
130
|
+
const unit = buildServiceUnit({
|
|
131
|
+
nodeBin: process.execPath,
|
|
132
|
+
cliEntry: resolveCliEntry()
|
|
133
|
+
});
|
|
134
|
+
const target = getServicePath();
|
|
135
|
+
|
|
136
|
+
process.stdout.write("\nWill write:\n");
|
|
137
|
+
process.stdout.write("─".repeat(60) + "\n");
|
|
138
|
+
process.stdout.write(unit);
|
|
139
|
+
process.stdout.write("─".repeat(60) + "\n\n");
|
|
140
|
+
process.stdout.write(`To: ${target}\n\n`);
|
|
141
|
+
|
|
142
|
+
if (!yes) {
|
|
143
|
+
const ans = await question("Install?", { default: "y" });
|
|
144
|
+
if (!ans.toLowerCase().startsWith("y")) {
|
|
145
|
+
process.stdout.write("aborted\n");
|
|
146
|
+
return 1;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
151
|
+
await fs.writeFile(target, unit, { mode: 0o644 });
|
|
152
|
+
process.stdout.write(`✓ wrote ${target}\n`);
|
|
153
|
+
|
|
154
|
+
const reload = runSystemctl(["daemon-reload"]);
|
|
155
|
+
if (reload.status !== 0) {
|
|
156
|
+
process.stderr.write("warning: 'systemctl --user daemon-reload' failed — your changes may not be picked up until the next reload.\n");
|
|
157
|
+
} else {
|
|
158
|
+
process.stdout.write("✓ systemctl --user daemon-reload\n");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (enableAfter) {
|
|
162
|
+
const enabled = runSystemctl(["enable", "--now", SERVICE_NAME]);
|
|
163
|
+
if (enabled.status === 0) {
|
|
164
|
+
process.stdout.write("✓ enabled and started\n");
|
|
165
|
+
} else {
|
|
166
|
+
process.stderr.write("warning: enable --now failed; run manually with 'systemctl --user enable --now infernet'\n");
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
process.stdout.write("\nNext:\n");
|
|
170
|
+
process.stdout.write(" systemctl --user enable --now infernet # auto-start at login + run now\n");
|
|
171
|
+
process.stdout.write(" systemctl --user status infernet # check status\n");
|
|
172
|
+
process.stdout.write(" journalctl --user -u infernet -f # tail logs\n");
|
|
173
|
+
process.stdout.write(" loginctl enable-linger $USER # (one-time) keep running when not logged in\n");
|
|
174
|
+
}
|
|
175
|
+
return 0;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function uninstallCmd(args) {
|
|
179
|
+
if (!ensureLinux()) return 2;
|
|
180
|
+
const yes = args.has("confirm") || args.has("yes");
|
|
181
|
+
const target = getServicePath();
|
|
182
|
+
|
|
183
|
+
let exists = true;
|
|
184
|
+
try { await fs.access(target); } catch { exists = false; }
|
|
185
|
+
|
|
186
|
+
if (!exists) {
|
|
187
|
+
process.stdout.write(`No service file at ${target}; nothing to do.\n`);
|
|
188
|
+
return 0;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
process.stdout.write(`Will stop / disable / delete: ${target}\n`);
|
|
192
|
+
if (!yes) {
|
|
193
|
+
const ans = await question("Uninstall?", { default: "y" });
|
|
194
|
+
if (!ans.toLowerCase().startsWith("y")) {
|
|
195
|
+
process.stdout.write("aborted\n");
|
|
196
|
+
return 1;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
runSystemctl(["disable", "--now", SERVICE_NAME], { inherit: false });
|
|
201
|
+
try {
|
|
202
|
+
await fs.unlink(target);
|
|
203
|
+
process.stdout.write(`✓ removed ${target}\n`);
|
|
204
|
+
} catch (err) {
|
|
205
|
+
process.stderr.write(`failed to remove unit file: ${err?.message ?? err}\n`);
|
|
206
|
+
return 1;
|
|
207
|
+
}
|
|
208
|
+
runSystemctl(["daemon-reload"], { inherit: false });
|
|
209
|
+
process.stdout.write("✓ uninstalled\n");
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function spawnInherited(bin, argv) {
|
|
214
|
+
return new Promise((resolve) => {
|
|
215
|
+
const child = spawn(bin, argv, { stdio: "inherit" });
|
|
216
|
+
child.on("exit", (code) => resolve(code ?? 0));
|
|
217
|
+
child.on("error", () => resolve(1));
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export default async function service(args) {
|
|
222
|
+
if (args.has("help") || args.has("h")) {
|
|
223
|
+
process.stdout.write(HELP);
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
const sub = (args.positional ?? [])[0];
|
|
227
|
+
switch (sub) {
|
|
228
|
+
case "install": return installCmd(args);
|
|
229
|
+
case "uninstall": return uninstallCmd(args);
|
|
230
|
+
case "enable":
|
|
231
|
+
if (!ensureLinux()) return 2;
|
|
232
|
+
return spawnInherited("systemctl", ["--user", "enable", "--now", SERVICE_NAME]);
|
|
233
|
+
case "disable":
|
|
234
|
+
if (!ensureLinux()) return 2;
|
|
235
|
+
return spawnInherited("systemctl", ["--user", "disable", "--now", SERVICE_NAME]);
|
|
236
|
+
case "status":
|
|
237
|
+
if (!ensureLinux()) return 2;
|
|
238
|
+
return spawnInherited("systemctl", ["--user", "status", SERVICE_NAME]);
|
|
239
|
+
case "logs":
|
|
240
|
+
if (!ensureLinux()) return 2;
|
|
241
|
+
return spawnInherited("journalctl", ["--user", "-u", SERVICE_NAME, "-f"]);
|
|
242
|
+
case "unit":
|
|
243
|
+
process.stdout.write(buildServiceUnit({
|
|
244
|
+
nodeBin: process.execPath,
|
|
245
|
+
cliEntry: resolveCliEntry()
|
|
246
|
+
}));
|
|
247
|
+
return 0;
|
|
248
|
+
default:
|
|
249
|
+
process.stderr.write(sub
|
|
250
|
+
? `unknown subcommand: ${sub}\n\n`
|
|
251
|
+
: "error: missing subcommand\n\n");
|
|
252
|
+
process.stderr.write(HELP);
|
|
253
|
+
return 2;
|
|
254
|
+
}
|
|
255
|
+
}
|