mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
updatenotification: update_helper.js recode with pm2 library (v2.27.x) (#3332)
#3285 Because there is so many conflit with package, I have rewrite the code with v2.27.0-develop For remember: * recode: `update_helper.js` with `pm2` library * fix: default config -> `updates` is a array * delete: `command-exists` library (not used) * delete: `PM2_GetList()` function (not used) * add: check `updates.length` (prevent crash) * add: `[PM2]` tag in log (for better visibility) * add: `pm2` library advantage: * we use the pm2 library directly * avoids weird returns from child_process.exec when requesting a json format from pm2 * simplified the code inconvenient: * we have vulnerabilities with axios 240120 Fix: * use `pm2_env.pm_cwd` instead of `pm2_env.PWD` : prevent using `pm2 restart <id> --update-env` in other directory (for enable GPU rendering for exemple) * resolve packages (again)
This commit is contained in:
parent
995b61b689
commit
c96ced9137
2
.github/workflows/depsreview.yaml
vendored
2
.github/workflows/depsreview.yaml
vendored
@ -16,3 +16,5 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
- name: "Dependency Review"
|
||||
uses: actions/dependency-review-action@v3
|
||||
with:
|
||||
allow-ghsas: GHSA-wf5p-g6vw-rhxx
|
||||
|
@ -15,6 +15,7 @@ _This release is scheduled to be released on 2024-04-01._
|
||||
|
||||
### Updated
|
||||
|
||||
- Update updatenotification (update_helper.js): Recode with pm2 library (#3332)
|
||||
- Removing lodash dependency by replacing merge by spread operator (#3339)
|
||||
- Use node prefix for build-in modules (#3340)
|
||||
- Rework logging colors (#3350)
|
||||
|
@ -1,6 +1,7 @@
|
||||
const Exec = require("node:child_process").exec;
|
||||
const Spawn = require("node:child_process").spawn;
|
||||
const commandExists = require("command-exists");
|
||||
const pm2 = require("pm2");
|
||||
|
||||
const Log = require("logger");
|
||||
|
||||
/* class Updater
|
||||
@ -138,7 +139,7 @@ class Updater {
|
||||
// restart MagicMiror with "pm2"
|
||||
pm2Restart () {
|
||||
Log.info("updatenotification: PM2 will restarting MagicMirror...");
|
||||
Exec(`pm2 restart ${this.PM2}`, (err, std, sde) => {
|
||||
pm2.restart(this.PM2, (err, proc) => {
|
||||
if (err) {
|
||||
Log.error("updatenotification:[PM2] restart Error", err);
|
||||
}
|
||||
@ -159,53 +160,35 @@ class Updater {
|
||||
check_PM2_Process () {
|
||||
Log.info("updatenotification: Checking PM2 using...");
|
||||
return new Promise((resolve) => {
|
||||
commandExists("pm2")
|
||||
.then(async () => {
|
||||
var PM2_List = await this.PM2_GetList();
|
||||
if (!PM2_List) {
|
||||
pm2.connect((err) => {
|
||||
if (err) {
|
||||
Log.error("updatenotification: [PM2]", err);
|
||||
this.usePM2 = false;
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
pm2.list((err, list) => {
|
||||
if (err) {
|
||||
Log.error("updatenotification: [PM2] Can't get process List!");
|
||||
this.usePM2 = false;
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
PM2_List.forEach((pm) => {
|
||||
if (pm.pm2_env.version === this.version && pm.pm2_env.status === "online" && pm.pm2_env.PWD.includes(this.root_path)) {
|
||||
list.forEach((pm) => {
|
||||
if (pm.pm2_env.version === this.version && pm.pm2_env.status === "online" && pm.pm2_env.pm_cwd.includes(`${this.root_path}/`)) {
|
||||
this.PM2 = pm.name;
|
||||
this.usePM2 = true;
|
||||
Log.info("updatenotification: You are using pm2 with", this.PM2);
|
||||
Log.info("updatenotification: [PM2] You are using pm2 with", this.PM2);
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
pm2.disconnect();
|
||||
if (!this.PM2) {
|
||||
Log.info("updatenotification: You are not using pm2");
|
||||
Log.info("updatenotification: [PM2] You are not using pm2");
|
||||
this.usePM2 = false;
|
||||
resolve(false);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
Log.info("updatenotification: You are not using pm2");
|
||||
this.usePM2 = false;
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Get the list of pm2 process
|
||||
PM2_GetList () {
|
||||
return new Promise((resolve) => {
|
||||
Exec("pm2 jlist", (err, std, sde) => {
|
||||
if (err) {
|
||||
resolve(null);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let result = JSON.parse(std);
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
Log.error("updatenotification: [PM2] can't GetList!");
|
||||
Log.debug("updatenotification: [PM2] GetList is not an JSON format", e);
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -218,7 +201,7 @@ class Updater {
|
||||
|
||||
// search update module command
|
||||
applyCommand (module) {
|
||||
if (this.isMagicMirror(module.module)) return null;
|
||||
if (this.isMagicMirror(module.module) || !this.updates.length) return null;
|
||||
let command = null;
|
||||
this.updates.forEach((updater) => {
|
||||
if (updater[module]) command = updater[module];
|
||||
|
@ -18,7 +18,7 @@ Module.register("updatenotification", {
|
||||
suspended: false,
|
||||
moduleList: {},
|
||||
needRestart: false,
|
||||
updates: {},
|
||||
updates: [],
|
||||
|
||||
start () {
|
||||
Log.info(`Starting module: ${this.name}`);
|
||||
|
1093
package-lock.json
generated
1093
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -72,7 +72,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"ansis": "^2.0.3",
|
||||
"command-exists": "^1.2.9",
|
||||
"console-stamp": "^3.1.2",
|
||||
"envsub": "^4.1.0",
|
||||
"eslint": "^8.56.0",
|
||||
@ -85,6 +84,7 @@
|
||||
"module-alias": "^2.2.3",
|
||||
"moment": "^2.30.1",
|
||||
"node-ical": "^0.17.1",
|
||||
"pm2": "^5.3.0",
|
||||
"socket.io": "^4.7.4",
|
||||
"systeminformation": "^5.21.22"
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user