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

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

View File

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

View File

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