From a38e4b0b144eed8b42e6d6c894a00ad3feca40aa Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 8 Oct 2021 21:24:05 +0900 Subject: [PATCH] =?UTF-8?q?server:=20=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=83=A9=E3=82=A4=E3=83=B3=E3=82=AA=E3=83=97=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E5=BB=83=E6=AD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolve #7863 Resolve #6337 --- CHANGELOG.md | 2 ++ package.json | 1 - src/argv.ts | 23 ----------------------- src/boot/index.ts | 8 ++++---- src/boot/master.ts | 8 ++++---- src/db/postgre.ts | 4 ++-- src/env.ts | 20 ++++++++++++++++++++ src/queue/index.ts | 4 ++-- src/server/index.ts | 4 ++-- src/services/logger.ts | 8 ++++---- yarn.lock | 5 ----- 11 files changed, 40 insertions(+), 47 deletions(-) delete mode 100644 src/argv.ts create mode 100644 src/env.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index f65de7911..215555df7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ - クライアント: MFM関数構文のサジェストを実装 - ActivityPub: HTML -> MFMの変換を強化 - API: ap系のエンドポイントをログイン必須化+レートリミット追加 +- Misskeyのコマンドラインオプションを廃止 + - 代わりに環境変数で設定することができます ### Bugfixes - Fix createDeleteAccountJob diff --git a/package.json b/package.json index d12a0fc9b..308e6242c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/argv.ts b/src/argv.ts deleted file mode 100644 index 106ecf267..000000000 --- a/src/argv.ts +++ /dev/null @@ -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 }; diff --git a/src/boot/index.ts b/src/boot/index.ts index 20c53a366..cb4c8536d 100644 --- a/src/boot/index.ts +++ b/src/boot/index.ts @@ -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); } diff --git a/src/boot/master.ts b/src/boot/master.ts index d9cc7c16b..071b37b76 100644 --- a/src/boot/master.ts +++ b/src/boot/master.ts @@ -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(); diff --git a/src/db/postgre.ts b/src/db/postgre.ts index 8948f22cd..0b635ea18 100644 --- a/src/db/postgre.ts +++ b/src/db/postgre.ts @@ -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)); } } diff --git a/src/env.ts b/src/env.ts new file mode 100644 index 000000000..1b678edc4 --- /dev/null +++ b/src/env.ts @@ -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 }; diff --git a/src/queue/index.ts b/src/queue/index.ts index c787253de..1e1d5da5a 100644 --- a/src/queue/index.ts +++ b/src/queue/index.ts @@ -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); diff --git a/src/server/index.ts b/src/server/index.ts index fb4e48c1c..c89159614 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -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 })); diff --git a/src/services/logger.ts b/src/services/logger.ts index 229be891e..8e783e67f 100644 --- a/src/services/logger.ts +++ b/src/services/logger.ts @@ -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 | 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 | 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); } } diff --git a/yarn.lock b/yarn.lock index e999c2055..b5ef77912 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"