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] Fix pm2 using detection when pm2 script is in MagicMirror root folder #3576

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

bugsounet
Copy link
Contributor

I discover this bug:

When pm2 sh script is on MagicMirror root folder, updatenotification is not able to detect pm2 using

0|MagicMirror  | [2024-10-02 17:23:09.215] [DEBUG]   Version Compare: 2.30.0-develop 2.30.0-develop --> true 
0|MagicMirror  | [2024-10-02 17:23:09.216] [DEBUG]   Status: online 
0|MagicMirror  | [2024-10-02 17:23:09.216] [DEBUG]   PM2 MagicMirror starting  from Path: /home/bugsounet/MagicMirror-dev 
0|MagicMirror  | [2024-10-02 17:23:09.216] [DEBUG]   MagicMirror Path /home/bugsounet/MagicMirror-dev/
0|MagicMirror  | [2024-10-02 17:23:09.216] [DEBUG]   Compare: false
0|MagicMirror  | [2024-10-02 17:23:09.216] [INFO]  updatenotification: [PM2] You are not using pm2 

@khassel khassel merged commit ee98a0c into MagicMirrorOrg:develop Oct 2, 2024
5 of 8 checks passed
@bugsounet bugsounet deleted the updatenotification branch October 11, 2024 09:19
@FrankBlackMG
Copy link

This change didn't work for me since my cwd in PM2 is different from my MagicMirror path. It didn't work previous to the fix either. The change below works for my setup and appears to be a solid way for a process to determine if it's managed by PM2. My only concern is that I'm not sure when unique_id was implemented in PM2.

//if (pm.pm2_env.version === this.version && pm.pm2_env.status === "online" && pm.pm2_env.pm_cwd.includes(`${this.root_path}`)) {

if (process.env.unique_id !== undefined && process.env.unique_id === pm.pm2_env.unique_id) {

@sdetweil
Copy link
Collaborator

sdetweil commented Oct 25, 2024

I think the better path is to put a linked file in the MM folder and have pm2 use that.

see the ln command

otherwise there is no way for us to know its related to MagicMirror

look at the info output from
pm2 info x
where x is the name or number of the app being managed

otherwise I think an optional parm to the updateNotification module is the only other way out..

tell us the name of the pm2 app.

my MMM-Config module also depends on the app path being inside the MM folder.

@FrankBlackMG
Copy link

unique_id is a GUID injected by PM2. It's in the process of MagicMirror where you are making the call to the PM2 API and it's also in the environment section of the pm object (pm.pm2_env.unique_id) when iterating over the list of PM2 managed processes. That seems definitive unless I'm missing something. I do think a linked file would work nicely, but it's something that has to be done rather than just making a simple code change. I dumped the whole env json from each pm object in the PM2 list and you can see all of the package.json vars e.g. name=magicmirror or the repository.url being "https://github.com/MagicMirrorOrg/MagicMirror" so those could be checked as well if you didn't trust the GUID match check.

@bugsounet
Copy link
Contributor Author

@FrankBlackMG Thanks for this purpose, il will inspect

rejas pushed a commit that referenced this pull request Oct 28, 2024
…e or outside MagicMirror root folder (#3605)

This will fix #3576 

@FrankBlackMG: 

I don't use `*env.unique_id` because some others modules can use pm2 too
for starting a service and unique_id is the same (this will make
confusion)
So I check `name` and `pm_id` for found it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants