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:
parent
1270ca71f8
commit
fcd2a61b65
14 changed files with 48 additions and 18 deletions
|
@ -38,17 +38,6 @@ if (config.title) {
|
|||
process.title = config.title;
|
||||
}
|
||||
|
||||
/*
|
||||
const cleanExit = () => process.exit();
|
||||
process.on('SIGINT', cleanExit); // catch ctrl-c
|
||||
process.on('SIGTERM', cleanExit); // catch kill
|
||||
|
||||
process.on('exit', function() {
|
||||
// TODO
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
async function startHTTPServer(appType, appName, port) {
|
||||
const app = await appBuilder.createApp(appType);
|
||||
app.set('port', port);
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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
31
server/lib/fork.js
Normal 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;
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
const config = require('config');
|
||||
const reportHelpers = require('../lib/report-helpers');
|
||||
const fork = require('child_process').fork;
|
||||
const fork = require('../lib/fork').fork;
|
||||
const path = require('path');
|
||||
const log = require('../lib/log');
|
||||
const fs = require('fs');
|
||||
|
|
|
@ -8,6 +8,7 @@ const { CampaignType, CampaignStatus, CampaignSource } = require('../../shared/c
|
|||
const util = require('util');
|
||||
const campaigns = require('../models/campaigns');
|
||||
const contextHelpers = require('../lib/context-helpers');
|
||||
require('../lib/fork');
|
||||
|
||||
const { tLog } = require('../lib/translate');
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ const shares = require('../models/shares');
|
|||
const { tLog } = require('../lib/translate');
|
||||
const {ListActivityType} = require('../../shared/activity-log');
|
||||
const activityLog = require('../lib/activity-log');
|
||||
require('../lib/fork');
|
||||
|
||||
|
||||
const csvparse = require('csv-parse');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const config = require('config');
|
||||
const fork = require('child_process').fork;
|
||||
const fork = require('../lib/fork').fork;
|
||||
const log = require('../lib/log');
|
||||
const path = require('path');
|
||||
const knex = require('../lib/knex');
|
||||
|
@ -11,6 +11,7 @@ const campaigns = require('../models/campaigns');
|
|||
const builtinZoneMta = require('../lib/builtin-zone-mta');
|
||||
const {CampaignActivityType} = require('../../shared/activity-log');
|
||||
const activityLog = require('../lib/activity-log');
|
||||
require('../lib/fork');
|
||||
|
||||
|
||||
let messageTid = 0;
|
||||
|
|
|
@ -5,6 +5,7 @@ const log = require('../lib/log');
|
|||
const mailers = require('../lib/mailers');
|
||||
const CampaignSender = require('../lib/campaign-sender');
|
||||
const {enforce} = require('../lib/helpers');
|
||||
require('../lib/fork');
|
||||
|
||||
const workerId = Number.parseInt(process.argv[2]);
|
||||
let running = false;
|
||||
|
|
|
@ -12,6 +12,7 @@ const knex = require('../../../lib/knex');
|
|||
const contextHelpers = require('../../../lib/context-helpers');
|
||||
const {renderCsvFromStream} = require('../../../lib/report-helpers');
|
||||
const stream = require('stream');
|
||||
require('../../../lib/fork');
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
|
|
|
@ -10,5 +10,10 @@ module.exports.init = (app, done) => {
|
|||
type: 'zone-mta-started'
|
||||
});
|
||||
|
||||
process.on('message', msg => {
|
||||
if (msg === 'exit') {
|
||||
process.exit(); }
|
||||
});
|
||||
|
||||
done();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue