mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-24 07:46:39 +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
|
||||
|
||||
// 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 () => {
|
||||
process.once('SIGINT', async () => {
|
||||
this.logger.logLivepush('Cleaning up device...');
|
||||
await Promise.all(
|
||||
_.map(this.containers, (container) => {
|
||||
container.livepush.cleanupIntermediateContainers();
|
||||
}),
|
||||
);
|
||||
|
||||
process.exit(0);
|
||||
this.logger.logDebug('Cleaning up done.');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,13 @@ export function displayDeviceLogs(
|
||||
logs.on('data', (log) => {
|
||||
displayLogLine(log, logger, system, filterServices);
|
||||
});
|
||||
|
||||
logs.on('error', reject);
|
||||
logs.on('end', () => {
|
||||
logger.logError('Connection to device lost');
|
||||
logs.once('error', reject);
|
||||
logs.once('end', () => {
|
||||
logger.logWarn('Connection to device lost');
|
||||
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) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// 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();
|
||||
}
|
||||
});
|
||||
return awaitRemoteBuildStream(build, stream);
|
||||
}
|
||||
|
||||
// We're running a headless build, which means we'll
|
||||
@ -166,6 +141,42 @@ export async function startRemoteBuild(build: RemoteBuild): Promise<void> {
|
||||
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) {
|
||||
if (!process.stdout.isTTY) {
|
||||
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…
Reference in New Issue
Block a user