Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updatenotification: update_helper.js recode with pm2 library #3285

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ _This release is scheduled to be released on 2024-01-01._
- Fix #3256 filter out bad results from rrule.between
- Fix calendar events sometimes not respecting deleted events (#3250)
- Fix electron loadurl locally on Windows when address "0.0.0.0" (#2550)
- Fix updatanotification (update_helper.js): catch error if reponse is not an JSON format (check PM2)
- Fix missing typeof in calendar module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deletion of line 45 was not intentional, was it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a oversight when i merged develop into it. will merge develop again now that other PRs got merged and re-add it

- Fix updatanotification (update_helper.js): Recode with pm2 library

## [2.25.0] - 2023-10-01

Expand Down
50 changes: 16 additions & 34 deletions modules/default/updatenotification/update_helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Exec = require("child_process").exec;
const Spawn = require("child_process").spawn;
const commandExists = require("command-exists");
const pm2 = require("pm2");
const Log = require("logger");

/* class Updater
Expand Down Expand Up @@ -138,7 +138,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);
}
Expand All @@ -159,53 +159,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) => {
list.forEach((pm) => {
if (pm.pm2_env.version === this.version && pm.pm2_env.status === "online" && pm.pm2_env.PWD.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);
}
});
});
}
Expand All @@ -218,7 +200,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];
Expand Down
2 changes: 1 addition & 1 deletion modules/default/updatenotification/updatenotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Module.register("updatenotification", {
suspended: false,
moduleList: {},
needRestart: false,
updates: {},
updates: [],

start() {
Log.info(`Starting module: ${this.name}`);
Expand Down
Loading
Loading