-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_helper.bk
More file actions
40 lines (33 loc) · 1.4 KB
/
node_helper.bk
File metadata and controls
40 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const NodeHelper = require("node_helper");
const { exec } = require("child_process");
module.exports = NodeHelper.create({
start() {
console.log("MMM-ProcessStatus helper started");
},
socketNotificationReceived(notification, payload) {
if (notification === "CHECK_PROCESS") {
let results = [];
// Loop through each process and check the status
payload.processNames.forEach((processName) => {
const command = payload.checkCommand || `pgrep -x "${processName}"`;
exec(command, (error, stdout, stderr) => {
let status = "stopped"; // Default status
if (error || stderr) {
console.error(`Error checking ${processName}: ${error || stderr}`);
} else if (stdout.trim() !== "") {
status = "running";
}
// Store result for the current process
results.push({
processName,
status
});
// Once all processes are checked, send results back
if (results.length === payload.processNames.length) {
this.sendSocketNotification("PROCESS_STATUS", results);
}
});
});
}
}
});