Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.59k stars 2.62k forks source link

[JS API] `PM2.start` returns empty array, possibly related to caching #5581

Open mikegwhit opened 1 year ago

mikegwhit commented 1 year ago

What's going wrong?

When running PM2 start from the JavaScript API, an empty array is returned with no error. The process does not start, nor is there a record of it using pm2 list. Running PM2 as a different user resolves this. Deleting the PM2 cache using rm -rf ~/.pm2 does not resolve this. Running the PM2 command directly resolves this (instead of via PM2 JS API). Running via CLI resolves this. Killing all processes with pm2 in the name does not resolve this.

/*
    {
      "interpreter": "node",
      "interpreter_args": " \"/home/user/cli.js\" server --trace-warnings --is-daemon=true --daemon-name=payments  ",
      "name": "payments",
      "script": "\"/home/user/cli.js\" server --trace-warnings --is-daemon=true --daemon-name=payments  ",
      "cwd": "/home/user/payments",
      "time": true,
      "output": "/home/user/.logs/payments.log",
      "error": "/home/user/.logs/payments.err.log",
      "exec_mode": "fork",
      "exp_backoff_restart_delay": 100,
      "max_memory_restart": "150M",
      "autorestart": false,
      "restart_delay": 10000,
      "kill_timeout": 10000,
      "shutdown_with_message": false,
      "env": {},
      "instances": 1
    }
*/
pm2.start(options, handler); // returns empty array and no error in handler

However, using the CLI, this works:

pm2 start --name=payments "node \"/home/user/cli.js\" server --trace-warnings --is-daemon=true --daemon-name=payments"

How could we reproduce this issue?

Hard to repro. I imagine this is a caching issue.

Supporting information

v5.1.2 Node v19.5.0

mikegwhit commented 1 year ago

Adding conclusive remarks that, upon trying to run PM2 as multiple different users, this may be related to a file permissions issue on the .logs folder generated. PM2 should throw this error when calling pm2.start.

This use case occurred because user (me) tried to start PM2 from different users for security purposes. Without strictly starting PM2 as one user or another, relied on shared access via linux groups and/or ACL's. I forgot to add the default user to the proper group.

Leaving open for someone else to review, but conclusion is to run: pm2 report

Running pm2 report generates the debug info with the EACCESS error that resolved this. May consider for DX bubbling error to pm2.start API.