@animastor/installer 0.1.0
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 +21 -0
- package/README.md +66 -0
- package/ai/install-manifests/audio/qwen-tts.json +445 -0
- package/ai/install-manifests/image/qwen-image.json +465 -0
- package/ai/install-manifests/video/ltx-2.3.json +892 -0
- package/package.json +42 -0
- package/src/installer/cli.js +1067 -0
- package/src/installer/compatibility-resolver.js +1287 -0
- package/src/installer/download-planner.js +172 -0
- package/src/installer/engine/comfyui.js +508 -0
- package/src/installer/engine/downloader.js +514 -0
- package/src/installer/engine/engine.js +1180 -0
- package/src/installer/engine/io.js +437 -0
- package/src/installer/engine/logger.js +75 -0
- package/src/installer/engine/nodes.js +146 -0
- package/src/installer/engine/prereq.js +399 -0
- package/src/installer/engine/probe.js +349 -0
- package/src/installer/engine/progress.js +350 -0
- package/src/installer/engine/state.js +170 -0
- package/src/installer/engine/term.js +298 -0
- package/src/installer/engine/worker.js +430 -0
- package/src/installer/engine/workflows.js +153 -0
- package/src/installer/index.js +40 -0
- package/src/installer/install-manifest.js +376 -0
- package/src/installer/install-plan.js +741 -0
- package/src/installer/management.js +489 -0
- package/src/installer/platform/deployment/docker.js +78 -0
- package/src/installer/platform/deployment/native.js +36 -0
- package/src/installer/platform/index.js +165 -0
- package/src/installer/platform/linux.js +341 -0
- package/src/installer/platform/windows.js +360 -0
- package/src/installer/safety-rules.js +156 -0
- package/src/installer/setup-contract.js +1401 -0
- package/src/installer/uninstaller.js +572 -0
- package/src/installer/verification-report.js +220 -0
- package/src/installer/worker-bundle-source.js +64 -0
- package/src/installer/workflow-artifacts.js +152 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Platform abstraction — Private Worker Installer (cross-platform prep).
|
|
5
|
+
*
|
|
6
|
+
* Two ORTHOGONAL dimensions (never mix them):
|
|
7
|
+
*
|
|
8
|
+
* Platform — the operating system the installer runs on:
|
|
9
|
+
* 'linux' | 'windows'
|
|
10
|
+
* (auto-detected from process.platform; never a CLI flag)
|
|
11
|
+
*
|
|
12
|
+
* Deployment — HOW the installer's products run:
|
|
13
|
+
* 'native' | 'docker'
|
|
14
|
+
* (docker is a deployment of a platform — usually linux —
|
|
15
|
+
* NOT a platform of its own)
|
|
16
|
+
*
|
|
17
|
+
* The universal engine code calls the adapter methods listed in
|
|
18
|
+
* `ADAPTER_INTERFACE`; each platform module (linux.js / windows.js) provides
|
|
19
|
+
* its own implementation. Adapters are loaded LAZILY: selecting the windows
|
|
20
|
+
* adapter never loads linux-only code paths (and vice versa) — guaranteed by
|
|
21
|
+
* the architecture test suite.
|
|
22
|
+
*
|
|
23
|
+
* Adapters are chosen automatically. Production support today:
|
|
24
|
+
* linux + native — fully supported (unchanged behavior)
|
|
25
|
+
* windows + native — architectural preview (platform adapter present)
|
|
26
|
+
* * + docker — deployment adapter prepared, NOT production-supported
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const path = require('path');
|
|
30
|
+
|
|
31
|
+
/** OS platforms the installer knows about (adapter modules exist). */
|
|
32
|
+
const PLATFORMS = Object.freeze(['linux', 'windows']);
|
|
33
|
+
|
|
34
|
+
/** Deployment targets (docker is a DEPLOYMENT, not an OS). */
|
|
35
|
+
const DEPLOYMENTS = Object.freeze(['native', 'docker']);
|
|
36
|
+
|
|
37
|
+
/** Canonical platform for a Node.js platform id, or null when unsupported. */
|
|
38
|
+
function detectPlatform(processPlatform = process.platform) {
|
|
39
|
+
if (processPlatform === 'linux') return 'linux';
|
|
40
|
+
if (processPlatform === 'win32') return 'windows';
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Deployment detection: docker when the container markers are present.
|
|
46
|
+
* Pure when `fsExists`/`env` are injected (tests); on a real host it probes
|
|
47
|
+
* the canonical /.dockerenv marker plus the common env fingerprints.
|
|
48
|
+
* Docker markers are only meaningful on the linux platform — windows
|
|
49
|
+
* containers are explicitly not a target.
|
|
50
|
+
*/
|
|
51
|
+
function detectDeployment({ platform = detectPlatform(), fsExists = null, env = process.env } = {}) {
|
|
52
|
+
if (platform === 'windows') return 'native';
|
|
53
|
+
const exists = fsExists || ((p) => { try { return require('fs').existsSync(p); } catch (_) { return false; } });
|
|
54
|
+
if (exists('/.dockerenv')) return 'docker';
|
|
55
|
+
if (env.ANIMASTOR_DEPLOYMENT) {
|
|
56
|
+
const v = String(env.ANIMASTOR_DEPLOYMENT).toLowerCase();
|
|
57
|
+
if (v === 'docker' || v === 'native') return v;
|
|
58
|
+
}
|
|
59
|
+
if (/docker|containerd|kubepods/.test(String(env.container || ''))) return 'docker';
|
|
60
|
+
return 'native';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Raised when the host platform has no adapter (e.g. darwin, freebsd). */
|
|
64
|
+
class UnsupportedPlatformError extends Error {
|
|
65
|
+
constructor(platform) {
|
|
66
|
+
super(`unsupported platform "${platform ?? 'unknown'}": the Animastor installer supports linux and windows (docker is a separate deployment target).`);
|
|
67
|
+
this.name = 'UnsupportedPlatformError';
|
|
68
|
+
this.code = 'unsupported_platform';
|
|
69
|
+
this.platform = platform ?? null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Adapter modules are LAZY so a selected platform never loads the others. */
|
|
74
|
+
const ADAPTER_MODULES = {
|
|
75
|
+
linux: () => require('./linux'),
|
|
76
|
+
windows: () => require('./windows'),
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** Resolved-adapter cache (one module instance per platform). */
|
|
80
|
+
const adapterCache = new Map();
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The full adapter surface the engine is allowed to call. Documented here so
|
|
84
|
+
* every platform module implements the same contract (checked by tests).
|
|
85
|
+
*/
|
|
86
|
+
const ADAPTER_INTERFACE = Object.freeze([
|
|
87
|
+
'name', 'displayName', 'productionReady',
|
|
88
|
+
'HOME_ENV', 'UID_GUARD', 'TOOL_SCRIPT_MODE',
|
|
89
|
+
'defaultRoot', 'defaultWorkerDir', 'venvPythonBin',
|
|
90
|
+
'findPidsByCmdlineAndCwd', 'readProcessCwd', 'readProcessCmdline',
|
|
91
|
+
'processStartMs', 'pidUid', 'findComfyUIPids', 'findPidsByCwdPrefix',
|
|
92
|
+
'sleepCommand', 'killCommand', 'psCheckCommand',
|
|
93
|
+
'hostPackageCommand', 'hostPackagesCommand', 'checkBuildPrerequisites',
|
|
94
|
+
'toolScriptName', 'renderToolScript',
|
|
95
|
+
'probeAmdGpu',
|
|
96
|
+
]);
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Resolve the platform adapter. Lazily requires ONLY the selected module —
|
|
100
|
+
* on linux the windows module is never imported, and vice versa.
|
|
101
|
+
* @param {string|null|undefined} platform explicit platform id; default = auto-detect
|
|
102
|
+
* @returns {object} platform adapter (see ADAPTER_INTERFACE)
|
|
103
|
+
* @throws UnsupportedPlatformError for darwin/freebsd/… (clear, early, loud)
|
|
104
|
+
*/
|
|
105
|
+
function getPlatformAdapter(platform) {
|
|
106
|
+
const id = platform == null ? detectPlatform() : platform;
|
|
107
|
+
if (!id || !PLATFORMS.includes(id)) {
|
|
108
|
+
throw new UnsupportedPlatformError(id);
|
|
109
|
+
}
|
|
110
|
+
let mod = adapterCache.get(id);
|
|
111
|
+
if (mod) return mod;
|
|
112
|
+
mod = ADAPTER_MODULES[id]();
|
|
113
|
+
for (const key of ADAPTER_INTERFACE) {
|
|
114
|
+
if (mod[key] === undefined) {
|
|
115
|
+
throw new Error(`platform adapter "${id}" is incomplete: missing "${key}"`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
adapterCache.set(id, mod);
|
|
119
|
+
return mod;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Resolve the deployment adapter. Lazily requires ONLY the selected module.
|
|
124
|
+
* Docker deployment on a windows platform is rejected: docker is a linux
|
|
125
|
+
* deployment target (windows containers are explicitly out of scope).
|
|
126
|
+
*/
|
|
127
|
+
function getDeploymentAdapter(deployment = 'native', { platform = detectPlatform() } = {}) {
|
|
128
|
+
if (!DEPLOYMENTS.includes(deployment)) {
|
|
129
|
+
throw new Error(`unknown deployment "${deployment}" (expected one of ${DEPLOYMENTS.join(', ')})`);
|
|
130
|
+
}
|
|
131
|
+
if (deployment === 'docker' && platform && platform !== 'linux') {
|
|
132
|
+
throw new Error(`docker deployment requires the linux platform (got "${platform}"); windows containers are not a supported target.`);
|
|
133
|
+
}
|
|
134
|
+
return require(`./deployment/${deployment}`);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Resolve the runtime context for a whole installer run: one platform
|
|
139
|
+
* adapter + one deployment adapter + the effective production-support
|
|
140
|
+
* verdict. This is the single entry point the CLI/engine should use.
|
|
141
|
+
*/
|
|
142
|
+
function resolveRuntime({ platform = detectPlatform(), deployment = null, env = process.env } = {}) {
|
|
143
|
+
const adapter = getPlatformAdapter(platform);
|
|
144
|
+
const dep = deployment || detectDeployment({ platform, env });
|
|
145
|
+
const deploymentAdapter = getDeploymentAdapter(dep, { platform });
|
|
146
|
+
return {
|
|
147
|
+
platform,
|
|
148
|
+
deployment: dep,
|
|
149
|
+
adapter,
|
|
150
|
+
deploymentAdapter,
|
|
151
|
+
productionReady: adapter.productionReady && deploymentAdapter.productionReady,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = {
|
|
156
|
+
PLATFORMS,
|
|
157
|
+
DEPLOYMENTS,
|
|
158
|
+
ADAPTER_INTERFACE,
|
|
159
|
+
UnsupportedPlatformError,
|
|
160
|
+
detectPlatform,
|
|
161
|
+
detectDeployment,
|
|
162
|
+
getPlatformAdapter,
|
|
163
|
+
getDeploymentAdapter,
|
|
164
|
+
resolveRuntime,
|
|
165
|
+
};
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Linux platform adapter — Private Worker Installer (cross-platform prep).
|
|
5
|
+
*
|
|
6
|
+
* Extracts every OS-specific behaviour of the installer that is genuinely
|
|
7
|
+
* Linux-specific so the universal engine code can stay platform-neutral:
|
|
8
|
+
*
|
|
9
|
+
* - process discovery via /proc (cwd-verified, never global pkill);
|
|
10
|
+
* - process start time / uid from /proc/<pid>;
|
|
11
|
+
* - venv layout (bin/python);
|
|
12
|
+
* - Debian/Ubuntu apt remediation commands;
|
|
13
|
+
* - POSIX shell management-tool wrappers (#!/bin/sh);
|
|
14
|
+
* - AMD GPU detection via sysfs/rocm-smi/lspci.
|
|
15
|
+
*
|
|
16
|
+
* IMPORTANT CONTRACT: every method takes the `io` abstraction as its first
|
|
17
|
+
* argument (or reads it from the options object) and uses ONLY io.exec /
|
|
18
|
+
* io.fs primitives. This keeps the adapter fully testable with the memory
|
|
19
|
+
* fs + scripted exec mocks, exactly like the engine code it was extracted
|
|
20
|
+
* from — the existing Linux test suite keeps passing unchanged.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const path = require('path');
|
|
24
|
+
|
|
25
|
+
const NAME = 'linux';
|
|
26
|
+
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
// Paths
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
/** Default ComfyUI root: $HOME/ComfyUI (POSIX home layout). */
|
|
32
|
+
function defaultRoot(home) {
|
|
33
|
+
return path.join(home || '/root', 'ComfyUI');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Default worker bundle dir: $HOME/animastor/worker. */
|
|
37
|
+
function defaultWorkerDir(home) {
|
|
38
|
+
return path.join(home || '/root', 'animastor', 'worker');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Home directory env var name on this platform. */
|
|
42
|
+
const HOME_ENV = 'HOME';
|
|
43
|
+
|
|
44
|
+
/** Python interpreter inside a venv (POSIX layout). */
|
|
45
|
+
function venvPythonBin(venvDir) {
|
|
46
|
+
return path.join(venvDir, 'bin', 'python');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Process management (procfs-backed)
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* PIDs of processes whose command line matches `cmdPattern` AND whose cwd
|
|
55
|
+
* equals `cwd`. `pgrep -f` matches host-wide, so every candidate is confirmed
|
|
56
|
+
* via /proc/<pid>/cwd — a foreign installation is never touched.
|
|
57
|
+
* @returns {number[]} matching pids
|
|
58
|
+
*/
|
|
59
|
+
function findPidsByCmdlineAndCwd(io, { cmdPattern, cwd }) {
|
|
60
|
+
const out = [];
|
|
61
|
+
const r = io.exec('pgrep', ['-f', cmdPattern]);
|
|
62
|
+
if (!r || r.code !== 0 || !r.stdout) return out;
|
|
63
|
+
for (const line of String(r.stdout).split('\n')) {
|
|
64
|
+
const pid = Number(line.trim());
|
|
65
|
+
if (!Number.isFinite(pid) || pid <= 0) continue;
|
|
66
|
+
const cwdRes = io.exec('readlink', [`/proc/${pid}/cwd`]);
|
|
67
|
+
if (cwdRes && cwdRes.code === 0
|
|
68
|
+
&& path.resolve(String(cwdRes.stdout).trim()) === path.resolve(cwd)) {
|
|
69
|
+
out.push(pid);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** cwd of a pid (readlink /proc/<pid>/cwd) or null. */
|
|
76
|
+
function readProcessCwd(io, pid) {
|
|
77
|
+
const r = io.exec('readlink', [`/proc/${pid}/cwd`]);
|
|
78
|
+
return r && r.code === 0 ? String(r.stdout).trim() : null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Command line argv of a pid (/proc/<pid>/cmdline, NUL-separated) or null. */
|
|
82
|
+
function readProcessCmdline(io, pid) {
|
|
83
|
+
try {
|
|
84
|
+
return io.fs.readFileSync(`/proc/${pid}/cmdline`, 'utf8').split('\0').filter(Boolean);
|
|
85
|
+
} catch (_) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Process start time in ms (/proc/<pid> mtime is the Linux start time). */
|
|
91
|
+
function processStartMs(io, pid) {
|
|
92
|
+
try {
|
|
93
|
+
return io.fs.statSync(`/proc/${pid}`).mtimeMs;
|
|
94
|
+
} catch (_) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Uid owning a process (/proc/<pid> stat) or null when unavailable. */
|
|
100
|
+
function pidUid(io, pid) {
|
|
101
|
+
try {
|
|
102
|
+
const st = io.fs.statSync(`/proc/${pid}`);
|
|
103
|
+
return typeof st.uid === 'number' ? st.uid : null;
|
|
104
|
+
} catch (_) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* PIDs of ComfyUI processes running from `root` (cwd check via /proc), by
|
|
111
|
+
* default on `port`. The cwd check means the installer only ever touches an
|
|
112
|
+
* instance it manages — a foreign ComfyUI (different root) is never signaled.
|
|
113
|
+
*/
|
|
114
|
+
function findComfyUIPids(io, { root, port = null }) {
|
|
115
|
+
const out = [];
|
|
116
|
+
let dirs = [];
|
|
117
|
+
try { dirs = io.fs.readdirSync('/proc').filter((n) => /^\d+$/.test(n)); } catch (_) { return out; }
|
|
118
|
+
for (const dir of dirs) {
|
|
119
|
+
const pid = Number(dir);
|
|
120
|
+
if (!Number.isFinite(pid) || pid === process.pid) continue;
|
|
121
|
+
const parts = readProcessCmdline(io, pid);
|
|
122
|
+
if (!parts || !parts.some((a) => a === 'main.py' || a.endsWith('/main.py'))) continue;
|
|
123
|
+
if (port != null) {
|
|
124
|
+
const portIdx = parts.indexOf('--port');
|
|
125
|
+
const procPort = portIdx !== -1 ? Number(parts[portIdx + 1]) : 8188;
|
|
126
|
+
if (procPort !== Number(port)) continue;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
if (io.fs.readlinkSync(`/proc/${pid}/cwd`) !== root) continue;
|
|
130
|
+
} catch (_) { continue; } // foreign process or already gone
|
|
131
|
+
out.push(pid);
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Scan /proc for processes whose cwd is inside any of `paths` (prefix match).
|
|
138
|
+
* Used by the uninstaller to find components of THIS installation.
|
|
139
|
+
* Implemented as a single sh -c loop (the historical implementation) so the
|
|
140
|
+
* mocked-exec tests keep working.
|
|
141
|
+
*/
|
|
142
|
+
function findPidsByCwdPrefix(io, paths) {
|
|
143
|
+
const shQuote = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
|
|
144
|
+
const script = 'for p in /proc/[0-9]*; do '
|
|
145
|
+
+ 'cwd=$(readlink "$p/cwd" 2>/dev/null) || continue; '
|
|
146
|
+
+ `case "$cwd" in ${paths.map((p) => `${shQuote(p)}*`).join('| ')}) echo "\${p#/proc/}";; esac; done`;
|
|
147
|
+
const r = io.exec('sh', ['-c', script]);
|
|
148
|
+
if (!r || r.code !== 0 || !r.stdout) return [];
|
|
149
|
+
return String(r.stdout).split('\n').map((l) => Number(l.trim())).filter((n) => Number.isFinite(n) && n > 0);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// Shell command fragments (start/grace/alive/kill)
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
/** Grace sleep: POSIX sleep(1). Returns { cmd, args } for io.exec. */
|
|
157
|
+
function sleepCommand(seconds) {
|
|
158
|
+
return { cmd: 'sleep', args: [String(Math.max(1, Math.ceil(seconds)))] };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Kill a pid: POSIX kill(1). */
|
|
162
|
+
function killCommand(pid) {
|
|
163
|
+
return { cmd: 'kill', args: [String(pid)] };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Liveness check returning the process args (worker.cjs marker match). */
|
|
167
|
+
function psCheckCommand(pid) {
|
|
168
|
+
return { cmd: 'ps', args: ['-p', String(pid), '-o', 'args='] };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ---------------------------------------------------------------------------
|
|
172
|
+
// Host prerequisites / remediation
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
|
|
175
|
+
/** Debian/Ubuntu apt remediation for a host package. */
|
|
176
|
+
function hostPackageCommand(pkg) {
|
|
177
|
+
return `sudo apt install ${pkg}`;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Debian/Ubuntu apt remediation for several host packages. */
|
|
181
|
+
function hostPackagesCommand(pkgs) {
|
|
182
|
+
return `sudo apt-get install -y ${pkgs}`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* C build-tool prerequisites (native Python extensions). Debian/Ubuntu
|
|
187
|
+
* package names — a Linux-specific concern, so it lives in this adapter.
|
|
188
|
+
*/
|
|
189
|
+
function checkBuildPrerequisites(io, { python = 'python3', log = null } = {}) {
|
|
190
|
+
const missing = [];
|
|
191
|
+
const versionRes = io.exec(python, ['--version']);
|
|
192
|
+
const vMatch = /Python\s+([0-9][0-9.]*)/.exec(String(versionRes.stdout) + String(versionRes.stderr));
|
|
193
|
+
const pyVer = vMatch ? vMatch[1] : null;
|
|
194
|
+
const pyMajor = pyVer ? pyVer.split('.').slice(0, 2).join('.') : null;
|
|
195
|
+
|
|
196
|
+
const gcc = io.exec('gcc', ['--version']);
|
|
197
|
+
if (gcc.code !== 0) missing.push({ pkg: 'build-essential', check: 'gcc --version' });
|
|
198
|
+
|
|
199
|
+
const devPkg = pyMajor ? `python${pyMajor}-dev` : 'python3-dev';
|
|
200
|
+
const devCheck = io.exec(python, ['-c', 'import sysconfig; print(sysconfig.get_path("include"))']);
|
|
201
|
+
if (devCheck.code !== 0 || !String(devCheck.stdout).trim()) {
|
|
202
|
+
missing.push({ pkg: devPkg, check: `${python} -c "import sysconfig; print(sysconfig.get_path('include'))"` });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const sndfile = io.exec('pkg-config', ['--exists', 'sndfile']);
|
|
206
|
+
if (sndfile.code !== 0) missing.push({ pkg: 'libsndfile1-dev', check: 'pkg-config --exists sndfile' });
|
|
207
|
+
|
|
208
|
+
if (missing.length === 0) return { ok: true, missing: [] };
|
|
209
|
+
|
|
210
|
+
const pkgList = missing.map((m) => m.pkg).join(' ');
|
|
211
|
+
const cmd = hostPackagesCommand(pkgList);
|
|
212
|
+
const msg = `Missing C build tools required by Python packages with native extensions: ${missing.map((m) => m.pkg).join(', ')}. `
|
|
213
|
+
+ `Run: ${cmd}`;
|
|
214
|
+
if (log) log.warn(msg);
|
|
215
|
+
return { ok: false, missing, remediation: { package: pkgList, command: cmd }, message: msg };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ---------------------------------------------------------------------------
|
|
219
|
+
// Management tools (POSIX shell wrappers)
|
|
220
|
+
// ---------------------------------------------------------------------------
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Tool script filename: identity on Linux — the canonical names are the
|
|
224
|
+
* historical POSIX shell names (status.sh, reboot-worker.sh, …).
|
|
225
|
+
*/
|
|
226
|
+
function toolScriptName(fileName) {
|
|
227
|
+
return fileName;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function shQuote(s) {
|
|
231
|
+
return `'${String(s).replace(/'/g, `'\\''`)}'`;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Render one management-tool wrapper (#!/bin/sh shim around the CLI). */
|
|
235
|
+
function renderToolScript({ command, nodePath, cliPath, statePath, root, workerDir }) {
|
|
236
|
+
return [
|
|
237
|
+
'#!/bin/sh',
|
|
238
|
+
'# Animastor management tool — generated by animastor-installer.',
|
|
239
|
+
'# Do not edit: re-run the installer to refresh (paths are recorded at install time).',
|
|
240
|
+
`exec ${shQuote(nodePath)} ${shQuote(cliPath)} ${command} \\`,
|
|
241
|
+
` --state ${shQuote(statePath)} \\`,
|
|
242
|
+
` --root ${shQuote(root || '')} \\`,
|
|
243
|
+
` --worker-dir ${shQuote(workerDir || '')} "$@"`,
|
|
244
|
+
'',
|
|
245
|
+
].join('\n');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Mode bits applied to generated tool scripts. */
|
|
249
|
+
const TOOL_SCRIPT_MODE = 0o755;
|
|
250
|
+
|
|
251
|
+
// ---------------------------------------------------------------------------
|
|
252
|
+
// GPU probing (platform-specific parts)
|
|
253
|
+
// ---------------------------------------------------------------------------
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* AMD GPU detection with positive evidence only (Linux paths):
|
|
257
|
+
* 1. rocm-smi runtime (Card series: …), or
|
|
258
|
+
* 2. kernel drm sysfs vendor 0x1002 (amdgpu), name via lspci when available.
|
|
259
|
+
* Empty/unknown output is treated as "not detected" — never guessed.
|
|
260
|
+
*/
|
|
261
|
+
function probeAmdGpu(io) {
|
|
262
|
+
const rocm = io.exec('rocm-smi', ['--showproductname']);
|
|
263
|
+
if (rocm.code === 0) {
|
|
264
|
+
const m = /Card series:\s*(.+)/.exec(rocm.stdout);
|
|
265
|
+
if (m && m[1].trim()) {
|
|
266
|
+
return { vendor: 'amd', name: m[1].trim(), vram_mib: null, driver_version: null, detection: 'rocm-smi' };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
const drm = '/sys/class/drm';
|
|
271
|
+
if (io.fs.isDirectory(drm)) {
|
|
272
|
+
for (const entry of io.fs.readdirSync(drm)) {
|
|
273
|
+
if (!/^card\d+$/.test(entry)) continue;
|
|
274
|
+
const vendorPath = `${drm}/${entry}/device/vendor`;
|
|
275
|
+
if (!io.fs.existsSync(vendorPath)) continue;
|
|
276
|
+
const vendor = String(io.fs.readFileSync(vendorPath, 'utf8')).trim().toLowerCase();
|
|
277
|
+
if (vendor !== '0x1002') continue;
|
|
278
|
+
let name = null;
|
|
279
|
+
const productPath = `${drm}/${entry}/device/product_name`;
|
|
280
|
+
if (io.fs.existsSync(productPath)) {
|
|
281
|
+
name = String(io.fs.readFileSync(productPath, 'utf8')).trim() || null;
|
|
282
|
+
}
|
|
283
|
+
if (!name) {
|
|
284
|
+
const lspci = io.exec('lspci', []);
|
|
285
|
+
if (lspci.code === 0) {
|
|
286
|
+
const m = /VGA compatible controller[^\n]*\[AMD\/ATI\][^\n]*/.exec(lspci.stdout)
|
|
287
|
+
|| /Display controller[^\n]*\[AMD\/ATI\][^\n]*/.exec(lspci.stdout);
|
|
288
|
+
if (m) {
|
|
289
|
+
const chip = m[0].split(':').slice(2).join(':').trim();
|
|
290
|
+
if (chip) name = chip;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return { vendor: 'amd', name: name || 'AMD GPU', vram_mib: null, driver_version: null, detection: 'sysfs-vendor' };
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
} catch (_) { /* sysfs unavailable — not detected */ }
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// ---------------------------------------------------------------------------
|
|
302
|
+
// Ownership guard
|
|
303
|
+
// ---------------------------------------------------------------------------
|
|
304
|
+
|
|
305
|
+
/** Uid guard is meaningful on Linux (shared hosts, sudo mixing). */
|
|
306
|
+
const UID_GUARD = true;
|
|
307
|
+
|
|
308
|
+
module.exports = {
|
|
309
|
+
name: NAME,
|
|
310
|
+
displayName: 'Linux (native)',
|
|
311
|
+
productionReady: true,
|
|
312
|
+
|
|
313
|
+
HOME_ENV,
|
|
314
|
+
UID_GUARD,
|
|
315
|
+
TOOL_SCRIPT_MODE,
|
|
316
|
+
|
|
317
|
+
defaultRoot,
|
|
318
|
+
defaultWorkerDir,
|
|
319
|
+
venvPythonBin,
|
|
320
|
+
|
|
321
|
+
findPidsByCmdlineAndCwd,
|
|
322
|
+
readProcessCwd,
|
|
323
|
+
readProcessCmdline,
|
|
324
|
+
processStartMs,
|
|
325
|
+
pidUid,
|
|
326
|
+
findComfyUIPids,
|
|
327
|
+
findPidsByCwdPrefix,
|
|
328
|
+
|
|
329
|
+
sleepCommand,
|
|
330
|
+
killCommand,
|
|
331
|
+
psCheckCommand,
|
|
332
|
+
|
|
333
|
+
hostPackageCommand,
|
|
334
|
+
hostPackagesCommand,
|
|
335
|
+
checkBuildPrerequisites,
|
|
336
|
+
|
|
337
|
+
toolScriptName,
|
|
338
|
+
renderToolScript,
|
|
339
|
+
|
|
340
|
+
probeAmdGpu,
|
|
341
|
+
};
|