keyserver/index.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

/**
* Mailvelope - secure email with OpenPGP encryption for Webmail
* Copyright (C) 2016 Mailvelope GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
const config = require('config');
2017-08-18 10:01:34 +00:00
const log = require('winston');
2017-08-18 10:04:43 +00:00
const papertrail = require('./src/dao/papertrail');
2017-08-17 11:16:49 +00:00
log.level = config.log.level;
2017-08-18 10:04:43 +00:00
papertrail.init(config.papertrail);
2016-05-26 11:58:38 +00:00
//
// Start worker cluster depending on number of CPUs
//
if (cluster.isMaster) {
for (let i = 0; i < numCPUs; i++) {
2016-05-26 11:58:38 +00:00
cluster.fork();
}
2017-08-17 11:16:49 +00:00
cluster.on('fork', worker => log.info('cluster', `Forked worker #${worker.id} [pid:${worker.process.pid}]`));
2016-05-26 11:58:38 +00:00
cluster.on('exit', worker => {
2017-08-17 11:16:49 +00:00
log.warn('cluster', `Worker #${worker.id} [pid:${worker.process.pid}] died`);
2019-05-27 12:31:22 +00:00
cluster.fork();
2016-05-26 11:58:38 +00:00
});
} else {
2017-08-17 11:16:49 +00:00
require('./src');
2016-05-26 11:58:38 +00:00
}
//
// Error handling
//
process.on('SIGTERM', () => {
log.warn('exit', 'Exited on SIGTERM');
process.exit(0);
});
process.on('SIGINT', () => {
log.warn('exit', 'Exited on SIGINT');
process.exit(0);
});
process.on('uncaughtException', err => {
2016-05-28 13:37:29 +00:00
log.error('index', 'Uncaught exception', err);
process.exit(1);
2017-08-15 08:03:06 +00:00
});