diff --git a/packages/kbn-es/src/cli_commands/serverless.ts b/packages/kbn-es/src/cli_commands/serverless.ts index 53f1e1b35ae74..f20d957851fed 100644 --- a/packages/kbn-es/src/cli_commands/serverless.ts +++ b/packages/kbn-es/src/cli_commands/serverless.ts @@ -30,11 +30,16 @@ export const serverless: Command = { --tag Image tag of ESS to run from ${SERVERLESS_REPO} [default: ${SERVERLESS_TAG}] --image Full path of ESS image to run, has precedence over tag. [default: ${SERVERLESS_IMG}] + + --background Start ESS without attaching to the first node's logs + --basePath Path to the directory where the ES cluster will store data --clean Remove existing file system object store before running + --kill Kill running ESS nodes if detected on startup --port The port to bind to on 127.0.0.1 [default: ${DEFAULT_PORT}] --ssl Enable HTTP SSL on Elasticsearch - --kill Kill running ESS nodes if detected - --background Start ESS without attaching to the first node's logs + --teardown If this process exits, teardown the ES cluster as well + --waitForReady Wait for the ES cluster to be ready to serve requests + -E Additional key=value settings to pass to Elasticsearch -F Absolute paths for files to mount into containers @@ -60,8 +65,8 @@ export const serverless: Command = { files: 'F', }, - string: ['tag', 'image'], - boolean: ['clean', 'ssl', 'kill', 'background'], + string: ['tag', 'image', 'basePath'], + boolean: ['clean', 'ssl', 'kill', 'background', 'teardown', 'waitForReady'], default: defaults, }) as unknown as ServerlessOptions; diff --git a/packages/kbn-es/src/utils/docker.ts b/packages/kbn-es/src/utils/docker.ts index 563fd33c7a01e..00adea7e07cd6 100644 --- a/packages/kbn-es/src/utils/docker.ts +++ b/packages/kbn-es/src/utils/docker.ts @@ -626,11 +626,24 @@ export async function runServerlessCluster(log: ToolingLog, options: ServerlessO log.success('ES is ready'); } + if (options.teardown) { + // SIGINT will not trigger in FTR (see cluster.runServerless for FTR signal) + process.on('SIGINT', () => teardownServerlessClusterSync(log, options)); + } + if (!options.background) { // The ESS cluster has to be started detached, so we attach a logger afterwards for output await execa('docker', ['logs', '-f', SERVERLESS_NODES[0].name], { // inherit is required to show Docker output and Java console output for pw, enrollment token, etc stdio: ['ignore', 'inherit', 'inherit'], + }).catch((error) => { + /** + * 255 is a generic exit code which is triggered from docker logs command + * if we teardown the cluster since the entrypoint doesn't exit normally + */ + if (error.exitCode !== 255) { + log.error(error.message); + } }); }