6 Commits

Author SHA1 Message Date
96c5967a35 1.0.11 2019-05-27 15:16:39 +02:00
c21c10d7f2 fix(core): update 2019-05-27 15:16:38 +02:00
eb137c3871 1.0.10 2019-05-23 17:54:42 +02:00
334a38c71e fix(core): update 2019-05-23 17:54:41 +02:00
0d0404d00d 1.0.9 2019-05-23 17:53:17 +02:00
44414ab1b4 fix(core): now killing groups of processes with negative pid 2019-05-23 17:53:16 +02:00
3 changed files with 18 additions and 12 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartexit",
"version": "1.0.8",
"version": "1.0.11",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartexit",
"version": "1.0.8",
"version": "1.0.11",
"private": false,
"description": "do things before one exists a process",
"main": "dist/index.js",

View File

@ -19,43 +19,49 @@ export class SmartExit {
}
public async killAll() {
console.log('Checking for remaining child processes before exit...');
console.log('SMARTEXIT: Checking for remaining child processes before exit...');
if (this.processesToEnd.getArray().length > 0) {
console.log('found remaining child processes');
let counter = 1;
this.processesToEnd.forEach(async childProcessArg => {
console.log(`killing process #${counter}`);
const pid = childProcessArg.pid;
console.log(`SMARTEXIT: killing process #${counter} with pid ${pid}`);
plugins.smartdelay.delayFor(10000).then(() => {
if (childProcessArg.killed) {
return;
}
childProcessArg.kill('SIGKILL');
})
childProcessArg.kill('SIGINT');
process.kill(-pid, 'SIGKILL');
});
process.kill(-pid, 'SIGINT');
counter++;
});
} else {
console.log(`Everything looks clean. Ready to exit!`);
console.log(`SMARTEXIT: Everything looks clean. Ready to exit!`);
}
}
constructor() {
// do app specific cleaning before exiting
process.on('exit', async () => {
process.on('exit', async (code) => {
if (code === 0) {
console.log('SMARTEXIT: Process wants to exit');
await this.killAll();
}
});
// catch ctrl+c event and exit normally
process.on('SIGINT', async () => {
console.log('Ctrl-C...');
console.log('SMARTEXIT: Ctrl-C... or SIGINT signal received!');
await this.killAll();
});
//catch uncaught exceptions, trace, then exit normally
process.on('uncaughtException', async err => {
console.log('Ctrl-C...');
console.log('SMARTEXIT: uncaught exception...');
console.log(err);
await this.killAll();
process.exit(1);
});
}
}