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
|
@ -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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue