いくつかのコマンドラインオプションを追加するなど

This commit is contained in:
syuilo 2018-07-28 17:52:54 +09:00
parent 23c32f1211
commit fb74f1d72b
2 changed files with 57 additions and 31 deletions

View file

@ -90,6 +90,7 @@
"bootstrap-vue": "2.0.0-rc.11", "bootstrap-vue": "2.0.0-rc.11",
"cafy": "11.3.0", "cafy": "11.3.0",
"chalk": "2.4.1", "chalk": "2.4.1",
"commander": "2.16.0",
"crc-32": "1.2.0", "crc-32": "1.2.0",
"css-loader": "1.0.0", "css-loader": "1.0.0",
"dateformat": "3.0.3", "dateformat": "3.0.3",

View file

@ -11,6 +11,7 @@ import chalk from 'chalk';
import * as portscanner from 'portscanner'; import * as portscanner from 'portscanner';
import isRoot = require('is-root'); import isRoot = require('is-root');
import Xev from 'xev'; import Xev from 'xev';
import * as program from 'commander';
import Logger from './misc/logger'; import Logger from './misc/logger';
import ProgressBar from './misc/cli/progressbar'; import ProgressBar from './misc/cli/progressbar';
@ -31,6 +32,14 @@ if (process.env.NODE_ENV != 'production') {
process.env.DEBUG = 'misskey:*'; process.env.DEBUG = 'misskey:*';
} }
const pkg = require('../package.json');
program
.version(pkg.version)
.option('--no-daemons', 'Disable daemon processes (for debbuging)')
.option('--disable-clustering', 'Disable clustering')
.parse(process.argv);
// Start app // Start app
main(); main();
@ -38,13 +47,20 @@ main();
* Init process * Init process
*/ */
function main() { function main() {
if (cluster.isMaster) { if (cluster.isMaster || program.disableClustering) {
masterMain(); masterMain();
ev.mount(); if (cluster.isMaster) {
serverStats(); ev.mount();
notesStats(); }
} else {
if (!program.noDaemons) {
serverStats();
notesStats();
}
}
if (cluster.isWorker || program.disableClustering) {
workerMain(); workerMain();
} }
} }
@ -66,10 +82,12 @@ async function masterMain() {
Logger.succ('Misskey initialized'); Logger.succ('Misskey initialized');
spawnWorkers(config.clusterLimit, () => { if (!program.disableClustering) {
await spawnWorkers(config.clusterLimit);
Logger.succ('All workers started'); Logger.succ('All workers started');
Logger.info(`Now listening on port ${config.port} on ${config.url}`); }
});
Logger.info(`Now listening on port ${config.port} on ${config.url}`);
} }
/** /**
@ -79,8 +97,10 @@ async function workerMain() {
// start server // start server
await require('./server').default(); await require('./server').default();
// Send a 'ready' message to parent process if (cluster.isWorker) {
process.send('ready'); // Send a 'ready' message to parent process
process.send('ready');
}
} }
/** /**
@ -124,40 +144,45 @@ async function init(): Promise<Config> {
} }
// Try to connect to MongoDB // Try to connect to MongoDB
checkMongoDb(config);
return config;
}
function checkMongoDb(config: Config) {
const mongoDBLogger = new Logger('MongoDB'); const mongoDBLogger = new Logger('MongoDB');
mongoDBLogger.info(`Host: ${config.mongodb.host}`); mongoDBLogger.info(`Host: ${config.mongodb.host}`);
mongoDBLogger.info(`Port: ${config.mongodb.port}`); mongoDBLogger.info(`Port: ${config.mongodb.port}`);
mongoDBLogger.info(`DB: ${config.mongodb.db}`); mongoDBLogger.info(`DB: ${config.mongodb.db}`);
if (config.mongodb.user) mongoDBLogger.info(`User: ${config.mongodb.user}`); if (config.mongodb.user) mongoDBLogger.info(`User: ${config.mongodb.user}`);
if (config.mongodb.pass) mongoDBLogger.info(`Pass: ****`); if (config.mongodb.pass) mongoDBLogger.info(`Pass: ****`);
const db = require('./db/mongodb').default; require('./db/mongodb');
mongoDBLogger.succ('Connectivity confirmed'); mongoDBLogger.succ('Connectivity confirmed');
db.close();
return config;
} }
function spawnWorkers(limit: number, onComplete: Function) { function spawnWorkers(limit: number) {
// Count the machine's CPUs return new Promise(res => {
const cpuCount = os.cpus().length; // Count the machine's CPUs
const cpuCount = os.cpus().length;
const count = limit || cpuCount; const count = limit || cpuCount;
const progress = new ProgressBar(count, 'Starting workers'); const progress = new ProgressBar(count, 'Starting workers');
// Create a worker for each CPU // Create a worker for each CPU
for (let i = 0; i < count; i++) { for (let i = 0; i < count; i++) {
const worker = cluster.fork(); const worker = cluster.fork();
worker.on('message', message => { worker.on('message', message => {
if (message === 'ready') { if (message === 'ready') {
progress.increment(); progress.increment();
} }
});
}
// On all workers started
progress.on('complete', () => {
res();
}); });
}
// On all workers started
progress.on('complete', () => {
onComplete();
}); });
} }