WIP logo/terminal stuff

This commit is contained in:
Emma [it/its]@Rory&
2024-10-27 23:30:14 +01:00
committed by Rory&
parent 3f7d26118d
commit bd81cde977
15 changed files with 1552 additions and 26 deletions
+1 -1
View File
@@ -91,7 +91,7 @@ async function main() {
Sentry.errorHandler(app);
console.log(`[Server] ${green(`listening on port ${bold(port)}`)}`);
console.log(`[Server] ${green(`Listening on port ${bold(port)}`)}`);
}
main().catch(console.error);
+17 -18
View File
@@ -18,6 +18,7 @@
// process.env.MONGOMS_DEBUG = "true";
import moduleAlias from "module-alias";
moduleAlias(__dirname + "../../../package.json");
import "reflect-metadata";
@@ -26,8 +27,10 @@ import os from "os";
import { red, bold, yellow, cyan } from "picocolors";
import { initStats } from "./stats";
import { config } from "dotenv";
config();
import { execSync } from "child_process";
import { centerString, Logo } from "@spacebar/util";
const cores = process.env.THREADS ? parseInt(process.env.THREADS) : 1;
@@ -41,23 +44,19 @@ function getCommitOrFail() {
if (cluster.isPrimary) {
const commit = getCommitOrFail();
Logo.printLogo();
console.log(
bold(`
███████╗██████╗ █████╗ ██████╗███████╗██████╗ █████╗ ██████╗
██╔════╝██╔══██╗██╔══██╗██╔════╝██╔════╝██╔══██╗██╔══██╗██╔══██╗
███████╗██████╔╝███████║██║ █████╗ ██████╔╝███████║██████╔╝
╚════██║██╔═══╝ ██╔══██║██║ ██╔══╝ ██╔══██╗██╔══██║██╔══██╗
███████║██║ ██║ ██║╚██████╗███████╗██████╔╝██║ ██║██║ ██║
╚══════╝╚═╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
spacebar-server | ${yellow(
`Pre-release (${
commit !== null
? commit.slice(0, 7)
: "Unknown (Git cannot be found)"
})`,
)}
${centerString(
`spacebar-server | ${yellow(
`Pre-release (${
commit !== null
? commit.slice(0, 7)
: "Unknown (Git cannot be found)"
})`,
)}`,
64,
)}
Commit Hash: ${
commit !== null
@@ -74,7 +73,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)
initStats();
console.log(`[Process] starting with ${cores} threads`);
console.log(`[Process] Starting with ${cores} threads`);
if (cores === 1) {
require("./Server");
@@ -87,7 +86,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)
const delay = process.env.DATABASE?.includes("://") ? 0 : i * 1000;
setTimeout(() => {
cluster.fork();
console.log(`[Process] worker ${cyan(i)} started.`);
console.log(`[Process] Worker ${cyan(i)} started.`);
}, delay);
}
@@ -102,7 +101,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).)
cluster.on("exit", (worker) => {
console.log(
`[Worker] ${red(
`died with PID: ${worker.process.pid} , restarting ...`,
`PID ${worker.process.pid} died, restarting ...`,
)}`,
);
cluster.fork();
+31 -5
View File
@@ -18,18 +18,44 @@
import os from "os";
import osu from "node-os-utils";
import { readFileSync } from "node:fs";
import { red } from "picocolors";
export function initStats() {
console.log(`[Path] running in ${__dirname}`);
console.log(`[Path] Running in ${process.cwd()}`);
console.log(`[Path] Running from ${__dirname}`);
try {
console.log(`[CPU] ${osu.cpu.model()} Cores x${osu.cpu.count()}`);
console.log(`[CPU] ${osu.cpu.model()} (x${osu.cpu.count()})`);
} catch {
console.log("[CPU] Failed to get cpu model!");
console.log("[CPU] Failed to get CPU model!");
}
console.log(`[System] ${os.platform()} ${os.arch()}`);
console.log(`[Process] running with PID: ${process.pid}`);
console.log(`[System] ${os.platform()} ${os.release()} ${os.arch()}`);
if (os.platform() == "linux") {
try {
const osReleaseLines = readFileSync(
"/etc/os-release",
"utf8",
).split("\n");
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
const osRelease: any = {};
for (const line of osReleaseLines) {
if (!line) continue;
const [key, value] = line.match(/(.*?)="?([^"]*)"?/)!.slice(1);
osRelease[key] = value;
}
console.log(
`[System]\x1b[${osRelease.ANSI_COLOR}m ${osRelease.NAME ?? "Unknown"} ${osRelease.VERSION ?? "Unknown"} (${osRelease.BUILD_ID ?? "No build ID"})\x1b[0m`,
);
} catch (e) {
console.log(
"[System] Unknown Linux distribution (missing /etc/os-release)",
);
console.log(e);
}
}
console.log(`[Process] Running with PID: ${process.pid}`);
if (process.getuid && process.getuid() === 0) {
console.warn(
red(