install: auto detect and set wiredTigerCacheSize

pull/541/head
undefined 2 years ago
parent d3892202dc
commit f4d8cd7a5d
No known key found for this signature in database

@ -4,6 +4,7 @@
import { execSync, ExecSyncOptions } from 'child_process'; import { execSync, ExecSyncOptions } from 'child_process';
import { existsSync, readFileSync, writeFileSync } from 'fs'; import { existsSync, readFileSync, writeFileSync } from 'fs';
import net from 'net'; import net from 'net';
import os from 'os';
const exec = (command: string, args?: ExecSyncOptions) => { const exec = (command: string, args?: ExecSyncOptions) => {
try { try {
@ -224,6 +225,19 @@ function rollbackResolveField() {
return true; return true;
} }
const mem = os.totalmem() / 1024 / 1024 / 1024; // In GiB
const wtsize = Math.floor((mem / 6) * 10) / 10;
const printInfo = [
'echo "扫码加入QQ群',
'echo https://qm.qq.com/cgi-bin/qm/qr\\?k\\=0aTZfDKURRhPBZVpTYBohYG6P6sxABTw | qrencode -o - -m 2 -t UTF8',
() => {
password = new URL(require(`${process.env.HOME}/.hydro/config.json`).uri).password || '(No password)';
log.info('extra.dbUser');
log.info('extra.dbPassword', password);
},
];
const Steps = () => [ const Steps = () => [
{ {
init: 'install.preparing', init: 'install.preparing',
@ -360,7 +374,8 @@ connect-timeout = 10`);
() => writeFileSync(`${process.env.HOME}/.hydro/mount.yaml`, mount), () => writeFileSync(`${process.env.HOME}/.hydro/mount.yaml`, mount),
`pm2 start bash --name hydro-sandbox -- -c "ulimit -s unlimited && hydro-sandbox -mount-conf ${process.env.HOME}/.hydro/mount.yaml"`, `pm2 start bash --name hydro-sandbox -- -c "ulimit -s unlimited && hydro-sandbox -mount-conf ${process.env.HOME}/.hydro/mount.yaml"`,
...installAsJudge ? [] : [ ...installAsJudge ? [] : [
'pm2 start mongod --name mongodb -- --auth --bind_ip 0.0.0.0', () => console.log(`WiredTiger cache size: ${wtsize}GB`),
`pm2 start mongod --name mongodb -- --auth --bind_ip 0.0.0.0 --wiredTigerCacheSizeGB=${wtsize}`,
() => sleep(1000), () => sleep(1000),
'pm2 start hydrooj', 'pm2 start hydrooj',
async () => { async () => {
@ -401,13 +416,7 @@ connect-timeout = 10`);
{ {
init: 'install.done', init: 'install.done',
skip: () => installAsJudge, skip: () => installAsJudge,
operations: [ operations: printInfo,
() => {
password = new URL(require(`${process.env.HOME}/.hydro/config.json`).uri).password || '(No password)';
},
() => log.info('extra.dbUser'),
() => log.info('extra.dbPassword', password),
],
}, },
{ {
init: 'install.postinstall', init: 'install.postinstall',
@ -425,6 +434,7 @@ connect-timeout = 10`);
{ {
init: 'install.alldone', init: 'install.alldone',
operations: [ operations: [
...printInfo,
() => log.info('install.alldone'), () => log.info('install.alldone'),
() => installAsJudge && log.info('install.editJudgeConfigAndStart'), () => installAsJudge && log.info('install.editJudgeConfigAndStart'),
], ],

Loading…
Cancel
Save