@camunda8/cli 4.7.0-alpha.4 → 4.7.0-alpha.40
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/CONTEXT.md +12 -0
- package/PLUGIN-HELP.md +1 -1
- package/README.md +8 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +2 -2
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/helpers/deploy-helpers.d.ts +13 -0
- package/dist/commands/helpers/deploy-helpers.d.ts.map +1 -1
- package/dist/commands/helpers/deploy-helpers.js +9 -5
- package/dist/commands/helpers/deploy-helpers.js.map +1 -1
- package/dist/commands/mcp-proxy.d.ts.map +1 -1
- package/dist/commands/mcp-proxy.js +13 -8
- package/dist/commands/mcp-proxy.js.map +1 -1
- package/dist/commands/profiles.d.ts.map +1 -1
- package/dist/commands/profiles.js +13 -7
- package/dist/commands/profiles.js.map +1 -1
- package/dist/commands/run.d.ts.map +1 -1
- package/dist/commands/run.js +1 -8
- package/dist/commands/run.js.map +1 -1
- package/dist/commands/watch.d.ts.map +1 -1
- package/dist/commands/watch.js +10 -2
- package/dist/commands/watch.js.map +1 -1
- package/dist/core/client.d.ts +13 -0
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +48 -21
- package/dist/core/client.js.map +1 -1
- package/dist/core/config.d.ts +34 -3
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +91 -9
- package/dist/core/config.js.map +1 -1
- package/dist/core/env-address.d.ts +22 -0
- package/dist/core/env-address.d.ts.map +1 -0
- package/dist/core/env-address.js +30 -0
- package/dist/core/env-address.js.map +1 -0
- package/dist/core/errors.d.ts +17 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +32 -0
- package/dist/core/errors.js.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +2 -1
- package/dist/core/logger.js.map +1 -1
- package/dist/core/node-version.d.ts +18 -0
- package/dist/core/node-version.d.ts.map +1 -0
- package/dist/core/node-version.js +38 -0
- package/dist/core/node-version.js.map +1 -0
- package/dist/default-plugins/cluster/README.md +16 -1
- package/dist/default-plugins/cluster/c8ctl-plugin.js +742 -114
- package/dist/default-plugins/element-template/c8ctl-plugin.js +248 -7
- package/dist/default-plugins/mcp/README.md +37 -0
- package/dist/default-plugins/mcp/c8ctl-plugin.js +4973 -0
- package/dist/default-plugins/mcp/package.json +8 -0
- package/dist/default-plugins/modeler/README.md +23 -0
- package/dist/default-plugins/modeler/c8ctl-plugin.js +4314 -0
- package/dist/default-plugins/modeler/package.json +8 -0
- package/dist/default-plugins/setup/README.md +42 -0
- package/dist/default-plugins/setup/c8ctl-plugin.js +6845 -0
- package/dist/default-plugins/setup/package.json +8 -0
- package/dist/default-plugins/skills/README.md +35 -0
- package/dist/default-plugins/skills/c8ctl-plugin.js +3369 -0
- package/dist/default-plugins/skills/package.json +8 -0
- package/dist/framework/argv-parser.d.ts +14 -0
- package/dist/framework/argv-parser.d.ts.map +1 -1
- package/dist/framework/argv-parser.js +25 -0
- package/dist/framework/argv-parser.js.map +1 -1
- package/dist/framework/command-registry.d.ts +28 -2
- package/dist/framework/command-registry.d.ts.map +1 -1
- package/dist/framework/command-registry.js +47 -2
- package/dist/framework/command-registry.js.map +1 -1
- package/dist/framework/plugins/plugin-loader.d.ts +20 -2
- package/dist/framework/plugins/plugin-loader.d.ts.map +1 -1
- package/dist/framework/plugins/plugin-loader.js.map +1 -1
- package/dist/framework/ui/help.d.ts.map +1 -1
- package/dist/framework/ui/help.js +57 -14
- package/dist/framework/ui/help.js.map +1 -1
- package/dist/framework/ui/prompt.d.ts +88 -0
- package/dist/framework/ui/prompt.d.ts.map +1 -1
- package/dist/framework/ui/prompt.js +558 -20
- package/dist/framework/ui/prompt.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -12
- package/dist/index.js.map +1 -1
- package/dist/utils/command-local/mcp-install-helpers.d.ts +68 -0
- package/dist/utils/command-local/mcp-install-helpers.d.ts.map +1 -0
- package/dist/utils/command-local/mcp-install-helpers.js +485 -0
- package/dist/utils/command-local/mcp-install-helpers.js.map +1 -0
- package/dist/utils/command-local/process-instance-helpers.d.ts +6 -0
- package/dist/utils/command-local/process-instance-helpers.d.ts.map +1 -1
- package/dist/utils/command-local/process-instance-helpers.js +9 -0
- package/dist/utils/command-local/process-instance-helpers.js.map +1 -1
- package/dist/utils/command-local/skills-install-helpers.d.ts +49 -0
- package/dist/utils/command-local/skills-install-helpers.d.ts.map +1 -0
- package/dist/utils/command-local/skills-install-helpers.js +436 -0
- package/dist/utils/command-local/skills-install-helpers.js.map +1 -0
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/shared/camunda-json.d.ts +16 -3
- package/dist/utils/shared/camunda-json.d.ts.map +1 -1
- package/dist/utils/shared/camunda-json.js +20 -5
- package/dist/utils/shared/camunda-json.js.map +1 -1
- package/dist/utils/shared/deploy-resource-selection.d.ts +7 -15
- package/dist/utils/shared/deploy-resource-selection.d.ts.map +1 -1
- package/dist/utils/shared/deploy-resource-selection.js +9 -19
- package/dist/utils/shared/deploy-resource-selection.js.map +1 -1
- package/dist/utils/shared/ignore.d.ts +6 -0
- package/dist/utils/shared/ignore.d.ts.map +1 -1
- package/dist/utils/shared/ignore.js +9 -1
- package/dist/utils/shared/ignore.js.map +1 -1
- package/package.json +3 -2
- package/dist/utils/command-local/setup-detectors.d.ts +0 -51
- package/dist/utils/command-local/setup-detectors.d.ts.map +0 -1
- package/dist/utils/command-local/setup-detectors.js +0 -115
- package/dist/utils/command-local/setup-detectors.js.map +0 -1
- package/dist/utils/command-local/setup-prerequisites.d.ts +0 -67
- package/dist/utils/command-local/setup-prerequisites.d.ts.map +0 -1
- package/dist/utils/command-local/setup-prerequisites.js +0 -238
- package/dist/utils/command-local/setup-prerequisites.js.map +0 -1
|
@@ -10,21 +10,26 @@
|
|
|
10
10
|
|
|
11
11
|
import { spawn, execFileSync } from 'node:child_process';
|
|
12
12
|
import {
|
|
13
|
+
closeSync,
|
|
13
14
|
createWriteStream,
|
|
14
15
|
existsSync,
|
|
16
|
+
fstatSync,
|
|
15
17
|
mkdirSync,
|
|
18
|
+
openSync,
|
|
16
19
|
writeFileSync,
|
|
17
20
|
renameSync,
|
|
18
21
|
rmSync,
|
|
19
22
|
readdirSync,
|
|
20
23
|
readFileSync,
|
|
24
|
+
readSync,
|
|
21
25
|
statSync,
|
|
22
26
|
} from 'node:fs';
|
|
23
27
|
import { once } from 'node:events';
|
|
24
28
|
import { chmod } from 'node:fs/promises';
|
|
25
|
-
import { homedir, platform as osPlatform, arch as osArch } from 'node:os';
|
|
26
|
-
import { join, dirname, isAbsolute, resolve } from 'node:path';
|
|
29
|
+
import { homedir, platform as osPlatform, arch as osArch, constants as osConstants } from 'node:os';
|
|
30
|
+
import { join, dirname, basename, isAbsolute, relative, resolve } from 'node:path';
|
|
27
31
|
import { finished } from 'node:stream/promises';
|
|
32
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
28
33
|
import { fileURLToPath } from 'node:url';
|
|
29
34
|
|
|
30
35
|
// ---------------------------------------------------------------------------
|
|
@@ -210,37 +215,145 @@ function readLocalAliasMapping(cacheDir, alias) {
|
|
|
210
215
|
const filePath = getAliasMappingPath(cacheDir, alias);
|
|
211
216
|
if (!existsSync(filePath)) return null;
|
|
212
217
|
try {
|
|
213
|
-
const value = readFileSync(filePath, 'utf-8').trim();
|
|
214
218
|
// Only use the cached mapping if the version is actually installed
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
219
|
+
return findInstalledAliasTarget(cacheDir, readFileSync(filePath, 'utf-8').trim(), alias);
|
|
220
|
+
} catch {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Return the installed version that satisfies an alias target, or null.
|
|
227
|
+
* An exact install wins; for a rolling minor pattern ("8.9") the highest
|
|
228
|
+
* installed pin in that minor line ("8.9.5") also counts, so a compatible
|
|
229
|
+
* pinned install is not re-downloaded (#431). For `stable`, an install whose
|
|
230
|
+
* build is a prerelease never counts — whether pinned ("c8run-8.10.0-alpha1")
|
|
231
|
+
* or a rolling dir that still holds an alpha build ("c8run-8.10/c8run-8.10.0-alpha1").
|
|
232
|
+
*/
|
|
233
|
+
function findInstalledAliasTarget(cacheDir, value, alias) {
|
|
234
|
+
const accepts = (version) => {
|
|
235
|
+
const build = installedBuildName(cacheDir, version);
|
|
236
|
+
if (!build) return false;
|
|
237
|
+
return alias !== 'stable' || !isPrereleaseBuild(build);
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
if (accepts(value)) return value;
|
|
241
|
+
|
|
242
|
+
if (isMinorVersionPattern(value)) {
|
|
243
|
+
const installedVersions = getInstalledVersionsList(cacheDir)
|
|
244
|
+
.sort((a, b) => a.localeCompare(b, undefined, { numeric: true }));
|
|
245
|
+
const match = installedVersions
|
|
246
|
+
.filter((v) => v.startsWith(value + '.'))
|
|
247
|
+
.reverse()
|
|
248
|
+
.find(accepts);
|
|
249
|
+
if (match) return match;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** True for a build dir like "c8run-8.10.0-alpha1" (anything with a semver prerelease suffix). */
|
|
256
|
+
function isPrereleaseBuild(buildDirName) {
|
|
257
|
+
return /^c8run-\d+\.\d+(\.\d+)?-/.test(buildDirName);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Every cluster data dir in an install: `camunda-data` and the `data` dir
|
|
262
|
+
* inside each `camunda-zeebe-` dir, beside any launcher in the install dir
|
|
263
|
+
* or one of its immediate subdirs (older builds of a rolling install, or an
|
|
264
|
+
* install that lost its launcher). `cluster purge` deletes exactly these, and
|
|
265
|
+
* `stable` refuses to replace an install that still has any.
|
|
266
|
+
*/
|
|
267
|
+
function findClusterDataDirs(installDir) {
|
|
268
|
+
const listDirs = (dir) => {
|
|
269
|
+
try {
|
|
270
|
+
return readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory());
|
|
271
|
+
} catch {
|
|
272
|
+
return [];
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
const roots = [installDir, ...listDirs(installDir).map((entry) => join(installDir, entry.name))];
|
|
276
|
+
const found = [];
|
|
277
|
+
for (const root of roots) {
|
|
278
|
+
const camundaData = join(root, 'camunda-data');
|
|
279
|
+
if (existsSync(camundaData)) found.push(camundaData);
|
|
280
|
+
for (const entry of listDirs(root)) {
|
|
281
|
+
const journal = join(root, entry.name, 'data');
|
|
282
|
+
if (entry.name.startsWith('camunda-zeebe-') && existsSync(journal)) found.push(journal);
|
|
230
283
|
}
|
|
284
|
+
}
|
|
285
|
+
return found;
|
|
286
|
+
}
|
|
231
287
|
|
|
232
|
-
|
|
288
|
+
/**
|
|
289
|
+
* Refuse to replace a `stable` install whose cluster data would be deleted:
|
|
290
|
+
* a prerelease build, or an install that lost its launcher. Data may sit
|
|
291
|
+
* beside the launcher or, without one, in the install dir or a subdir of it.
|
|
292
|
+
* A GA build is replaced like any rolling update.
|
|
293
|
+
*/
|
|
294
|
+
function refuseIfClusterDataAtRisk(config) {
|
|
295
|
+
const version = config.version;
|
|
296
|
+
const installDir = join(config.cacheDir, `c8run-${version}`);
|
|
297
|
+
if (!existsSync(installDir)) return;
|
|
298
|
+
const build = installedBuildName(config.cacheDir, version);
|
|
299
|
+
if (build && !isPrereleaseBuild(build)) return;
|
|
300
|
+
|
|
301
|
+
if (findClusterDataDirs(installDir).length === 0) return;
|
|
302
|
+
|
|
303
|
+
const state = build
|
|
304
|
+
? `holds a prerelease build (${build.slice('c8run-'.length)}) with cluster data`
|
|
305
|
+
: 'has cluster data but no c8run launcher';
|
|
306
|
+
const options = build
|
|
307
|
+
? `Keep using it with "c8ctl cluster start ${version}", or delete its data with`
|
|
308
|
+
: 'Delete its data with';
|
|
309
|
+
throw new Error(
|
|
310
|
+
`c8run ${version} ${state}. "stable" needs a GA build, and replacing this install would delete that data. ` +
|
|
311
|
+
`${options} "c8ctl cluster purge ${version}" and run this command again.`,
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Name of the build dir whose c8run would launch for `version` (e.g. "c8run-8.10.0-alpha1"), or null. */
|
|
316
|
+
function installedBuildName(cacheDir, version) {
|
|
317
|
+
const binaryPath = findC8RunBinaryPath({ cacheDir, version });
|
|
318
|
+
return binaryPath ? basename(dirname(binaryPath)) : null;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** The prerelease build installed for `version`, or null when none is installed or it is GA. */
|
|
322
|
+
function installedPrereleaseBuild(cacheDir, version) {
|
|
323
|
+
const build = installedBuildName(cacheDir, version);
|
|
324
|
+
return build && isPrereleaseBuild(build) ? build : null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Explain why `stable` has no usable local install when the version it would
|
|
329
|
+
* resolve to only holds a prerelease build — either `version` itself or the
|
|
330
|
+
* cached `stable` mapping (which resolution skips for that reason). Null otherwise.
|
|
331
|
+
*/
|
|
332
|
+
function describePrereleaseOnlyStable(cacheDir, version) {
|
|
333
|
+
let cached = null;
|
|
334
|
+
try {
|
|
335
|
+
cached = readFileSync(getAliasMappingPath(cacheDir, 'stable'), 'utf-8').trim();
|
|
233
336
|
} catch {
|
|
234
|
-
|
|
337
|
+
// No cached mapping
|
|
235
338
|
}
|
|
339
|
+
for (const candidate of [version, cached]) {
|
|
340
|
+
const build = candidate && installedPrereleaseBuild(cacheDir, candidate);
|
|
341
|
+
if (build) {
|
|
342
|
+
return `Only a prerelease build of ${candidate} is installed (${build.slice('c8run-'.length)}); "stable" needs a GA build.`;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
236
346
|
}
|
|
237
347
|
|
|
348
|
+
/** Persist an alias mapping. Returns false if it could not be written. */
|
|
238
349
|
export function storeLocalAliasMapping(cacheDir, alias, resolved) {
|
|
239
350
|
try {
|
|
240
351
|
mkdirSync(cacheDir, { recursive: true });
|
|
241
352
|
writeFileSync(getAliasMappingPath(cacheDir, alias), resolved);
|
|
353
|
+
return true;
|
|
242
354
|
} catch {
|
|
243
355
|
// Best-effort — don't break the command if we can't persist
|
|
356
|
+
return false;
|
|
244
357
|
}
|
|
245
358
|
}
|
|
246
359
|
|
|
@@ -265,16 +378,21 @@ export function _resetDynamicAliasCache() {
|
|
|
265
378
|
}
|
|
266
379
|
|
|
267
380
|
/**
|
|
268
|
-
* Non-blocking background check: query the remote download server and
|
|
269
|
-
*
|
|
381
|
+
* Non-blocking background check: query the remote download server and act
|
|
382
|
+
* if the remote alias resolves to a newer minor than the one being started.
|
|
383
|
+
*
|
|
384
|
+
* - Newer version already installed (e.g. via `cluster install 8.10`): the
|
|
385
|
+
* persisted alias mapping is advanced to it, so the *next* `start` uses it.
|
|
386
|
+
* Nothing is downloaded — the user already chose to install that version.
|
|
387
|
+
* - Newer version not installed: only a hint is printed; the mapping is left
|
|
388
|
+
* alone so `start` never silently switches to a version it would have to
|
|
389
|
+
* download.
|
|
270
390
|
*
|
|
271
|
-
*
|
|
272
|
-
* updated when the user explicitly runs `cluster install`, keeping `start`
|
|
273
|
-
* deterministic across runs.
|
|
391
|
+
* The current run is never affected: it has already resolved its version.
|
|
274
392
|
*
|
|
275
393
|
* Returns the fire-and-forget promise (for testing).
|
|
276
394
|
*/
|
|
277
|
-
export function checkBackgroundAliasFreshness(versionSpec, resolvedVersion) {
|
|
395
|
+
export function checkBackgroundAliasFreshness(versionSpec, resolvedVersion, cacheDir) {
|
|
278
396
|
const logger = getLogger();
|
|
279
397
|
const controller = new AbortController();
|
|
280
398
|
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
@@ -285,7 +403,22 @@ export function checkBackgroundAliasFreshness(versionSpec, resolvedVersion) {
|
|
|
285
403
|
if (html) {
|
|
286
404
|
const remote = parseVersionsFromHtml(html);
|
|
287
405
|
const remoteVersion = remote?.[versionSpec];
|
|
288
|
-
if (remoteVersion
|
|
406
|
+
if (!remoteVersion || !isRemoteMinorNewer(remoteVersion, resolvedVersion)) return;
|
|
407
|
+
const installed = cacheDir && findInstalledAliasTarget(cacheDir, remoteVersion, versionSpec);
|
|
408
|
+
if (installed) {
|
|
409
|
+
if (storeLocalAliasMapping(cacheDir, versionSpec, remoteVersion)) {
|
|
410
|
+
logger.info(
|
|
411
|
+
`"${versionSpec}" now resolves to ${remoteVersion}, which is already installed. ` +
|
|
412
|
+
`The next "c8ctl cluster start ${versionSpec}" will use it.`,
|
|
413
|
+
);
|
|
414
|
+
} else {
|
|
415
|
+
// Name the exact install: a plain "8.10" would look for c8run-8.10 and download it.
|
|
416
|
+
logger.info(
|
|
417
|
+
`"${versionSpec}" now resolves to ${remoteVersion}, which is already installed, ` +
|
|
418
|
+
`but the cached alias could not be updated. Start it with: c8ctl cluster start ${installed}`,
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
} else {
|
|
289
422
|
logger.info(
|
|
290
423
|
`A newer "${versionSpec}" release is available (${remoteVersion}). ` +
|
|
291
424
|
`Install it with: c8ctl cluster install ${versionSpec}`,
|
|
@@ -310,6 +443,25 @@ function fireAndForget(promise) {
|
|
|
310
443
|
return promise.catch(() => {});
|
|
311
444
|
}
|
|
312
445
|
|
|
446
|
+
/**
|
|
447
|
+
* Give the background `start` hints (alias freshness, rolling update) a short,
|
|
448
|
+
* bounded chance to print before a failed start calls process.exit(), which
|
|
449
|
+
* would otherwise drop them mid-flight. A failed start is when a newer version
|
|
450
|
+
* is most worth knowing about.
|
|
451
|
+
*/
|
|
452
|
+
export async function flushStartHints(config, timeoutMs = 1000) {
|
|
453
|
+
const pending = [config?._aliasHintPromise, config?._hintPromise].filter(Boolean);
|
|
454
|
+
if (pending.length === 0) return;
|
|
455
|
+
let timer;
|
|
456
|
+
await Promise.race([
|
|
457
|
+
Promise.all(pending),
|
|
458
|
+
new Promise((resolve) => {
|
|
459
|
+
timer = setTimeout(resolve, timeoutMs);
|
|
460
|
+
}),
|
|
461
|
+
]);
|
|
462
|
+
clearTimeout(timer);
|
|
463
|
+
}
|
|
464
|
+
|
|
313
465
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
314
466
|
|
|
315
467
|
// ---------------------------------------------------------------------------
|
|
@@ -334,12 +486,13 @@ export const metadata = {
|
|
|
334
486
|
// so the subcommand flags are documented via `flagsHint` instead.
|
|
335
487
|
passthrough: true,
|
|
336
488
|
passthroughHint:
|
|
337
|
-
'--purge, --debug, --physical-tenants and --c8-version are read by the plugin. For local management, physical-tenants and --physical-tenant are forwarded unchanged to a compatible c8run release.',
|
|
489
|
+
'--purge, --debug, --port, --physical-tenants and --c8-version are read by the plugin. For local management, physical-tenants and --physical-tenant are forwarded unchanged to a compatible c8run release.',
|
|
338
490
|
flagsHint: [
|
|
339
491
|
'--c8-version <version> Camunda version, alias or major.minor (alternative to the positional <version>)',
|
|
340
492
|
'--debug (start, stop) Stream raw c8run output',
|
|
341
493
|
'--purge (stop only) Also delete runtime data after stopping',
|
|
342
494
|
'--physical-tenants <ids> (start only) Comma-separated physical tenants for this run (repeatable; Camunda 8.10+)',
|
|
495
|
+
'--port <number> (start only) Main Camunda HTTP port (default 8080; gRPC 26500 and health 9600 stay fixed)',
|
|
343
496
|
'--physical-tenant <id> (secrets only) Scope secrets to one physical tenant (also --physical-tenant=<id>)',
|
|
344
497
|
],
|
|
345
498
|
subcommands: [
|
|
@@ -360,6 +513,7 @@ export const metadata = {
|
|
|
360
513
|
{ command: 'c8ctl cluster start', description: 'Start a local Camunda 8 cluster (latest stable)' },
|
|
361
514
|
{ command: 'c8ctl cluster start 8.8', description: 'Start the latest cached 8.8.x release' },
|
|
362
515
|
{ command: 'c8ctl cluster start 8.9.0-alpha5', description: 'Start a specific version' },
|
|
516
|
+
{ command: 'c8ctl cluster start --port 9091', description: 'Start a local cluster serving HTTP on port 9091' },
|
|
363
517
|
{ command: 'c8ctl cluster stop', description: 'Stop the running cluster' },
|
|
364
518
|
{ command: 'c8ctl cluster status', description: 'Show whether a cluster is running and how to connect' },
|
|
365
519
|
{ command: 'c8ctl cluster logs', description: 'Stream log output from the running cluster' },
|
|
@@ -404,6 +558,8 @@ function getLogger() {
|
|
|
404
558
|
|
|
405
559
|
const ACTIVE_MARKER_FILE = 'cluster.active';
|
|
406
560
|
const VERSION_MARKER_FILE = 'cluster.version';
|
|
561
|
+
const PORT_MARKER_FILE = 'cluster.port';
|
|
562
|
+
const DEFAULT_HTTP_PORT = 8080;
|
|
407
563
|
// Durable running-cluster PID record, written at start time. Unlike c8run's
|
|
408
564
|
// own `.process` pidfiles — which live INSIDE a version's install dir and
|
|
409
565
|
// vanish when that dir is replaced or removed — this record lives at the
|
|
@@ -1276,7 +1432,11 @@ async function downloadC8Run(config) {
|
|
|
1276
1432
|
return { archivePath: targetFile, etag: result.etag };
|
|
1277
1433
|
}
|
|
1278
1434
|
|
|
1279
|
-
|
|
1435
|
+
// How long an aborted extractor gets to exit before it is killed outright.
|
|
1436
|
+
const EXTRACTOR_KILL_GRACE_MS = 3000;
|
|
1437
|
+
|
|
1438
|
+
/** Aborting `abortSignal` terminates the extractor; the promise settles once it has exited. */
|
|
1439
|
+
async function extractArchive(archivePath, targetDir, { abortSignal } = {}) {
|
|
1280
1440
|
const logger = getLogger();
|
|
1281
1441
|
logger.info(`Extracting to ${targetDir}...`);
|
|
1282
1442
|
|
|
@@ -1290,6 +1450,17 @@ async function extractArchive(archivePath, targetDir) {
|
|
|
1290
1450
|
|
|
1291
1451
|
return new Promise((resolve, reject) => {
|
|
1292
1452
|
const proc = spawn(command, args, { stdio: 'inherit' });
|
|
1453
|
+
let killTimer;
|
|
1454
|
+
const terminate = () => {
|
|
1455
|
+
proc.kill('SIGTERM');
|
|
1456
|
+
killTimer = setTimeout(() => proc.kill('SIGKILL'), EXTRACTOR_KILL_GRACE_MS);
|
|
1457
|
+
};
|
|
1458
|
+
if (abortSignal?.aborted) terminate();
|
|
1459
|
+
else abortSignal?.addEventListener('abort', terminate, { once: true });
|
|
1460
|
+
proc.on('close', () => {
|
|
1461
|
+
clearTimeout(killTimer);
|
|
1462
|
+
abortSignal?.removeEventListener('abort', terminate);
|
|
1463
|
+
});
|
|
1293
1464
|
proc.on('exit', (code, signal) => {
|
|
1294
1465
|
if (code === 0) {
|
|
1295
1466
|
logger.info('Extraction complete.');
|
|
@@ -1491,7 +1662,18 @@ export async function hasNewerVersionAvailable(config) {
|
|
|
1491
1662
|
export async function ensureC8RunInstalled(config) {
|
|
1492
1663
|
const logger = getLogger();
|
|
1493
1664
|
|
|
1494
|
-
|
|
1665
|
+
// `stable` must never launch a prerelease, e.g. a rolling dir still holding
|
|
1666
|
+
// the alpha build installed through `alpha` before that minor went GA.
|
|
1667
|
+
const prereleaseBuild = config.requireGA ? installedPrereleaseBuild(config.cacheDir, config.version) : null;
|
|
1668
|
+
// Checked before downloading anything, and again right before the swap.
|
|
1669
|
+
if (config.requireGA) refuseIfClusterDataAtRisk(config);
|
|
1670
|
+
|
|
1671
|
+
if (prereleaseBuild) {
|
|
1672
|
+
logger.info(
|
|
1673
|
+
`c8run ${config.version} holds a prerelease build (${prereleaseBuild.slice('c8run-'.length)}); ` +
|
|
1674
|
+
'"stable" needs a GA build, so it will be replaced.',
|
|
1675
|
+
);
|
|
1676
|
+
} else if (isC8RunInstalled(config)) {
|
|
1495
1677
|
if (config.checkForUpdates) {
|
|
1496
1678
|
// Explicitly asked to check for updates (e.g. install subcommand with a rolling version)
|
|
1497
1679
|
const hasUpdate = await hasNewerVersionAvailable(config);
|
|
@@ -1509,7 +1691,9 @@ export async function ensureC8RunInstalled(config) {
|
|
|
1509
1691
|
'Stop it first with "c8ctl cluster stop", then re-run the install.',
|
|
1510
1692
|
);
|
|
1511
1693
|
}
|
|
1512
|
-
|
|
1694
|
+
// stable is replaced via a staged swap after the new build is validated,
|
|
1695
|
+
// so a rejected archive never leaves it without a usable install.
|
|
1696
|
+
if (!config.requireGA) purgeInstalledVersion(config);
|
|
1513
1697
|
} else {
|
|
1514
1698
|
// Use local installation as-is (start subcommand, or pinned version)
|
|
1515
1699
|
logger.info(`c8run ${config.version} is already installed.`);
|
|
@@ -1549,20 +1733,34 @@ export async function ensureC8RunInstalled(config) {
|
|
|
1549
1733
|
);
|
|
1550
1734
|
}
|
|
1551
1735
|
|
|
1552
|
-
logger.info('No local installation found. Setting up...');
|
|
1736
|
+
if (!isC8RunInstalled(config)) logger.info('No local installation found. Setting up...');
|
|
1553
1737
|
|
|
1554
|
-
|
|
1738
|
+
let download;
|
|
1739
|
+
try {
|
|
1740
|
+
download = await downloadC8Run(config);
|
|
1741
|
+
} catch (error) {
|
|
1742
|
+
const note = config.requireGA && describePrereleaseOnlyStable(config.cacheDir, config.version);
|
|
1743
|
+
if (note) throw new Error(`${note} ${error?.message ?? error}`, { cause: error?.cause });
|
|
1744
|
+
throw error;
|
|
1745
|
+
}
|
|
1746
|
+
const { archivePath, etag } = download;
|
|
1555
1747
|
|
|
1556
1748
|
const installDir = join(config.cacheDir, `c8run-${config.version}`);
|
|
1557
|
-
|
|
1749
|
+
|
|
1750
|
+
if (config.requireGA) {
|
|
1751
|
+
await installGABuild(config, archivePath, installDir);
|
|
1752
|
+
} else {
|
|
1753
|
+
await extractArchive(archivePath, installDir);
|
|
1754
|
+
}
|
|
1558
1755
|
|
|
1559
1756
|
// Clean up the downloaded archive to save disk space
|
|
1560
1757
|
if (existsSync(archivePath)) {
|
|
1561
1758
|
rmSync(archivePath);
|
|
1562
1759
|
}
|
|
1563
1760
|
|
|
1564
|
-
|
|
1565
|
-
|
|
1761
|
+
if (!config.requireGA) {
|
|
1762
|
+
await chmod(getC8RunBinaryPath(config), 0o755);
|
|
1763
|
+
}
|
|
1566
1764
|
|
|
1567
1765
|
// Store the ETag for rolling versions so future checks can detect new releases
|
|
1568
1766
|
if (config.isRolling && etag) {
|
|
@@ -1572,18 +1770,159 @@ export async function ensureC8RunInstalled(config) {
|
|
|
1572
1770
|
logger.info(`c8run ${config.version} installed successfully.`);
|
|
1573
1771
|
}
|
|
1574
1772
|
|
|
1773
|
+
/**
|
|
1774
|
+
* Install the archive for `stable` without ever leaving a prerelease or
|
|
1775
|
+
* nothing in place: extract into a staging dir, require a GA launcher there,
|
|
1776
|
+
* then swap it in. Any failure before the swap leaves the existing install
|
|
1777
|
+
* (e.g. a usable alpha build) untouched.
|
|
1778
|
+
*/
|
|
1779
|
+
async function installGABuild(config, archivePath, installDir) {
|
|
1780
|
+
const logger = getLogger();
|
|
1781
|
+
const stagingRoot = join(config.cacheDir, `.staging-c8run-${config.version}-${process.pid}`);
|
|
1782
|
+
const stagedDir = join(stagingRoot, `c8run-${config.version}`);
|
|
1783
|
+
// Dot-prefixed so neither dir is ever listed as an installed version ("c8run-*").
|
|
1784
|
+
const backupDir = join(config.cacheDir, `.replaced-c8run-${config.version}-${process.pid}`);
|
|
1785
|
+
// Leftovers of runs that were killed outright (SIGKILL, power loss) cannot clean up after themselves.
|
|
1786
|
+
sweepStaleInstallDirs(config.cacheDir);
|
|
1787
|
+
rmSync(stagingRoot, { recursive: true, force: true });
|
|
1788
|
+
|
|
1789
|
+
// `finally` does not run when a signal ends the process, so clean up here.
|
|
1790
|
+
// The swap below is synchronous, so a signal can only land while extracting.
|
|
1791
|
+
const extraction = new AbortController();
|
|
1792
|
+
let extracting = Promise.resolve();
|
|
1793
|
+
let interrupted = false;
|
|
1794
|
+
const signalHandlers = INTERRUPT_SIGNALS.map((signal) => {
|
|
1795
|
+
const handler = async () => {
|
|
1796
|
+
interrupted = true;
|
|
1797
|
+
extraction.abort();
|
|
1798
|
+
// The extractor must be gone first, or it can recreate files after the cleanup.
|
|
1799
|
+
await extracting.catch(() => {});
|
|
1800
|
+
removeStagingRoot(stagingRoot);
|
|
1801
|
+
process.exit(128 + osConstants.signals[signal]);
|
|
1802
|
+
};
|
|
1803
|
+
process.on(signal, handler);
|
|
1804
|
+
return [signal, handler];
|
|
1805
|
+
});
|
|
1806
|
+
|
|
1807
|
+
try {
|
|
1808
|
+
extracting = extractArchive(archivePath, stagedDir, { abortSignal: extraction.signal });
|
|
1809
|
+
// On an interrupt the handler owns the shutdown; do not let the abort error unwind into the caller first.
|
|
1810
|
+
await extracting.catch((error) => {
|
|
1811
|
+
if (interrupted) return new Promise(() => {});
|
|
1812
|
+
throw error;
|
|
1813
|
+
});
|
|
1814
|
+
const stagedBinary = findC8RunBinaryPath({ cacheDir: stagingRoot, version: config.version });
|
|
1815
|
+
if (!stagedBinary) {
|
|
1816
|
+
throw new Error(`The downloaded c8run ${config.version} archive does not contain a c8run launcher.`);
|
|
1817
|
+
}
|
|
1818
|
+
const stagedBuild = basename(dirname(stagedBinary));
|
|
1819
|
+
if (isPrereleaseBuild(stagedBuild)) {
|
|
1820
|
+
throw new Error(
|
|
1821
|
+
`The downloaded c8run ${config.version} is a prerelease build (${stagedBuild.slice('c8run-'.length)}); ` +
|
|
1822
|
+
'"stable" needs a GA build. Try again once the GA build is published, or start an explicit GA version.',
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
await chmod(stagedBinary, 0o755);
|
|
1826
|
+
|
|
1827
|
+
// Rechecked here: another c8ctl may have started this version during the download.
|
|
1828
|
+
if (isVersionInstanceRunning(config.cacheDir, config.version)) {
|
|
1829
|
+
throw new Error(
|
|
1830
|
+
`Refusing to replace c8run ${config.version}: an instance started from it is still running. ` +
|
|
1831
|
+
'Stop it first with "c8ctl cluster stop".',
|
|
1832
|
+
);
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
// Rechecked here too: data may have been created during the download.
|
|
1836
|
+
refuseIfClusterDataAtRisk(config);
|
|
1837
|
+
|
|
1838
|
+
const replacing = existsSync(installDir);
|
|
1839
|
+
if (replacing) {
|
|
1840
|
+
logger.info(`Replacing the existing c8run ${config.version} build...`);
|
|
1841
|
+
rmSync(backupDir, { recursive: true, force: true });
|
|
1842
|
+
renameSync(installDir, backupDir);
|
|
1843
|
+
}
|
|
1844
|
+
try {
|
|
1845
|
+
renameSync(stagedDir, installDir);
|
|
1846
|
+
} catch (error) {
|
|
1847
|
+
if (replacing) renameSync(backupDir, installDir);
|
|
1848
|
+
throw error;
|
|
1849
|
+
}
|
|
1850
|
+
if (replacing) rmSync(backupDir, { recursive: true, force: true });
|
|
1851
|
+
} finally {
|
|
1852
|
+
for (const [signal, handler] of signalHandlers) process.off(signal, handler);
|
|
1853
|
+
rmSync(stagingRoot, { recursive: true, force: true });
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
const INTERRUPT_SIGNALS = ['SIGINT', 'SIGTERM'];
|
|
1858
|
+
|
|
1859
|
+
function removeStagingRoot(stagingRoot) {
|
|
1860
|
+
try {
|
|
1861
|
+
rmSync(stagingRoot, { recursive: true, force: true, maxRetries: 5, retryDelay: 50 });
|
|
1862
|
+
} catch {
|
|
1863
|
+
// Best effort: the next install or delete/purge sweeps what is left.
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
const STALE_INSTALL_DIR = /^\.(staging|replaced)-(c8run-.+)-(\d+)$/;
|
|
1868
|
+
|
|
1869
|
+
/**
|
|
1870
|
+
* Clean up after `.staging-c8run-*` and `.replaced-c8run-*` dirs whose owning
|
|
1871
|
+
* c8ctl (the trailing pid) is gone. They are dot-prefixed, so `cluster list`
|
|
1872
|
+
* and `cluster delete` never see them. Dirs of a live pid belong to a
|
|
1873
|
+
* concurrent install and are left alone.
|
|
1874
|
+
*
|
|
1875
|
+
* A staging dir is only ever a partial extraction, so it is deleted. A
|
|
1876
|
+
* `.replaced` dir is the previous install, set aside just before the swap; if
|
|
1877
|
+
* its owner died between the two renames it is the only copy left, so it is
|
|
1878
|
+
* moved back when the install dir is missing and deleted only when redundant.
|
|
1879
|
+
*/
|
|
1880
|
+
export function sweepStaleInstallDirs(cacheDir) {
|
|
1881
|
+
if (!existsSync(cacheDir)) return;
|
|
1882
|
+
for (const entry of readdirSync(cacheDir, { withFileTypes: true })) {
|
|
1883
|
+
const match = entry.isDirectory() && STALE_INSTALL_DIR.exec(entry.name);
|
|
1884
|
+
if (!match || isPidAlive(Number(match[3]))) continue;
|
|
1885
|
+
const dir = join(cacheDir, entry.name);
|
|
1886
|
+
try {
|
|
1887
|
+
const installDir = join(cacheDir, match[2]);
|
|
1888
|
+
if (match[1] === 'replaced' && !existsSync(installDir)) {
|
|
1889
|
+
renameSync(dir, installDir);
|
|
1890
|
+
} else {
|
|
1891
|
+
rmSync(dir, { recursive: true, force: true });
|
|
1892
|
+
}
|
|
1893
|
+
} catch {
|
|
1894
|
+
// Best effort: housekeeping must not fail the command that triggered it.
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1575
1899
|
// ---------------------------------------------------------------------------
|
|
1576
1900
|
// Process management
|
|
1577
1901
|
// ---------------------------------------------------------------------------
|
|
1578
1902
|
|
|
1579
1903
|
const STARTUP_SUMMARY_MARKER = '- Operate:';
|
|
1580
1904
|
|
|
1581
|
-
|
|
1905
|
+
/**
|
|
1906
|
+
* c8run's zerolog console lines (`9:57AM INF …`). The summary is printed
|
|
1907
|
+
* as soon as Camunda is healthy, but the captured output continues with
|
|
1908
|
+
* these log lines while the Connectors runtime still starts. Cut there —
|
|
1909
|
+
* printing them after the summary looks like the cluster started twice.
|
|
1910
|
+
*/
|
|
1911
|
+
const C8RUN_LOG_LINE =
|
|
1912
|
+
/^\d{1,2}:\d{2}(?::\d{2})?(?:AM|PM)?\s+(?:DBG|INF|WRN|ERR|FTL|PNC|TRC)\s/;
|
|
1913
|
+
|
|
1914
|
+
export function extractStartupSummary(rawOutput) {
|
|
1582
1915
|
const startIndex = rawOutput.indexOf(STARTUP_SUMMARY_MARKER);
|
|
1583
1916
|
if (startIndex === -1) {
|
|
1584
1917
|
return null;
|
|
1585
1918
|
}
|
|
1586
|
-
|
|
1919
|
+
const lines = rawOutput.slice(startIndex).split('\n');
|
|
1920
|
+
const summaryLines = [];
|
|
1921
|
+
for (const line of lines) {
|
|
1922
|
+
if (C8RUN_LOG_LINE.test(line.trimStart())) break;
|
|
1923
|
+
summaryLines.push(line);
|
|
1924
|
+
}
|
|
1925
|
+
return summaryLines.join('\n').trim();
|
|
1587
1926
|
}
|
|
1588
1927
|
|
|
1589
1928
|
async function waitForClusterReady(maxWaitMs = CLUSTER_STARTUP_TIMEOUT_MS) {
|
|
@@ -1614,29 +1953,39 @@ async function waitForClusterReady(maxWaitMs = CLUSTER_STARTUP_TIMEOUT_MS) {
|
|
|
1614
1953
|
return false;
|
|
1615
1954
|
}
|
|
1616
1955
|
|
|
1617
|
-
function printSummary(rawOutput, version) {
|
|
1956
|
+
function printSummary(rawOutput, version, port = DEFAULT_HTTP_PORT) {
|
|
1618
1957
|
const summary = extractStartupSummary(rawOutput);
|
|
1619
1958
|
|
|
1620
1959
|
if (summary) {
|
|
1621
1960
|
console.log(`\n${summary}\n`);
|
|
1622
|
-
|
|
1961
|
+
} else {
|
|
1962
|
+
// c8run daemonizes so captured output is often empty — print known defaults
|
|
1963
|
+
const urls = clusterUrls(port);
|
|
1964
|
+
console.log('');
|
|
1965
|
+
console.log(`Camunda 8 (${version}) is running:`);
|
|
1966
|
+
console.log('');
|
|
1967
|
+
console.log(` - Operate: ${urls.operate}`);
|
|
1968
|
+
console.log(` - Tasklist: ${urls.tasklist}`);
|
|
1969
|
+
console.log(` - Zeebe GRPC: ${urls.zeebeGrpc}`);
|
|
1970
|
+
console.log(` - Zeebe REST: ${urls.zeebeRest}`);
|
|
1971
|
+
console.log(` - Health: ${urls.health}`);
|
|
1972
|
+
console.log('');
|
|
1973
|
+
console.log(' Default credentials: demo / demo');
|
|
1974
|
+
console.log('');
|
|
1623
1975
|
}
|
|
1624
1976
|
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
console.log('');
|
|
1635
|
-
console.log(' Default credentials: demo / demo');
|
|
1636
|
-
console.log('');
|
|
1977
|
+
if (port !== DEFAULT_HTTP_PORT) {
|
|
1978
|
+
// The built-in 'local' profile targets the default port; tell the user how
|
|
1979
|
+
// to point c8ctl at this cluster rather than rewriting their profile.
|
|
1980
|
+
console.log(` c8ctl's 'local' profile targets port ${DEFAULT_HTTP_PORT}. To use this cluster, either:`);
|
|
1981
|
+
console.log(` c8ctl add profile local-${port} --baseUrl=http://localhost:${port}/v2 --username=demo --password=demo`);
|
|
1982
|
+
console.log(` c8ctl use profile local-${port}`);
|
|
1983
|
+
console.log(` or, with no active profile, set CAMUNDA_BASE_URL=http://localhost:${port}/v2`);
|
|
1984
|
+
console.log('');
|
|
1985
|
+
}
|
|
1637
1986
|
}
|
|
1638
1987
|
|
|
1639
|
-
async function startC8Run(config, debug = false, startArgs = []) {
|
|
1988
|
+
async function startC8Run(config, debug = false, startArgs = [], port = DEFAULT_HTTP_PORT) {
|
|
1640
1989
|
const logger = getLogger();
|
|
1641
1990
|
const binaryPath = getC8RunBinaryPath(config);
|
|
1642
1991
|
const logDir = join(dirname(binaryPath), 'log');
|
|
@@ -1647,6 +1996,7 @@ async function startC8Run(config, debug = false, startArgs = []) {
|
|
|
1647
1996
|
|
|
1648
1997
|
const markerFile = join(config.cacheDir, ACTIVE_MARKER_FILE);
|
|
1649
1998
|
const versionFile = join(config.cacheDir, VERSION_MARKER_FILE);
|
|
1999
|
+
const portFile = join(config.cacheDir, PORT_MARKER_FILE);
|
|
1650
2000
|
|
|
1651
2001
|
if (existsSync(markerFile)) {
|
|
1652
2002
|
// Check whether actual cluster processes are still alive.
|
|
@@ -1669,6 +2019,7 @@ async function startC8Run(config, debug = false, startArgs = []) {
|
|
|
1669
2019
|
logger.warn('Found stale cluster marker (no running processes detected). Cleaning up.');
|
|
1670
2020
|
if (existsSync(markerFile)) rmSync(markerFile);
|
|
1671
2021
|
if (existsSync(versionFile)) rmSync(versionFile);
|
|
2022
|
+
rmSync(portFile, { force: true });
|
|
1672
2023
|
} else if (hasRunningClusterPidfiles(config.cacheDir)) {
|
|
1673
2024
|
// No active marker, but a live process is still tracked — typically an
|
|
1674
2025
|
// orphan recorded only in the durable cache-root PID record after its
|
|
@@ -1689,16 +2040,37 @@ async function startC8Run(config, debug = false, startArgs = []) {
|
|
|
1689
2040
|
|
|
1690
2041
|
logger.info('Starting Camunda 8 local cluster...');
|
|
1691
2042
|
|
|
2043
|
+
// Persist the chosen port BEFORE spawning c8run. If c8ctl is interrupted
|
|
2044
|
+
// while the launcher is still running (SIGINT/SIGTERM, crash), c8run's
|
|
2045
|
+
// `.process` pidfiles can remain live without the success/failure writes
|
|
2046
|
+
// below ever running — and `cluster status` reads the recorded port whenever
|
|
2047
|
+
// tracked processes survive. Without this early write, recovery status would
|
|
2048
|
+
// advertise the default port for a cluster actually serving on the custom
|
|
2049
|
+
// one.
|
|
2050
|
+
writeFileSync(portFile, String(port));
|
|
2051
|
+
|
|
2052
|
+
// c8run passes its environment to every Java process it launches. An
|
|
2053
|
+
// inherited SERVER_PORT would therefore move the bundled Connectors runtime
|
|
2054
|
+
// onto the Camunda port as well (port clash) — use --port instead. On Windows
|
|
2055
|
+
// the variable name is case-insensitive, so the exclusion must be too.
|
|
2056
|
+
const launchEnv = buildC8RunLaunchEnv(resolveLocalStoreEnv(process.env, process.cwd()));
|
|
1692
2057
|
const proc = spawn(binaryPath, ['start', ...startArgs], {
|
|
1693
2058
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
1694
2059
|
cwd: dirname(binaryPath),
|
|
1695
|
-
env: { ...
|
|
2060
|
+
env: { ...launchEnv, C8RUN_CLI_NAME },
|
|
1696
2061
|
});
|
|
1697
2062
|
|
|
1698
2063
|
if (typeof proc.pid !== 'number') {
|
|
2064
|
+
// spawn() reports this failure via an async 'error' event; without a
|
|
2065
|
+
// listener it would crash the process while the hints are flushed below.
|
|
2066
|
+
proc.on('error', (err) => logger.error(`Failed to spawn c8run: ${err.message}`));
|
|
2067
|
+
if (!hasRunningClusterPidfiles(config.cacheDir)) {
|
|
2068
|
+
rmSync(portFile, { force: true });
|
|
2069
|
+
}
|
|
1699
2070
|
logger.error('Failed to start cluster process: no PID received from c8run.');
|
|
1700
2071
|
logger.error(`Check logs in: ${logDir}`);
|
|
1701
2072
|
logger.info(`Print logs with: cat "${logDir}"/*.log`, { essential: true });
|
|
2073
|
+
await flushStartHints(config);
|
|
1702
2074
|
process.exit(1);
|
|
1703
2075
|
}
|
|
1704
2076
|
|
|
@@ -1724,34 +2096,53 @@ async function startC8Run(config, debug = false, startArgs = []) {
|
|
|
1724
2096
|
let exitCode = null;
|
|
1725
2097
|
let exitSignal = null;
|
|
1726
2098
|
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
2099
|
+
try {
|
|
2100
|
+
await new Promise((resolve, reject) => {
|
|
2101
|
+
proc.on('error', (err) => {
|
|
2102
|
+
reject(new Error(`Failed to spawn c8run: ${err.message}`));
|
|
2103
|
+
});
|
|
2104
|
+
proc.on('close', (code, signal) => {
|
|
2105
|
+
exitCode = code;
|
|
2106
|
+
exitSignal = signal;
|
|
2107
|
+
resolve();
|
|
2108
|
+
});
|
|
1735
2109
|
});
|
|
1736
|
-
})
|
|
2110
|
+
} catch (error) {
|
|
2111
|
+
if (!hasRunningClusterPidfiles(config.cacheDir)) {
|
|
2112
|
+
rmSync(portFile, { force: true });
|
|
2113
|
+
}
|
|
2114
|
+
throw error;
|
|
2115
|
+
}
|
|
1737
2116
|
|
|
1738
2117
|
if (exitCode !== 0) {
|
|
1739
2118
|
// A failed tenant probe leaves healthy engines alive; preserve their identity
|
|
1740
2119
|
// for stop/status even if the installation directory is subsequently replaced.
|
|
1741
2120
|
try {
|
|
1742
2121
|
recordRunningClusterPids(config, { skipEmpty: true, startupFailed: true });
|
|
2122
|
+
// Persist the port for the survivors too: the success-only marker write
|
|
2123
|
+
// below never runs on this path, so without it a failed custom-port
|
|
2124
|
+
// start would leave status reporting the default port for processes
|
|
2125
|
+
// that actually serve on the custom one.
|
|
2126
|
+
writeFileSync(portFile, String(port));
|
|
1743
2127
|
} catch (error) {
|
|
1744
2128
|
logger.warn(`Could not record surviving cluster processes: ${formatErrorWithCause(error)}. Use "c8ctl cluster stop" while the installation is still present.`);
|
|
1745
2129
|
}
|
|
2130
|
+
if (!hasRunningClusterPidfiles(config.cacheDir)) {
|
|
2131
|
+
rmSync(portFile, { force: true });
|
|
2132
|
+
}
|
|
1746
2133
|
if (startupOutput.trim()) {
|
|
1747
2134
|
logger.error(`c8run output:\n${startupOutput.trim()}`);
|
|
1748
2135
|
}
|
|
1749
2136
|
if (startArgs.length > 0 && /flag provided but not defined: -physical-tenants/.test(startupOutput)) {
|
|
1750
2137
|
logger.error('This cached c8run build lacks --physical-tenants. Install a Camunda 8.10+ build containing physical-tenant CLI support with "c8ctl cluster install 8.10".');
|
|
1751
2138
|
}
|
|
2139
|
+
if (/flag provided but not defined: -port\b/.test(startupOutput)) {
|
|
2140
|
+
logger.error('This cached c8run build does not support --port. Install a newer Camunda 8 Run build (for example "c8ctl cluster install 8.10") or start without --port.');
|
|
2141
|
+
}
|
|
1752
2142
|
logger.error(
|
|
1753
2143
|
`c8run start exited with code ${exitCode ?? 'unknown'}${exitSignal ? ` (signal: ${exitSignal})` : ''}. Cluster will not be marked as running.`,
|
|
1754
2144
|
);
|
|
2145
|
+
await flushStartHints(config);
|
|
1755
2146
|
process.exit(typeof exitCode === 'number' && exitCode > 0 ? exitCode : 1);
|
|
1756
2147
|
}
|
|
1757
2148
|
|
|
@@ -1784,15 +2175,23 @@ async function startC8Run(config, debug = false, startArgs = []) {
|
|
|
1784
2175
|
}
|
|
1785
2176
|
writeFileSync(markerFile, 'running');
|
|
1786
2177
|
writeFileSync(versionFile, config.version);
|
|
1787
|
-
|
|
2178
|
+
writeFileSync(portFile, String(port));
|
|
2179
|
+
printSummary(startupOutput, config.version, port);
|
|
1788
2180
|
} else {
|
|
1789
2181
|
// Readiness can fail even after c8run exits successfully. Retain the same
|
|
1790
2182
|
// recovery handle as a nonzero launcher exit before reporting failure.
|
|
1791
2183
|
try {
|
|
1792
2184
|
recordRunningClusterPids(config, { skipEmpty: true, startupFailed: true });
|
|
2185
|
+
// Persist the port for the survivors too (same reason as the nonzero
|
|
2186
|
+
// launcher exit path above): without it, status would report the
|
|
2187
|
+
// default port for processes serving on the custom one.
|
|
2188
|
+
writeFileSync(portFile, String(port));
|
|
1793
2189
|
} catch (error) {
|
|
1794
2190
|
logger.warn(`Could not record surviving cluster processes: ${formatErrorWithCause(error)}. Use "c8ctl cluster stop" while the installation is still present.`);
|
|
1795
2191
|
}
|
|
2192
|
+
if (!hasRunningClusterPidfiles(config.cacheDir)) {
|
|
2193
|
+
rmSync(portFile, { force: true });
|
|
2194
|
+
}
|
|
1796
2195
|
logger.error(
|
|
1797
2196
|
'Cluster failed to start within timeout.',
|
|
1798
2197
|
);
|
|
@@ -2363,8 +2762,11 @@ export async function stopC8Run(config, debug = false) {
|
|
|
2363
2762
|
|
|
2364
2763
|
if (!markerExists && !clusterAppearsRunning) {
|
|
2365
2764
|
// Nothing live to stop. Retire any stale record left by a crash/kill so its
|
|
2366
|
-
// dead PIDs cannot later be mistaken for this cluster (#560).
|
|
2765
|
+
// dead PIDs cannot later be mistaken for this cluster (#560). No process is
|
|
2766
|
+
// serving, so the port record is stale too — drop it, otherwise a later
|
|
2767
|
+
// status would keep advertising the old custom port for a stopped cluster.
|
|
2367
2768
|
clearStaleRunningClusterRecord(config.cacheDir);
|
|
2769
|
+
rmSync(join(config.cacheDir, PORT_MARKER_FILE), { force: true });
|
|
2368
2770
|
logger.warn(
|
|
2369
2771
|
'No cluster is currently running.',
|
|
2370
2772
|
);
|
|
@@ -2386,6 +2788,7 @@ export async function stopC8Run(config, debug = false) {
|
|
|
2386
2788
|
if (existsSync(markerFile)) {
|
|
2387
2789
|
rmSync(markerFile);
|
|
2388
2790
|
}
|
|
2791
|
+
rmSync(join(config.cacheDir, PORT_MARKER_FILE), { force: true });
|
|
2389
2792
|
clearRunningClusterRecord(config.cacheDir);
|
|
2390
2793
|
return staleVersion;
|
|
2391
2794
|
}
|
|
@@ -2551,6 +2954,17 @@ export async function stopC8Run(config, debug = false) {
|
|
|
2551
2954
|
);
|
|
2552
2955
|
}
|
|
2553
2956
|
|
|
2957
|
+
// The port record describes the cluster that was just stopped. Only drop it
|
|
2958
|
+
// once NOTHING still tracks a live process — neither the durable PID record
|
|
2959
|
+
// nor c8run's own `.process` pidfiles. `remainingPids` alone misses a process
|
|
2960
|
+
// tracked only by a pidfile (e.g. one the durable record never captured, or
|
|
2961
|
+
// whose record was already cleared), so gating on it would delete the port
|
|
2962
|
+
// while that survivor still serves — and a later `cluster status` would
|
|
2963
|
+
// advertise the default port for a custom-port cluster.
|
|
2964
|
+
if (!hasRunningClusterPidfiles(config.cacheDir)) {
|
|
2965
|
+
rmSync(join(config.cacheDir, PORT_MARKER_FILE), { force: true });
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2554
2968
|
if (attempted === 0 && !hadSuccessfulStop) {
|
|
2555
2969
|
// ...but only when there is nothing left to reap. If a recorded process is
|
|
2556
2970
|
// still alive (e.g. reaping hit EPERM), the incomplete-stop diagnostic
|
|
@@ -2714,6 +3128,32 @@ function resolveLocalStoreEnv(env, cwd) {
|
|
|
2714
3128
|
return resolvedEnv;
|
|
2715
3129
|
}
|
|
2716
3130
|
|
|
3131
|
+
/**
|
|
3132
|
+
* Build the environment handed to the c8run child process. c8run forwards its
|
|
3133
|
+
* environment to every Java process it launches, so an inherited SERVER_PORT
|
|
3134
|
+
* would also move the bundled Connectors runtime onto the Camunda port (a port
|
|
3135
|
+
* clash) — strip it and pass the port via --port instead.
|
|
3136
|
+
*
|
|
3137
|
+
* On Windows environment-variable names are case-insensitive, so the exclusion
|
|
3138
|
+
* must match case-insensitively there: an inherited `Server_Port` or
|
|
3139
|
+
* `server_port` is the same variable as `SERVER_PORT` and must be removed too.
|
|
3140
|
+
* Elsewhere names are case-sensitive, so only the exact `SERVER_PORT` is dropped
|
|
3141
|
+
* (a distinct lowercase `server_port` is a different variable and is left alone).
|
|
3142
|
+
*
|
|
3143
|
+
* @param {Record<string, string | undefined>} env
|
|
3144
|
+
* @param {string} [platform]
|
|
3145
|
+
* @returns {Record<string, string | undefined>}
|
|
3146
|
+
*/
|
|
3147
|
+
export function buildC8RunLaunchEnv(env, platform = osPlatform()) {
|
|
3148
|
+
if (platform === 'win32') {
|
|
3149
|
+
return Object.fromEntries(
|
|
3150
|
+
Object.entries(env).filter(([name]) => name.toUpperCase() !== 'SERVER_PORT'),
|
|
3151
|
+
);
|
|
3152
|
+
}
|
|
3153
|
+
const { SERVER_PORT: _ignoredServerPort, ...launchEnv } = env;
|
|
3154
|
+
return launchEnv;
|
|
3155
|
+
}
|
|
3156
|
+
|
|
2717
3157
|
/**
|
|
2718
3158
|
* True when a cluster is currently running, returning its version. Requires
|
|
2719
3159
|
* both marker files plus a live pidfile — a stale marker with no live
|
|
@@ -2860,13 +3300,28 @@ async function runClusterLocalCommand(
|
|
|
2860
3300
|
// Status
|
|
2861
3301
|
// ---------------------------------------------------------------------------
|
|
2862
3302
|
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
}
|
|
3303
|
+
/**
|
|
3304
|
+
* Endpoints of the local cluster. `--port` moves only c8run's main HTTP port;
|
|
3305
|
+
* gRPC (26500) and the management/health port (9600) stay fixed.
|
|
3306
|
+
*/
|
|
3307
|
+
export function clusterUrls(port = DEFAULT_HTTP_PORT) {
|
|
3308
|
+
return {
|
|
3309
|
+
operate: `http://localhost:${port}/operate`,
|
|
3310
|
+
tasklist: `http://localhost:${port}/tasklist`,
|
|
3311
|
+
zeebeGrpc: 'localhost:26500',
|
|
3312
|
+
zeebeRest: `http://localhost:${port}/v2/`,
|
|
3313
|
+
health: 'http://localhost:9600/actuator/health',
|
|
3314
|
+
};
|
|
3315
|
+
}
|
|
3316
|
+
|
|
3317
|
+
/** HTTP port recorded by the latest start attempt, or the c8run default. */
|
|
3318
|
+
export function readClusterPort(cacheDir) {
|
|
3319
|
+
const portFile = join(cacheDir, PORT_MARKER_FILE);
|
|
3320
|
+
if (!existsSync(portFile)) return DEFAULT_HTTP_PORT;
|
|
3321
|
+
const raw = readFileSync(portFile, 'utf-8').trim();
|
|
3322
|
+
const port = /^\d+$/.test(raw) ? Number(raw) : NaN;
|
|
3323
|
+
return port >= 1 && port <= 65535 ? port : DEFAULT_HTTP_PORT;
|
|
3324
|
+
}
|
|
2870
3325
|
|
|
2871
3326
|
export async function clusterStatus(cacheDir) {
|
|
2872
3327
|
const logger = getLogger();
|
|
@@ -2879,6 +3334,10 @@ export async function clusterStatus(cacheDir) {
|
|
|
2879
3334
|
// install dir was replaced/removed, orphaning it (#560). Detect it so status
|
|
2880
3335
|
// never reports "stopped" while a tracked cluster process is still alive.
|
|
2881
3336
|
const processesRunning = hasRunningClusterPidfiles(cacheDir);
|
|
3337
|
+
// The port is persisted before c8run starts and may be the only surviving
|
|
3338
|
+
// endpoint record after an interrupted launch. Trust it whenever present;
|
|
3339
|
+
// readClusterPort falls back to the c8run default when it is absent or invalid.
|
|
3340
|
+
const CLUSTER_URLS = clusterUrls(readClusterPort(cacheDir));
|
|
2882
3341
|
const markerVersion = markerExists && existsSync(versionFile)
|
|
2883
3342
|
? readFileSync(versionFile, 'utf-8').trim() || null
|
|
2884
3343
|
: null;
|
|
@@ -3142,7 +3601,10 @@ export async function deleteVersion(cacheDir, versionSpec) {
|
|
|
3142
3601
|
|
|
3143
3602
|
const config = { cacheDir, version: resolvedVersion };
|
|
3144
3603
|
|
|
3145
|
-
|
|
3604
|
+
// Guard on the install dir, not on the binary: the dir can survive
|
|
3605
|
+
// without its launcher (partial/corrupt install), and delete should
|
|
3606
|
+
// still remove what is left rather than report the version unremovable.
|
|
3607
|
+
if (!existsSync(join(cacheDir, `c8run-${resolvedVersion}`))) {
|
|
3146
3608
|
logger.warn(`Version ${versionSpec} is not installed locally.`);
|
|
3147
3609
|
return;
|
|
3148
3610
|
}
|
|
@@ -3186,48 +3648,19 @@ export async function purgeClusterData(cacheDir, versionSpec) {
|
|
|
3186
3648
|
process.exit(1);
|
|
3187
3649
|
}
|
|
3188
3650
|
|
|
3189
|
-
const config = { cacheDir, version: resolvedVersion };
|
|
3190
3651
|
const installDir = join(cacheDir, `c8run-${resolvedVersion}`);
|
|
3191
3652
|
if (!existsSync(installDir)) {
|
|
3192
3653
|
logger.error(`Version ${resolvedVersion} is not installed locally.`);
|
|
3193
3654
|
process.exit(1);
|
|
3194
3655
|
}
|
|
3195
3656
|
|
|
3196
|
-
//
|
|
3197
|
-
//
|
|
3198
|
-
//
|
|
3199
|
-
// (#560) — fall back to scanning the install dir and its immediate subdirs so
|
|
3200
|
-
// leftover data is still purged instead of being silently left behind.
|
|
3201
|
-
const binaryPath = findC8RunBinaryPath(config);
|
|
3202
|
-
const dataRoots = binaryPath
|
|
3203
|
-
? [dirname(binaryPath)]
|
|
3204
|
-
: [
|
|
3205
|
-
installDir,
|
|
3206
|
-
...readdirSync(installDir, { withFileTypes: true })
|
|
3207
|
-
.filter((entry) => entry.isDirectory())
|
|
3208
|
-
.map((entry) => join(installDir, entry.name)),
|
|
3209
|
-
];
|
|
3210
|
-
|
|
3657
|
+
// Not only beside the launcher that would run: an older build of a rolling
|
|
3658
|
+
// install, or an install that lost its launcher, can hold data too, and
|
|
3659
|
+
// `stable` refuses to replace an install while any of it is left.
|
|
3211
3660
|
const deleted = [];
|
|
3212
|
-
for (const
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
if (existsSync(camundaDataDir)) {
|
|
3216
|
-
rmSync(camundaDataDir, { recursive: true });
|
|
3217
|
-
deleted.push('camunda-data');
|
|
3218
|
-
}
|
|
3219
|
-
|
|
3220
|
-
// Delete Zeebe journal data inside camunda-zeebe-* subdirectory
|
|
3221
|
-
if (existsSync(dataRoot)) {
|
|
3222
|
-
for (const entry of readdirSync(dataRoot, { withFileTypes: true })) {
|
|
3223
|
-
if (!entry.isDirectory() || !entry.name.startsWith('camunda-zeebe-')) continue;
|
|
3224
|
-
const dataDir = join(dataRoot, entry.name, 'data');
|
|
3225
|
-
if (existsSync(dataDir)) {
|
|
3226
|
-
rmSync(dataDir, { recursive: true });
|
|
3227
|
-
deleted.push(join(entry.name, 'data'));
|
|
3228
|
-
}
|
|
3229
|
-
}
|
|
3230
|
-
}
|
|
3661
|
+
for (const dataDir of findClusterDataDirs(installDir)) {
|
|
3662
|
+
rmSync(dataDir, { recursive: true });
|
|
3663
|
+
deleted.push(relative(installDir, dataDir));
|
|
3231
3664
|
}
|
|
3232
3665
|
|
|
3233
3666
|
if (deleted.length > 0) {
|
|
@@ -3250,6 +3683,164 @@ export async function purgeClusterData(cacheDir, versionSpec) {
|
|
|
3250
3683
|
|
|
3251
3684
|
const LOG_FILES = ['camunda.log', 'connectors.log'];
|
|
3252
3685
|
|
|
3686
|
+
// Like `tail -f`: show the last lines of each file, then follow appends.
|
|
3687
|
+
const FOLLOW_INITIAL_LINES = 10;
|
|
3688
|
+
// Logs can be large, so the initial lines are found by scanning back in blocks.
|
|
3689
|
+
const TAIL_BLOCK_BYTES = 64 * 1024;
|
|
3690
|
+
const NEWLINE = 0x0a;
|
|
3691
|
+
|
|
3692
|
+
function readRange(file, start, end) {
|
|
3693
|
+
const fd = openSync(file, 'r');
|
|
3694
|
+
try {
|
|
3695
|
+
const buffer = Buffer.alloc(end - start);
|
|
3696
|
+
const bytesRead = readSync(fd, buffer, 0, buffer.length, start);
|
|
3697
|
+
return buffer.subarray(0, bytesRead);
|
|
3698
|
+
} finally {
|
|
3699
|
+
closeSync(fd);
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
|
|
3703
|
+
/**
|
|
3704
|
+
* Byte offset at which the last `count` lines of `file` start. Scans back
|
|
3705
|
+
* from the end until enough newlines are found, so a single entry longer
|
|
3706
|
+
* than any fixed window is still shown in full. The offset is always at a
|
|
3707
|
+
* line start, so decoding from it never splits a UTF-8 character. Also
|
|
3708
|
+
* returns the identity of the scanned file, to detect a later replacement.
|
|
3709
|
+
*/
|
|
3710
|
+
function tailStart(file, count) {
|
|
3711
|
+
const fd = openSync(file, 'r');
|
|
3712
|
+
try {
|
|
3713
|
+
const stats = fstatSync(fd, { bigint: true });
|
|
3714
|
+
const id = fileIdentity(stats);
|
|
3715
|
+
const size = Number(stats.size);
|
|
3716
|
+
const buffer = Buffer.alloc(TAIL_BLOCK_BYTES);
|
|
3717
|
+
let newlines = 0;
|
|
3718
|
+
for (let end = size; end > 0;) {
|
|
3719
|
+
const start = Math.max(0, end - buffer.length);
|
|
3720
|
+
const bytesRead = readSync(fd, buffer, 0, end - start, start);
|
|
3721
|
+
for (let i = bytesRead - 1; i >= 0; i--) {
|
|
3722
|
+
// A trailing newline ends the last line rather than starting a new one.
|
|
3723
|
+
if (buffer[i] !== NEWLINE || start + i === size - 1) continue;
|
|
3724
|
+
if (++newlines === count) return { offset: start + i + 1, id };
|
|
3725
|
+
}
|
|
3726
|
+
end = start;
|
|
3727
|
+
}
|
|
3728
|
+
return { offset: 0, id };
|
|
3729
|
+
} finally {
|
|
3730
|
+
closeSync(fd);
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3734
|
+
const isMissingFile = error => error?.code === 'ENOENT';
|
|
3735
|
+
|
|
3736
|
+
const fileIdentity = stats => `${stats.dev}:${stats.ino}`;
|
|
3737
|
+
|
|
3738
|
+
/**
|
|
3739
|
+
* Follow log files without `tail`, which Windows does not ship. Prints the
|
|
3740
|
+
* last lines of each file (with `==> file <==` headers when there are several,
|
|
3741
|
+
* as `tail` does), then polls for appended bytes until `signal` aborts.
|
|
3742
|
+
* A file that shrinks or is replaced (truncated or rotated) is re-read from the start.
|
|
3743
|
+
*/
|
|
3744
|
+
export async function followLogFiles(files, {
|
|
3745
|
+
signal,
|
|
3746
|
+
write = chunk => process.stdout.write(chunk),
|
|
3747
|
+
intervalMs = 500,
|
|
3748
|
+
} = {}) {
|
|
3749
|
+
const multiple = files.length > 1;
|
|
3750
|
+
let current = null;
|
|
3751
|
+
const emit = (file, text) => {
|
|
3752
|
+
if (multiple && current !== file) {
|
|
3753
|
+
write(`${current === null ? '' : '\n'}==> ${file} <==\n`);
|
|
3754
|
+
current = file;
|
|
3755
|
+
}
|
|
3756
|
+
if (text) write(text);
|
|
3757
|
+
};
|
|
3758
|
+
|
|
3759
|
+
// Reads whatever was appended since the last read. A file can vanish at
|
|
3760
|
+
// any point while it is rotated, so a missing file just yields nothing
|
|
3761
|
+
// and is picked up again on a later poll.
|
|
3762
|
+
const readAppended = (file, entry) => {
|
|
3763
|
+
try {
|
|
3764
|
+
const stats = statSync(file, { bigint: true });
|
|
3765
|
+
const size = Number(stats.size);
|
|
3766
|
+
const id = fileIdentity(stats);
|
|
3767
|
+
// A replaced file can be as large as the one it rotated out.
|
|
3768
|
+
const replaced = entry.id !== undefined && entry.id !== id;
|
|
3769
|
+
entry.id = id;
|
|
3770
|
+
if (replaced || size < entry.offset) {
|
|
3771
|
+
entry.offset = 0;
|
|
3772
|
+
entry.decoder = new StringDecoder('utf8');
|
|
3773
|
+
}
|
|
3774
|
+
if (size === entry.offset) return '';
|
|
3775
|
+
const chunk = readRange(file, entry.offset, size);
|
|
3776
|
+
entry.offset += chunk.length;
|
|
3777
|
+
return entry.decoder.write(chunk);
|
|
3778
|
+
} catch (error) {
|
|
3779
|
+
if (isMissingFile(error)) return '';
|
|
3780
|
+
throw error;
|
|
3781
|
+
}
|
|
3782
|
+
};
|
|
3783
|
+
|
|
3784
|
+
const state = new Map();
|
|
3785
|
+
for (const file of files) {
|
|
3786
|
+
let start = { offset: 0, id: undefined };
|
|
3787
|
+
try {
|
|
3788
|
+
start = tailStart(file, FOLLOW_INITIAL_LINES);
|
|
3789
|
+
} catch (error) {
|
|
3790
|
+
if (!isMissingFile(error)) throw error;
|
|
3791
|
+
}
|
|
3792
|
+
const entry = { ...start, decoder: new StringDecoder('utf8') };
|
|
3793
|
+
state.set(file, entry);
|
|
3794
|
+
// Emitted even when empty, so every file gets its header up front.
|
|
3795
|
+
emit(file, readAppended(file, entry));
|
|
3796
|
+
}
|
|
3797
|
+
|
|
3798
|
+
const poll = () => {
|
|
3799
|
+
for (const file of files) {
|
|
3800
|
+
const text = readAppended(file, state.get(file));
|
|
3801
|
+
if (text) emit(file, text);
|
|
3802
|
+
}
|
|
3803
|
+
};
|
|
3804
|
+
|
|
3805
|
+
await new Promise((resolve, reject) => {
|
|
3806
|
+
let timer;
|
|
3807
|
+
const settle = error => {
|
|
3808
|
+
clearInterval(timer);
|
|
3809
|
+
signal?.removeEventListener('abort', stop);
|
|
3810
|
+
if (error) reject(error);
|
|
3811
|
+
else resolve();
|
|
3812
|
+
};
|
|
3813
|
+
// An unexpected read error ends following instead of escaping the timer.
|
|
3814
|
+
const tick = () => {
|
|
3815
|
+
try {
|
|
3816
|
+
poll();
|
|
3817
|
+
return true;
|
|
3818
|
+
} catch (error) {
|
|
3819
|
+
settle(error);
|
|
3820
|
+
return false;
|
|
3821
|
+
}
|
|
3822
|
+
};
|
|
3823
|
+
function stop() {
|
|
3824
|
+
if (tick()) settle();
|
|
3825
|
+
}
|
|
3826
|
+
timer = setInterval(tick, intervalMs);
|
|
3827
|
+
if (signal?.aborted) stop();
|
|
3828
|
+
else signal?.addEventListener('abort', stop, { once: true });
|
|
3829
|
+
});
|
|
3830
|
+
}
|
|
3831
|
+
|
|
3832
|
+
/** Follows log files until Ctrl+C, which ends the command cleanly. */
|
|
3833
|
+
export async function followLogsUntilInterrupted(files, options = {}) {
|
|
3834
|
+
const controller = new AbortController();
|
|
3835
|
+
const sigintHandler = () => controller.abort();
|
|
3836
|
+
process.on('SIGINT', sigintHandler);
|
|
3837
|
+
try {
|
|
3838
|
+
await followLogFiles(files, { ...options, signal: controller.signal });
|
|
3839
|
+
} finally {
|
|
3840
|
+
process.removeListener('SIGINT', sigintHandler);
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3843
|
+
|
|
3253
3844
|
export async function streamLogs(cacheDir) {
|
|
3254
3845
|
const logger = getLogger();
|
|
3255
3846
|
const markerFile = join(cacheDir, ACTIVE_MARKER_FILE);
|
|
@@ -3295,6 +3886,12 @@ export async function streamLogs(cacheDir) {
|
|
|
3295
3886
|
logger.info(`Streaming logs from ${logDir} (Ctrl+C to stop)...`);
|
|
3296
3887
|
logger.info('');
|
|
3297
3888
|
|
|
3889
|
+
if (osPlatform() === 'win32') {
|
|
3890
|
+
// Windows has no `tail`, so follow the files in-process.
|
|
3891
|
+
await followLogsUntilInterrupted(existingLogs);
|
|
3892
|
+
return;
|
|
3893
|
+
}
|
|
3894
|
+
|
|
3298
3895
|
// Use tail -f to follow all log files
|
|
3299
3896
|
const tailArgs = ['-f', ...existingLogs];
|
|
3300
3897
|
const tail = spawn('tail', tailArgs, { stdio: 'inherit' });
|
|
@@ -3343,6 +3940,15 @@ export function parsePluginArgs(args) {
|
|
|
3343
3940
|
continue;
|
|
3344
3941
|
}
|
|
3345
3942
|
|
|
3943
|
+
if (arg === '--port' || arg.startsWith('--port=')) {
|
|
3944
|
+
const value = arg === '--port' ? args[i + 1] : arg.slice('--port='.length);
|
|
3945
|
+
result.port = parsePort(value);
|
|
3946
|
+
result.startArgs ??= [];
|
|
3947
|
+
result.startArgs.push('--port', String(result.port));
|
|
3948
|
+
i += arg === '--port' ? 2 : 1;
|
|
3949
|
+
continue;
|
|
3950
|
+
}
|
|
3951
|
+
|
|
3346
3952
|
if (arg === '--c8-version') {
|
|
3347
3953
|
const next = args[i + 1];
|
|
3348
3954
|
if (!next || next.startsWith('-')) {
|
|
@@ -3395,12 +4001,26 @@ export function parsePluginArgs(args) {
|
|
|
3395
4001
|
i += 1;
|
|
3396
4002
|
}
|
|
3397
4003
|
|
|
4004
|
+
if (result.port !== undefined && result.subcommand !== 'start') {
|
|
4005
|
+
throw new Error('--port can only be used with the start subcommand');
|
|
4006
|
+
}
|
|
3398
4007
|
if (result.startArgs && result.subcommand !== 'start') {
|
|
3399
4008
|
throw new Error('--physical-tenants can only be used with the start subcommand');
|
|
3400
4009
|
}
|
|
3401
4010
|
return result;
|
|
3402
4011
|
}
|
|
3403
4012
|
|
|
4013
|
+
function parsePort(value) {
|
|
4014
|
+
if (!value || value.startsWith('-')) {
|
|
4015
|
+
throw new Error('Missing value for --port. Provide the HTTP port, for example: c8ctl cluster start --port 9091');
|
|
4016
|
+
}
|
|
4017
|
+
const port = /^\d+$/.test(value) ? Number(value) : NaN;
|
|
4018
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
4019
|
+
throw new Error(`Invalid value for --port: "${value}". Use an integer between 1 and 65535.`);
|
|
4020
|
+
}
|
|
4021
|
+
return port;
|
|
4022
|
+
}
|
|
4023
|
+
|
|
3404
4024
|
// ---------------------------------------------------------------------------
|
|
3405
4025
|
// Plugin commands export
|
|
3406
4026
|
// ---------------------------------------------------------------------------
|
|
@@ -3588,6 +4208,10 @@ export const commands = {
|
|
|
3588
4208
|
process.exit(1);
|
|
3589
4209
|
}
|
|
3590
4210
|
|
|
4211
|
+
if (parsed.subcommand === 'delete' || parsed.subcommand === 'purge') {
|
|
4212
|
+
sweepStaleInstallDirs(getCacheDir());
|
|
4213
|
+
}
|
|
4214
|
+
|
|
3591
4215
|
if (parsed.subcommand === 'delete') {
|
|
3592
4216
|
try {
|
|
3593
4217
|
await deleteVersion(getCacheDir(), parsed.version);
|
|
@@ -3637,11 +4261,6 @@ export const commands = {
|
|
|
3637
4261
|
logger.info(`Resolved alias "${versionSpec}" → ${version}`);
|
|
3638
4262
|
}
|
|
3639
4263
|
|
|
3640
|
-
// For start with a named alias, check in the background whether the
|
|
3641
|
-
// remote resolves to a different (newer) version and hint if so.
|
|
3642
|
-
if (isStart && isVersionAlias(versionSpec)) {
|
|
3643
|
-
checkBackgroundAliasFreshness(versionSpec, version);
|
|
3644
|
-
}
|
|
3645
4264
|
const rolling = isRollingVersion(versionSpec);
|
|
3646
4265
|
const config = {
|
|
3647
4266
|
cacheDir: theCacheDir,
|
|
@@ -3653,14 +4272,23 @@ export const commands = {
|
|
|
3653
4272
|
checkForUpdateHint: parsed.subcommand === 'start' && rolling,
|
|
3654
4273
|
// --verbose: detailed HTTP diagnostics for the c8run download
|
|
3655
4274
|
verbose: ctx?.verbose === true,
|
|
4275
|
+
// stable: reject (and replace) an install whose build is a prerelease
|
|
4276
|
+
requireGA: versionSpec === 'stable',
|
|
3656
4277
|
};
|
|
3657
4278
|
|
|
4279
|
+
// For start with a named alias, check in the background whether the
|
|
4280
|
+
// remote resolves to a different (newer) version and hint if so.
|
|
4281
|
+
if (isStart && isVersionAlias(versionSpec)) {
|
|
4282
|
+
config._aliasHintPromise = checkBackgroundAliasFreshness(versionSpec, version, theCacheDir);
|
|
4283
|
+
}
|
|
4284
|
+
|
|
3658
4285
|
if (parsed.subcommand === 'start') {
|
|
3659
4286
|
try {
|
|
3660
4287
|
await ensureC8RunInstalled(config);
|
|
3661
|
-
await startC8Run(config, parsed.debug, parsed.startArgs);
|
|
4288
|
+
await startC8Run(config, parsed.debug, parsed.startArgs, parsed.port);
|
|
3662
4289
|
} catch (error) {
|
|
3663
4290
|
logger.error(`Failed to start cluster: ${formatErrorWithCause(error)}`);
|
|
4291
|
+
await flushStartHints(config);
|
|
3664
4292
|
process.exit(1);
|
|
3665
4293
|
}
|
|
3666
4294
|
} else if (parsed.subcommand === 'stop') {
|