server: コマンドラインオプション廃止

Resolve #7863
Resolve #6337
This commit is contained in:
syuilo 2021-10-08 21:24:05 +09:00
parent 4d76e979a1
commit fb54b347a0
11 changed files with 40 additions and 47 deletions

View File

@ -16,6 +16,8 @@
- クライアント: MFM関数構文のサジェストを実装
- ActivityPub: HTML -> MFMの変換を強化
- API: ap系のエンドポイントをログイン必須化+レートリミット追加
- Misskeyのコマンドラインオプションを廃止
- 代わりに環境変数で設定することができます
### Bugfixes
- Fix createDeleteAccountJob

View File

@ -121,7 +121,6 @@
"chalk": "4.1.2",
"chart.js": "2.9.4",
"cli-highlight": "2.1.11",
"commander": "4.1.1",
"compare-versions": "3.6.0",
"concurrently": "6.3.0",
"content-disposition": "0.5.3",

View File

@ -1,23 +0,0 @@
import { Command } from 'commander';
import config from '@/config/index';
const program = new Command();
program.version(config.version);
program.option('--no-daemons', 'Disable daemon processes (for debbuging)');
program.option('--disable-clustering', 'Disable clustering');
program.option('--only-server', 'Run server only (without job queue processing)');
program.option('--only-queue', 'Pocessing job queue only (without server)');
program.option('--quiet', 'Suppress all logs');
program.option('--verbose', 'Enable all logs');
program.option('--with-log-time', 'Include timestamp for each logs');
program.option('--slow', 'Delay all requests (for debbuging)');
program.option('--color', 'This option is a dummy for some external program\'s (e.g. forever) issue.');
program.parse(process.argv);
if (process.env.MK_ONLY_QUEUE) program.onlyQueue = true;
if (process.env.NODE_ENV === 'test') program.disableClustering = true;
//if (process.env.NODE_ENV === 'test') program.quiet = true;
if (process.env.NODE_ENV === 'test') program.noDaemons = true;
export { program };

View File

@ -3,7 +3,7 @@ import * as chalk from 'chalk';
import Xev from 'xev';
import Logger from '@/services/logger';
import { program } from '../argv';
import { envOption } from '../env';
// for typeorm
import 'reflect-metadata';
@ -20,7 +20,7 @@ const ev = new Xev();
export default async function() {
process.title = `Misskey (${cluster.isMaster ? 'master' : 'worker'})`;
if (cluster.isMaster || program.disableClustering) {
if (cluster.isMaster || envOption.disableClustering) {
await masterMain();
if (cluster.isMaster) {
@ -28,7 +28,7 @@ export default async function() {
}
}
if (cluster.isWorker || program.disableClustering) {
if (cluster.isWorker || envOption.disableClustering) {
await workerMain();
}
@ -60,7 +60,7 @@ cluster.on('exit', worker => {
});
// Display detail of unhandled promise rejection
if (!program.quiet) {
if (!envOption.quiet) {
process.on('unhandledRejection', console.dir);
}

View File

@ -11,7 +11,7 @@ import Logger from '@/services/logger';
import loadConfig from '@/config/load';
import { Config } from '@/config/types';
import { lessThan } from '@/prelude/array';
import { program } from '../argv';
import { envOption } from '../env';
import { showMachineInfo } from '@/misc/show-machine-info';
import { initDb } from '../db/postgre';
@ -25,7 +25,7 @@ const logger = new Logger('core', 'cyan');
const bootLogger = logger.createSubLogger('boot', 'magenta', false);
function greet() {
if (!program.quiet) {
if (!envOption.quiet) {
//#region Misskey logo
const v = `v${meta.version}`;
console.log(' _____ _ _ ');
@ -73,13 +73,13 @@ export async function masterMain() {
bootLogger.succ('Misskey initialized');
if (!program.disableClustering) {
if (!envOption.disableClustering) {
await spawnWorkers(config.clusterLimit);
}
bootLogger.succ(`Now listening on port ${config.port} on ${config.url}`, null, true);
if (!program.noDaemons) {
if (!envOption.noDaemons) {
require('../daemons/server-stats').default();
require('../daemons/queue-stats').default();
require('../daemons/janitor').default();

View File

@ -63,7 +63,7 @@ import { Antenna } from '@/models/entities/antenna';
import { AntennaNote } from '@/models/entities/antenna-note';
import { PromoNote } from '@/models/entities/promo-note';
import { PromoRead } from '@/models/entities/promo-read';
import { program } from '../argv';
import { envOption } from '../env';
import { Relay } from '@/models/entities/relay';
import { MutedNote } from '@/models/entities/muted-note';
import { Channel } from '@/models/entities/channel';
@ -84,7 +84,7 @@ class MyCustomLogger implements Logger {
}
public logQuery(query: string, parameters?: any[]) {
if (program.verbose) {
if (envOption.verbose) {
sqlLogger.info(this.highlight(query));
}
}

20
src/env.ts Normal file
View File

@ -0,0 +1,20 @@
const envOption = {
onlyQueue: false,
onlyServer: false,
noDaemons: false,
disableClustering: false,
verbose: false,
withLogTime: false,
quiet: false,
slow: false,
};
for (const key of Object.keys(envOption) as (keyof typeof envOption)[]) {
if (process.env['MK_' + key.replace(/[A-Z]/g, letter => `_${letter}`).toUpperCase()]) envOption[key] = true;
}
if (process.env.NODE_ENV === 'test') envOption.disableClustering = true;
if (process.env.NODE_ENV === 'test') envOption.quiet = true;
if (process.env.NODE_ENV === 'test') envOption.noDaemons = true;
export { envOption };

View File

@ -1,7 +1,7 @@
import * as httpSignature from 'http-signature';
import config from '@/config/index';
import { program } from '../argv';
import { envOption } from '../env';
import processDeliver from './processors/deliver';
import processInbox from './processors/inbox';
@ -200,7 +200,7 @@ export function createCleanRemoteFilesJob() {
}
export default function() {
if (!program.onlyServer) {
if (!envOption.onlyServer) {
deliverQueue.process(config.deliverJobConcurrency || 128, processDeliver);
inboxQueue.process(config.inboxJobConcurrency || 16, processInbox);
processDb(dbQueue);

View File

@ -20,7 +20,7 @@ import config from '@/config/index';
import apiServer from './api/index';
import { sum } from '@/prelude/array';
import Logger from '@/services/logger';
import { program } from '../argv';
import { envOption } from '../env';
import { UserProfiles, Users } from '@/models/index';
import { networkChart } from '@/services/chart/index';
import { genAvatar } from '@/misc/gen-avatar';
@ -40,7 +40,7 @@ if (!['production', 'test'].includes(process.env.NODE_ENV || '')) {
}));
// Delay
if (program.slow) {
if (envOption.slow) {
app.use(slow({
delay: 3000
}));

View File

@ -2,7 +2,7 @@ import * as cluster from 'cluster';
import * as os from 'os';
import * as chalk from 'chalk';
import * as dateformat from 'dateformat';
import { program } from '../argv';
import { envOption } from '../env';
import { getRepository } from 'typeorm';
import { Log } from '@/models/entities/log';
import { genId } from '@/misc/gen-id';
@ -52,7 +52,7 @@ export default class Logger {
}
private log(level: Level, message: string, data?: Record<string, any> | null, important = false, subDomains: Domain[] = [], store = true): void {
if (program.quiet) return;
if (envOption.quiet) return;
if (!this.store) store = false;
if (level === 'debug') store = false;
@ -80,7 +80,7 @@ export default class Logger {
null;
let log = `${l} ${worker}\t[${domains.join(' ')}]\t${m}`;
if (program.withLogTime) log = chalk.gray(time) + ' ' + log;
if (envOption.withLogTime) log = chalk.gray(time) + ' ' + log;
console.log(important ? chalk.bold(log) : log);
@ -132,7 +132,7 @@ export default class Logger {
}
public debug(message: string, data?: Record<string, any> | null, important = false): void { // デバッグ用に使う(開発者に必要だが利用者に不要な情報)
if (process.env.NODE_ENV != 'production' || program.verbose) {
if (process.env.NODE_ENV != 'production' || envOption.verbose) {
this.log('debug', message, data, important);
}
}

View File

@ -3093,11 +3093,6 @@ combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
dependencies:
delayed-stream "~1.0.0"
commander@4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"
integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==
commander@^2.12.1, commander@^2.19.0, commander@^2.20.0:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"