core: pm2 cluster management

This commit is contained in:
undefined committed 2021-09-09 06:18:16 +08:00
1 parent 9f5c00a985
commit 448c398d21
30 files changed
+206 -427

No files matched your search

+20 -29
View File
@@ -2,39 +2,30 @@
/* eslint-disable import/no-extraneous-dependencies */
const os = require('os');
const path = require('path');
const cluster = require('cluster');
const fs = require('fs-extra');
const { filter } = require('lodash');
const argv = require('cac')().parse();
const hydro = require('hydrooj');
if (!cluster.isMaster) {
// Forked by hydro
hydro.load().catch((e) => {
console.error(e);
process.exit(1);
});
} else {
fs.ensureDirSync(path.resolve(os.homedir(), '.hydro'));
const addonPath = path.resolve(os.homedir(), '.hydro', 'addon.json');
let addons = filter(
fs.readdirSync(path.resolve(process.cwd(), 'packages')),
(i) => i !== 'hydrooj',
).map((i) => `@hydrooj/${i}`);
fs.writeFileSync(addonPath, JSON.stringify(addons, null, 2));
fs.ensureDirSync(path.resolve(os.homedir(), '.hydro'));
const addonPath = path.resolve(os.homedir(), '.hydro', 'addon.json');
let addons = filter(
fs.readdirSync(path.resolve(process.cwd(), 'packages')),
(i) => i !== 'hydrooj',
).map((i) => `@hydrooj/${i}`);
fs.writeFileSync(addonPath, JSON.stringify(addons, null, 2));
try {
const ui = argv.options.ui || '@hydrooj/ui-default';
require.resolve(ui);
addons = [ui, ...addons];
} catch (e) {
console.error('Please also install @hydrooj/ui-default');
}
addons = Array.from(new Set(addons));
for (const addon of addons) hydro.addon(addon);
(argv.args[0] === 'cli' ? hydro.loadCli : hydro.load)().catch((e) => {
console.error(e);
process.exit(1);
});
try {
const ui = argv.options.ui || '@hydrooj/ui-default';
require.resolve(ui);
addons = [ui, ...addons];
} catch (e) {
console.error('Please also install @hydrooj/ui-default');
}
addons = Array.from(new Set(addons));
for (const addon of addons) hydro.addon(addon);
(argv.args[0] === 'cli' ? hydro.loadCli : hydro.load)().catch((e) => {
console.error(e);
process.exit(1);
});