2021-08-15 00:10:54 +02:00
|
|
|
// process.env.MONGOMS_DEBUG = "true";
|
2021-08-13 12:58:18 +02:00
|
|
|
import cluster from "cluster";
|
|
|
|
import os from "os";
|
2021-10-04 21:01:08 +02:00
|
|
|
import { red, bold, yellow, cyan } from "chalk";
|
2021-08-14 23:15:19 +02:00
|
|
|
import { initStats } from "./stats";
|
2021-08-13 12:58:18 +02:00
|
|
|
|
2021-08-13 13:18:45 +02:00
|
|
|
// TODO: add tcp socket event transmission
|
|
|
|
const cores = 1 || Number(process.env.threads) || os.cpus().length;
|
2021-10-04 21:01:08 +02:00
|
|
|
const commit = require('child_process').execSync('git rev-parse HEAD').toString().trim();
|
|
|
|
|
|
|
|
console.log(bold(`
|
|
|
|
███████ ██████ ███████ ███████ ██████ ██████ ██████ ██████
|
|
|
|
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
|
|
█████ ██ ██ ███████ ███████ ██ ██ ██ ██████ ██ ██
|
|
|
|
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
|
|
|
██ ██████ ███████ ███████ ██████ ██████ ██ ██ ██████
|
|
|
|
|
|
|
|
|
|
|
|
fosscord-server | ${yellow(`Pre-relase (${commit.slice(0, 7)})`)}
|
|
|
|
|
|
|
|
Current commit: ${cyan(commit)} (${yellow(commit.slice(0, 7))})
|
|
|
|
`))
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-08-13 12:58:18 +02:00
|
|
|
|
|
|
|
if (cluster.isMaster && !process.env.masterStarted) {
|
|
|
|
process.env.masterStarted = "true";
|
|
|
|
|
|
|
|
(async () => {
|
2021-08-14 23:15:19 +02:00
|
|
|
initStats();
|
2021-08-13 12:58:18 +02:00
|
|
|
|
2021-08-13 20:54:52 +02:00
|
|
|
if (cores === 1) {
|
2021-09-19 18:45:09 +02:00
|
|
|
require("./Server");
|
2021-08-13 20:54:52 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-13 12:58:18 +02:00
|
|
|
// Fork workers.
|
|
|
|
for (let i = 0; i < cores; i++) {
|
|
|
|
cluster.fork();
|
|
|
|
}
|
|
|
|
|
|
|
|
cluster.on("exit", (worker: any, code: any, signal: any) => {
|
2021-09-19 18:45:09 +02:00
|
|
|
console.log(
|
2021-10-04 21:01:08 +02:00
|
|
|
`[Worker] ${red(`died with pid: ${worker.process.pid} , restarting ...`)}`
|
2021-09-19 18:45:09 +02:00
|
|
|
);
|
2021-08-13 12:58:18 +02:00
|
|
|
cluster.fork();
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
} else {
|
2021-09-19 18:45:09 +02:00
|
|
|
require("./Server");
|
2021-08-13 12:58:18 +02:00
|
|
|
}
|