Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
96c5967a35 | |||
c21c10d7f2 | |||
eb137c3871 | |||
334a38c71e |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartexit",
|
"name": "@pushrocks/smartexit",
|
||||||
"version": "1.0.9",
|
"version": "1.0.11",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartexit",
|
"name": "@pushrocks/smartexit",
|
||||||
"version": "1.0.9",
|
"version": "1.0.11",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "do things before one exists a process",
|
"description": "do things before one exists a process",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
17
ts/index.ts
17
ts/index.ts
@ -19,13 +19,13 @@ export class SmartExit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async killAll() {
|
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) {
|
if (this.processesToEnd.getArray().length > 0) {
|
||||||
console.log('found remaining child processes');
|
console.log('found remaining child processes');
|
||||||
let counter = 1;
|
let counter = 1;
|
||||||
this.processesToEnd.forEach(async childProcessArg => {
|
this.processesToEnd.forEach(async childProcessArg => {
|
||||||
const pid = childProcessArg.pid;
|
const pid = childProcessArg.pid;
|
||||||
console.log(`killing process #${counter} with pid ${pid}`);
|
console.log(`SMARTEXIT: killing process #${counter} with pid ${pid}`);
|
||||||
plugins.smartdelay.delayFor(10000).then(() => {
|
plugins.smartdelay.delayFor(10000).then(() => {
|
||||||
if (childProcessArg.killed) {
|
if (childProcessArg.killed) {
|
||||||
return;
|
return;
|
||||||
@ -37,26 +37,31 @@ export class SmartExit {
|
|||||||
counter++;
|
counter++;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log(`Everything looks clean. Ready to exit!`);
|
console.log(`SMARTEXIT: Everything looks clean. Ready to exit!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// do app specific cleaning before exiting
|
// 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();
|
await this.killAll();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// catch ctrl+c event and exit normally
|
// catch ctrl+c event and exit normally
|
||||||
process.on('SIGINT', async () => {
|
process.on('SIGINT', async () => {
|
||||||
console.log('Ctrl-C...');
|
console.log('SMARTEXIT: Ctrl-C... or SIGINT signal received!');
|
||||||
await this.killAll();
|
await this.killAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
//catch uncaught exceptions, trace, then exit normally
|
//catch uncaught exceptions, trace, then exit normally
|
||||||
process.on('uncaughtException', async err => {
|
process.on('uncaughtException', async err => {
|
||||||
console.log('Ctrl-C...');
|
console.log('SMARTEXIT: uncaught exception...');
|
||||||
|
console.log(err);
|
||||||
await this.killAll();
|
await this.killAll();
|
||||||
|
process.exit(1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user