いくつかのコマンドラインオプションを追加するなど
This commit is contained in:
		
							parent
							
								
									23c32f1211
								
							
						
					
					
						commit
						fb74f1d72b
					
				
					 2 changed files with 57 additions and 31 deletions
				
			
		| 
						 | 
				
			
			@ -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",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										45
									
								
								src/index.ts
									
										
									
									
									
								
							
							
						
						
									
										45
									
								
								src/index.ts
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -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();
 | 
			
		||||
 | 
			
		||||
		if (cluster.isMaster) {
 | 
			
		||||
			ev.mount();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!program.noDaemons) {
 | 
			
		||||
			serverStats();
 | 
			
		||||
			notesStats();
 | 
			
		||||
	} else {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	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}`);
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			@ -79,9 +97,11 @@ async function workerMain() {
 | 
			
		|||
	// start server
 | 
			
		||||
	await require('./server').default();
 | 
			
		||||
 | 
			
		||||
	if (cluster.isWorker) {
 | 
			
		||||
		// Send a 'ready' message to parent process
 | 
			
		||||
		process.send('ready');
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Init app
 | 
			
		||||
| 
						 | 
				
			
			@ -124,20 +144,24 @@ 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) {
 | 
			
		||||
function spawnWorkers(limit: number) {
 | 
			
		||||
	return new Promise(res => {
 | 
			
		||||
		// Count the machine's CPUs
 | 
			
		||||
		const cpuCount = os.cpus().length;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -157,7 +181,8 @@ function spawnWorkers(limit: number, onComplete: Function) {
 | 
			
		|||
 | 
			
		||||
		// On all workers started
 | 
			
		||||
		progress.on('complete', () => {
 | 
			
		||||
		onComplete();
 | 
			
		||||
			res();
 | 
			
		||||
		});
 | 
			
		||||
	});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue