mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-12-12 09:52:37 +00:00
logger: add calling filename as prefix on server side (#3926)
This commit is contained in:
@@ -51,7 +51,7 @@ class Updater {
|
||||
this.PM2Id = null; // pm2 process number
|
||||
this.version = global.version;
|
||||
this.root_path = global.root_path;
|
||||
Log.info("[updatenotification] Updater Class Loaded!");
|
||||
Log.info("Updater Class Loaded!");
|
||||
}
|
||||
|
||||
// [main command] parse if module update is needed
|
||||
@@ -81,7 +81,7 @@ class Updater {
|
||||
|
||||
await Promise.all(parser);
|
||||
let updater = Object.values(this.moduleList);
|
||||
Log.debug("[updatenotification] Update Result:", updater);
|
||||
Log.debug("Update Result:", updater);
|
||||
return updater;
|
||||
}
|
||||
|
||||
@@ -107,24 +107,24 @@ class Updater {
|
||||
if (module.updateCommand) {
|
||||
Command = module.updateCommand;
|
||||
} else {
|
||||
Log.warn(`[updatenotification] Update of ${module.name} is not supported.`);
|
||||
Log.warn(`Update of ${module.name} is not supported.`);
|
||||
return Result;
|
||||
}
|
||||
Log.info(`[updatenotification] Updating ${module.name}...`);
|
||||
Log.info(`Updating ${module.name}...`);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
Exec(Command, { cwd: modulePath, timeout: this.timeout }, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
Log.error(`[updatenotification] exec error: ${error}`);
|
||||
Log.error(`exec error: ${error}`);
|
||||
Result.error = true;
|
||||
} else {
|
||||
Log.info(`[updatenotification]:Update logs of ${module.name}: ${stdout}`);
|
||||
Log.info(`Update logs of ${module.name}: ${stdout}`);
|
||||
Result.updated = true;
|
||||
if (this.autoRestart) {
|
||||
Log.info("[updatenotification] Update done");
|
||||
Log.info("Update done");
|
||||
setTimeout(() => this.restart(), 3000);
|
||||
} else {
|
||||
Log.info("[updatenotification] Update done, don't forget to restart MagicMirror!");
|
||||
Log.info("Update done, don't forget to restart MagicMirror!");
|
||||
Result.needRestart = true;
|
||||
}
|
||||
}
|
||||
@@ -141,18 +141,18 @@ class Updater {
|
||||
|
||||
// restart MagicMirror with "pm2": use PM2Id for restart it
|
||||
pm2Restart () {
|
||||
Log.info("[updatenotification] [PM2] restarting MagicMirror...");
|
||||
Log.info("[PM2] restarting MagicMirror...");
|
||||
const pm2 = require("pm2");
|
||||
pm2.restart(this.PM2Id, (err, proc) => {
|
||||
if (err) {
|
||||
Log.error("[updatenotification] [PM2] restart Error", err);
|
||||
Log.error("[PM2] restart Error", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// restart MagicMirror with "node --run start"
|
||||
nodeRestart () {
|
||||
Log.info("[updatenotification] Restarting MagicMirror...");
|
||||
Log.info("Restarting MagicMirror...");
|
||||
const out = process.stdout;
|
||||
const err = process.stderr;
|
||||
const subprocess = Spawn("node --run start", { cwd: this.root_path, shell: true, detached: true, stdio: ["ignore", out, err] });
|
||||
@@ -162,49 +162,49 @@ class Updater {
|
||||
|
||||
// Check using pm2
|
||||
check_PM2_Process () {
|
||||
Log.info("[updatenotification] Checking PM2 using...");
|
||||
Log.info("Checking PM2 using...");
|
||||
return new Promise((resolve) => {
|
||||
if (fs.existsSync("/.dockerenv")) {
|
||||
Log.info("[updatenotification] Running in docker container, not using PM2 ...");
|
||||
Log.info("[PM2] Running in docker container, not using PM2 ...");
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (process.env.unique_id === undefined) {
|
||||
Log.info("[updatenotification] [PM2] You are not using pm2");
|
||||
Log.info("[PM2] You are not using pm2");
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.debug(`[updatenotification] [PM2] Search for pm2 id: ${process.env.pm_id} -- name: ${process.env.name} -- unique_id: ${process.env.unique_id}`);
|
||||
Log.debug(`[PM2] Search for pm2 id: ${process.env.pm_id} -- name: ${process.env.name} -- unique_id: ${process.env.unique_id}`);
|
||||
|
||||
const pm2 = require("pm2");
|
||||
pm2.connect((err) => {
|
||||
if (err) {
|
||||
Log.error("[updatenotification] [PM2]", err);
|
||||
Log.error("[PM2]", err);
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
pm2.list((err, list) => {
|
||||
if (err) {
|
||||
Log.error("[updatenotification] [PM2] Can't get process List!");
|
||||
Log.error("[PM2] Can't get process List!");
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
list.forEach((pm) => {
|
||||
Log.debug(`[updatenotification] [PM2] found pm2 process id: ${pm.pm_id} -- name: ${pm.name} -- unique_id: ${pm.pm2_env.unique_id}`);
|
||||
Log.debug(`[PM2] found pm2 process id: ${pm.pm_id} -- name: ${pm.name} -- unique_id: ${pm.pm2_env.unique_id}`);
|
||||
if (pm.pm2_env.status === "online" && process.env.name === pm.name && +process.env.pm_id === +pm.pm_id && process.env.unique_id === pm.pm2_env.unique_id) {
|
||||
this.PM2Id = pm.pm_id;
|
||||
this.usePM2 = true;
|
||||
Log.info(`[updatenotification] [PM2] You are using pm2 with id: ${this.PM2Id} (${pm.name})`);
|
||||
Log.info(`[PM2] You are using pm2 with id: ${this.PM2Id} (${pm.name})`);
|
||||
resolve(true);
|
||||
} else {
|
||||
Log.debug(`[updatenotification] [PM2] pm2 process id: ${pm.pm_id} don't match...`);
|
||||
Log.debug(`[PM2] pm2 process id: ${pm.pm_id} don't match...`);
|
||||
}
|
||||
});
|
||||
pm2.disconnect();
|
||||
if (!this.usePM2) {
|
||||
Log.info("[updatenotification] [PM2] You are not using pm2");
|
||||
Log.info("[PM2] You are not using pm2");
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user