[core] run systeminformation in subprocess so the info is always displayed (#4002)

If an error occurs during startup, we request system information from
the user. The problem is that this information is displayed too late,
for example, if the configuration check fails.

My initial idea was to use `await
Utils.logSystemInformation(global.version);`, but this increased the
startup time.

Therefore, the function is now called in a subprocess. This approach
provides the information in all cases and does not increase the startup
time.
This commit is contained in:
Karsten Hassel
2026-01-03 01:14:48 +01:00
committed by GitHub
parent 950f55197e
commit 241921b79c
5 changed files with 48 additions and 41 deletions

View File

@@ -3,6 +3,7 @@ require("./alias-resolver");
const fs = require("node:fs");
const path = require("node:path");
const Spawn = require("node:child_process").spawn;
const envsub = require("envsub");
const Log = require("logger");
@@ -25,7 +26,7 @@ global.mmTestMode = process.env.mmTestMode === "true";
Log.log(`Starting MagicMirror: v${global.version}`);
// Log system information.
Utils.logSystemInformation(global.version);
Spawn("node ./js/systeminformation.js", { cwd: this.root_path, shell: true, detached: true, stdio: "inherit" });
if (process.env.MM_CONFIG_FILE) {
global.configuration_file = process.env.MM_CONFIG_FILE.replace(`${global.root_path}/`, "");

39
js/systeminformation.js Normal file
View File

@@ -0,0 +1,39 @@
const os = require("node:os");
const si = require("systeminformation");
// needed with relative path because logSystemInformation is called in an own process in app.js:
const mmVersion = require("../package").version;
const Log = require("./logger");
const logSystemInformation = async () => {
try {
const system = await si.system();
const osInfo = await si.osInfo();
const versions = await si.versions();
const usedNodeVersion = process.version.replace("v", "");
const installedNodeVersion = versions.node;
const totalRam = (os.totalmem() / 1024 / 1024).toFixed(2);
const freeRam = (os.freemem() / 1024 / 1024).toFixed(2);
const usedRam = ((os.totalmem() - os.freemem()) / 1024 / 1024).toFixed(2);
let systemDataString = [
"\n#### System Information ####",
`- SYSTEM: manufacturer: ${system.manufacturer}; model: ${system.model}; virtual: ${system.virtual}; MM: v${mmVersion}`,
`- OS: platform: ${osInfo.platform}; distro: ${osInfo.distro}; release: ${osInfo.release}; arch: ${osInfo.arch}; kernel: ${versions.kernel}`,
`- VERSIONS: electron: ${process.versions.electron}; used node: ${usedNodeVersion}; installed node: ${installedNodeVersion}; npm: ${versions.npm}; pm2: ${versions.pm2}`,
`- ENV: XDG_SESSION_TYPE: ${process.env.XDG_SESSION_TYPE}; MM_CONFIG_FILE: ${process.env.MM_CONFIG_FILE}`,
` WAYLAND_DISPLAY: ${process.env.WAYLAND_DISPLAY}; DISPLAY: ${process.env.DISPLAY}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`,
`- RAM: total: ${totalRam} MB; free: ${freeRam} MB; used: ${usedRam} MB`,
`- OTHERS: uptime: ${Math.floor(os.uptime() / 60)} minutes; timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}`
].join("\n");
Log.info(systemDataString);
// Return is currently only for tests
return systemDataString;
} catch (error) {
Log.error(error);
}
};
module.exports = logSystemInformation;
logSystemInformation();

View File

@@ -1,6 +1,4 @@
const os = require("node:os");
const fs = require("node:fs");
const si = require("systeminformation");
const Log = require("logger");
const modulePositions = []; // will get list from index.html
@@ -10,37 +8,6 @@ const discoveredPositionsJSFilename = "js/positions.js";
module.exports = {
async logSystemInformation (mirrorVersion) {
try {
const system = await si.system();
const osInfo = await si.osInfo();
const versions = await si.versions();
const usedNodeVersion = process.version.replace("v", "");
const installedNodeVersion = versions.node;
const totalRam = (os.totalmem() / 1024 / 1024).toFixed(2);
const freeRam = (os.freemem() / 1024 / 1024).toFixed(2);
const usedRam = ((os.totalmem() - os.freemem()) / 1024 / 1024).toFixed(2);
let systemDataString = [
"\n#### System Information ####",
`- SYSTEM: manufacturer: ${system.manufacturer}; model: ${system.model}; virtual: ${system.virtual}; MM: ${mirrorVersion}`,
`- OS: platform: ${osInfo.platform}; distro: ${osInfo.distro}; release: ${osInfo.release}; arch: ${osInfo.arch}; kernel: ${versions.kernel}`,
`- VERSIONS: electron: ${process.versions.electron}; used node: ${usedNodeVersion}; installed node: ${installedNodeVersion}; npm: ${versions.npm}; pm2: ${versions.pm2}`,
`- ENV: XDG_SESSION_TYPE: ${process.env.XDG_SESSION_TYPE}; MM_CONFIG_FILE: ${process.env.MM_CONFIG_FILE}`,
` WAYLAND_DISPLAY: ${process.env.WAYLAND_DISPLAY}; DISPLAY: ${process.env.DISPLAY}; ELECTRON_ENABLE_GPU: ${process.env.ELECTRON_ENABLE_GPU}`,
`- RAM: total: ${totalRam} MB; free: ${freeRam} MB; used: ${usedRam} MB`,
`- OTHERS: uptime: ${Math.floor(os.uptime() / 60)} minutes; timeZone: ${Intl.DateTimeFormat().resolvedOptions().timeZone}`
].join("\n");
Log.info(systemDataString);
// Return is currently only for tests
return systemDataString;
} catch (error) {
Log.error(error);
}
},
// return all available module positions
getAvailableModulePositions () {
return modulePositions;

View File

@@ -0,0 +1,7 @@
const SystemInformation = require("../../../js/systeminformation");
describe("SystemInformation", () => {
it("should output system information", async () => {
await expect(SystemInformation()).resolves.toContain("platform: linux");
});
});

View File

@@ -1,7 +0,0 @@
const Utils = require("../../../js/utils");
describe("Utils", () => {
it("should output system information", async () => {
await expect(Utils.logSystemInformation()).resolves.toContain("platform: linux");
});
});