mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-27 06:20:14 +00:00
logs: Fix CTRL-C ignored on Windows (PowerShell, MSYS, Git for Windows)
Change-type: patch
This commit is contained in:
parent
5497835728
commit
d00db5ea8c
@ -221,21 +221,14 @@ export class LivepushManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup cleanup handlers for the device
|
// Setup cleanup handlers for the device
|
||||||
|
process.once('SIGINT', async () => {
|
||||||
// This is necessary because the `exit-hook` module is used by several
|
|
||||||
// dependencies, and will exit without calling the following handler.
|
|
||||||
// Once https://github.com/balena-io/balena-cli/issues/867 has been solved,
|
|
||||||
// we are free to (and definitely should) remove the below line
|
|
||||||
process.removeAllListeners('SIGINT');
|
|
||||||
process.on('SIGINT', async () => {
|
|
||||||
this.logger.logLivepush('Cleaning up device...');
|
this.logger.logLivepush('Cleaning up device...');
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
_.map(this.containers, (container) => {
|
_.map(this.containers, (container) => {
|
||||||
container.livepush.cleanupIntermediateContainers();
|
container.livepush.cleanupIntermediateContainers();
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
this.logger.logDebug('Cleaning up done.');
|
||||||
process.exit(0);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,12 +42,13 @@ export function displayDeviceLogs(
|
|||||||
logs.on('data', (log) => {
|
logs.on('data', (log) => {
|
||||||
displayLogLine(log, logger, system, filterServices);
|
displayLogLine(log, logger, system, filterServices);
|
||||||
});
|
});
|
||||||
|
logs.once('error', reject);
|
||||||
logs.on('error', reject);
|
logs.once('end', () => {
|
||||||
logs.on('end', () => {
|
logger.logWarn('Connection to device lost');
|
||||||
logger.logError('Connection to device lost');
|
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
process.once('SIGINT', () => logs.emit('close'));
|
||||||
|
process.once('SIGTERM', () => logs.emit('close'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,32 +123,7 @@ export async function startRemoteBuild(build: RemoteBuild): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!build.opts.headless) {
|
if (!build.opts.headless) {
|
||||||
return new Promise((resolve, reject) => {
|
return awaitRemoteBuildStream(build, stream);
|
||||||
// Setup interrupt handlers so we can cancel the build if the user presses
|
|
||||||
// ctrl+c
|
|
||||||
|
|
||||||
// This is necessary because the `exit-hook` module is used by several
|
|
||||||
// dependencies, and will exit without calling the following handler.
|
|
||||||
// Once https://github.com/balena-io/balena-cli/issues/867 has been solved,
|
|
||||||
// we are free to (and definitely should) remove the below line
|
|
||||||
process.removeAllListeners('SIGINT');
|
|
||||||
process.on('SIGINT', () => {
|
|
||||||
process.stderr.write('Received SIGINT, cleaning up. Please wait.\n');
|
|
||||||
cancelBuildIfNecessary(build).then(() => {
|
|
||||||
stream.end();
|
|
||||||
process.exit(130);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
stream.on('data', getBuilderMessageHandler(build));
|
|
||||||
stream.on('end', resolve);
|
|
||||||
stream.on('error', reject);
|
|
||||||
}).then(() => {
|
|
||||||
globalLogger.outputDeferredMessages();
|
|
||||||
if (build.hadError) {
|
|
||||||
throw new RemoteBuildFailedError();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're running a headless build, which means we'll
|
// We're running a headless build, which means we'll
|
||||||
@ -166,6 +141,42 @@ export async function startRemoteBuild(build: RemoteBuild): Promise<void> {
|
|||||||
handleHeadlessBuildMessage(result);
|
handleHeadlessBuildMessage(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function awaitRemoteBuildStream(
|
||||||
|
build: RemoteBuild,
|
||||||
|
stream: NodeJS.ReadWriteStream,
|
||||||
|
) {
|
||||||
|
let sigintHandler: (() => Promise<void>) | null = null;
|
||||||
|
try {
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
// Setup interrupt handlers so we can cancel the build if the user presses
|
||||||
|
// ctrl+c
|
||||||
|
sigintHandler = async () => {
|
||||||
|
process.exitCode = 130;
|
||||||
|
console.error('Received SIGINT, cleaning up. Please wait.');
|
||||||
|
try {
|
||||||
|
await cancelBuildIfNecessary(build);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err.message);
|
||||||
|
} finally {
|
||||||
|
stream.end();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
process.once('SIGINT', sigintHandler);
|
||||||
|
stream.on('data', getBuilderMessageHandler(build));
|
||||||
|
stream.on('end', resolve);
|
||||||
|
stream.on('error', reject);
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
if (sigintHandler) {
|
||||||
|
process.removeListener('SIGINT', sigintHandler);
|
||||||
|
}
|
||||||
|
globalLogger.outputDeferredMessages();
|
||||||
|
}
|
||||||
|
if (build.hadError) {
|
||||||
|
throw new RemoteBuildFailedError();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleHeadlessBuildMessage(message: HeadlessBuilderMessage) {
|
function handleHeadlessBuildMessage(message: HeadlessBuilderMessage) {
|
||||||
if (!process.stdout.isTTY) {
|
if (!process.stdout.isTTY) {
|
||||||
process.stdout.write(JSON.stringify(message));
|
process.stdout.write(JSON.stringify(message));
|
||||||
|
17
patches/all/exit-hook+1.1.1.patch
Normal file
17
patches/all/exit-hook+1.1.1.patch
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
diff --git a/node_modules/exit-hook/index.js b/node_modules/exit-hook/index.js
|
||||||
|
index e18013f..3366356 100644
|
||||||
|
--- a/node_modules/exit-hook/index.js
|
||||||
|
+++ b/node_modules/exit-hook/index.js
|
||||||
|
@@ -14,9 +14,9 @@ function exit(exit, signal) {
|
||||||
|
el();
|
||||||
|
});
|
||||||
|
|
||||||
|
- if (exit === true) {
|
||||||
|
- process.exit(128 + signal);
|
||||||
|
- }
|
||||||
|
+ // if (exit === true) {
|
||||||
|
+ // process.exit(128 + signal);
|
||||||
|
+ // }
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = function (cb) {
|
Loading…
x
Reference in New Issue
Block a user