2021-08-15 00:10:54 +02:00
|
|
|
// process.env.MONGOMS_DEBUG = "true";
|
2021-10-08 10:43:43 +02:00
|
|
|
import "reflect-metadata";
|
2021-08-13 12:58:18 +02:00
|
|
|
import cluster from "cluster";
|
|
|
|
import os from "os";
|
2021-10-04 21:39:50 +02:00
|
|
|
import { red, bold, yellow, cyan } from "nanocolors";
|
2021-08-14 23:15:19 +02:00
|
|
|
import { initStats } from "./stats";
|
2021-10-04 21:57:24 +02:00
|
|
|
import { config } from "dotenv";
|
|
|
|
config();
|
2021-10-04 21:31:12 +02:00
|
|
|
import { execSync } from "child_process";
|
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-08-13 12:58:18 +02:00
|
|
|
|
2021-10-09 01:45:02 +02:00
|
|
|
function getCommitOrFail() {
|
2021-10-04 21:31:12 +02:00
|
|
|
try {
|
2021-10-04 22:06:17 +02:00
|
|
|
return execSync("git rev-parse HEAD").toString().trim();
|
|
|
|
} catch (e) {
|
|
|
|
return null;
|
2021-10-04 21:31:12 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-04 22:06:17 +02:00
|
|
|
const commit = getCommitOrFail();
|
2021-10-04 21:31:12 +02:00
|
|
|
|
2021-10-04 22:06:17 +02:00
|
|
|
console.log(
|
|
|
|
bold(`
|
2021-10-08 20:35:29 +02:00
|
|
|
███████╗ ██████╗ ███████╗███████╗ ██████╗ ██████╗ ██████╗ ██████╗
|
|
|
|
██╔════╝██╔═══██╗██╔════╝██╔════╝██╔════╝██╔═══██╗██╔══██╗██╔══██╗
|
|
|
|
█████╗ ██║ ██║███████╗███████╗██║ ██║ ██║██████╔╝██║ ██║
|
|
|
|
██╔══╝ ██║ ██║╚════██║╚════██║██║ ██║ ██║██╔══██╗██║ ██║
|
|
|
|
██║ ╚██████╔╝███████║███████║╚██████╗╚██████╔╝██║ ██║██████╔╝
|
|
|
|
╚═╝ ╚═════╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝
|
2021-10-04 21:01:08 +02:00
|
|
|
|
2021-10-04 22:06:17 +02:00
|
|
|
fosscord-server | ${yellow(
|
|
|
|
`Pre-relase (${
|
|
|
|
commit !== null
|
|
|
|
? commit.slice(0, 7)
|
|
|
|
: "Unknown (Git cannot be found)"
|
|
|
|
})`
|
|
|
|
)}
|
2021-10-04 21:01:08 +02:00
|
|
|
|
2021-10-04 22:06:17 +02:00
|
|
|
Current commit: ${
|
|
|
|
commit !== null
|
|
|
|
? `${cyan(commit)} (${yellow(commit.slice(0, 7))})`
|
|
|
|
: "Unknown (Git cannot be found)"
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
);
|
2021-10-04 21:01:08 +02:00
|
|
|
|
2021-10-04 22:06:17 +02:00
|
|
|
if (commit == null)
|
|
|
|
console.log(yellow(`Warning: Git is not installed or not in PATH.`));
|
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 22:06:17 +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
|
|
|
}
|