From cfd393cf6520260fbb9aead15893b3e4414822a8 Mon Sep 17 00:00:00 2001 From: bugsounet Date: Sat, 9 Nov 2024 12:25:10 +0100 Subject: [PATCH] update pm2 checking --- components/controler.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/components/controler.js b/components/controler.js index e7bba37..f71d3f4 100644 --- a/components/controler.js +++ b/components/controler.js @@ -17,6 +17,13 @@ class Controler { resolve(false); return; } + + if (process.env.unique_id === undefined) { + console.log("[GA] You don't use PM2"); + resolve(false); + return; + } + pm2.list((err, list) => { if (err) { console.error("GA] Can't get pm2 process List!", err); @@ -24,15 +31,15 @@ class Controler { return; } list.forEach((pm) => { - if (pm.pm2_env.status === "online" && process.env.name === pm.name && +process.env.pm_id === +pm.pm_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.usePM2 = true; - this.PM2Process = pm.name; - console.log("[GA] You are using PM2 with", this.PM2Process); + this.PM2Process = pm.pm_id; + console.log(`[GA] You are using pm2 with id: ${this.PM2Process} (${pm.name})`); resolve(true); } }); pm2.disconnect(); - if (!this.PM2Process) { + if (!this.usePM2) { console.log("[GA] You don't use PM2"); resolve(false); }