Child processes are now terminated when the parent process dies. This means that if the main mailtrain process gets killed, there are no processes which remain running.

This commit is contained in:
Tomas Bures 2019-05-25 21:57:11 +02:00
parent 1270ca71f8
commit fcd2a61b65
14 changed files with 48 additions and 18 deletions

View file

@ -1,7 +1,7 @@
'use strict';
const config = require('config');
const fork = require('child_process').fork;
const fork = require('./fork').fork;
const log = require('./log');
const path = require('path');
const fs = require('fs-extra')

View file

@ -1,6 +1,6 @@
'use strict';
const fork = require('child_process').fork;
const fork = require('./fork').fork;
const log = require('./log');
const path = require('path');
const bluebird = require('bluebird');

View file

@ -1,6 +1,6 @@
'use strict';
const fork = require('child_process').fork;
const fork = require('./fork').fork;
const log = require('./log');
const path = require('path');
const senders = require('./senders');

31
server/lib/fork.js Normal file
View file

@ -0,0 +1,31 @@
'use strict';
const builtinFork = require('child_process').fork;
const cleanExit = () => process.exit();
process.on('SIGINT', cleanExit); // catch ctrl-c
process.on('SIGTERM', cleanExit); // catch kill
const children = [];
process.on('message', msg => {
if (msg === 'exit') {
cleanExit();
}
});
process.on('exit', function() {
for (const child of children) {
child.send('exit');
}
});
function fork(path, args, opts) {
const child = builtinFork(path, args, opts);
children.push(child);
return child;
}
module.exports.fork = fork;

View file

@ -1,7 +1,7 @@
'use strict';
const knex = require('./knex');
const fork = require('child_process').fork;
const fork = require('./fork').fork;
const log = require('./log');
const path = require('path');
const {ImportStatus, RunStatus} = require('../../shared/imports');

View file

@ -1,6 +1,6 @@
'use strict';
const fork = require('child_process').fork;
const fork = require('./fork').fork;
const log = require('./log');
const path = require('path');
const knex = require('./knex');