Unitech / Unitech/pm2

App runs fine when launced from Node directly but not `pm2 start`

Open
#5,518 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What's going wrong?

Suddenly I got this problem on a new server with one app. The app runs fine if launched directly:

node ./bin/www

But if I tried:

pm2 start ./bin/www --name FEX

the app doesn't seem to start. The memory column in pm2 list shows 0mb for all apps. pm2 log shows an empty log, not even a single line of error.

I have two other apps launched via pm2 and those are fine. They also show 0mb, but otherwise performs normally, when FEX is started.

What could be the cause?

This app has been running fine for many years on another server. I have just migrated it to a new server and this problem suddenly appeared.

There are three Node apps on this server. Two launched with pm2 are working fine. It is just this FEX app that is problematic. The other two apps are located in the home directory of the running user. The FEX is in another user's home directory, but the permissions are assigned and it can run if launched directly from Node.

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Wed Jan 11 2023 09:07:54 GMT+0800
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.2.2
node version         : 18.12.1
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : pi
uid                  : 1002
gid                  : 1003
uptime               : 610min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.2.2
node version         : 18.12.1
node path            : /usr/bin/pm2
argv                 : /usr/bin/node,/usr/bin/pm2,report
argv0                : node
user                 : pi
uid                  : 1002
gid                  : 1003
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Xeon(R) CPU @ 2.20GHz
cpus nb              : 2
freemem              : 476426240
totalmem             : 1012875264
home                 : /home/pi
===============================================================================
--- PM2 list -----------------------------------------------
┌──────────────────────────────────────────────────────────────────────────────
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├──────────────────────────────────────────────────────────────────────────────
│ 1  │ qty                │ fork     │ 0    │ online    │ 0.2%     │ 77.9mb   │
│ 0  │ payn               │ fork     │ 0    │ online    │ 0.3%     │ 71.8mb   │
└──────────────────────────────────────────────────────────────────────────────
===============================================================================
--- Daemon logs --------------------------------------------
/home/pi/.pm2/pm2.log last 20 lines:
PM2        | 2023-01-11T08:55:47: PM2 log: Stopping app:FEX id:4
PM2        | 2023-01-11T08:55:47: PM2 error: app=FEXid=4 does not have a pid
PM2        | 2023-01-11T08:56:02: PM2 log: App [FEX:5] starting in -fork mode-
PM2        | 2023-01-11T08:56:02: PM2 log: App [FEX:5] online
PM2        | 2023-01-11T08:56:02: PM2 error: Error: spawn node EACCES
PM2        |     at ChildProcess._handle.onexit (node:internal/child_process:283:19)
PM2        |     at onErrorNT (node:internal/child_process:476:16)
PM2        |     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
PM2        | 2023-01-11T08:56:02: PM2 error: Error caught while calling pidusage
PM2        | 2023-01-11T08:56:02: PM2 error: TypeError: One of the pids provided is invalid
PM2        | 2023-01-11T08:56:12: PM2 error: Error caught while calling pidusage
PM2        | 2023-01-11T08:56:12: PM2 error: TypeError: One of the pids provided is invalid
PM2        | 2023-01-11T08:56:15: PM2 error: Error caught while calling pidusage
PM2        | 2023-01-11T08:56:15: PM2 error: TypeError: One of the pids provided is invalid
PM2        | 2023-01-11T08:56:15: PM2 error: Error caught while calling pidusage
PM2        | 2023-01-11T08:56:15: PM2 error: TypeError: One of the pids provided is invalid
PM2        | 2023-01-11T08:56:23: PM2 error: Error caught while calling pidusage
PM2        | 2023-01-11T08:56:23: PM2 error: TypeError: One of the pids provided is invalid
PM2        | 2023-01-11T08:56:23: PM2 log: Stopping app:FEX id:5
PM2        | 2023-01-11T08:56:23: PM2 error: app=FEX id=5 does not have a pid

pm2 show FEX for one of the times I tried is:

┌───────────────────┬───────────────────────────────────┐
│ status            │ online                            │
│ name              │ FEX                               │
│ namespace         │ default                           │
│ version           │ N/A                               │
│ restarts          │ 0                                 │
│ uptime            │ 5s                                │
│ script path       │ /home/fex/bin/www                 │
│ script args       │ N/A                               │
│ error log path    │ /home/pi/.pm2/logs/FEX-error.log  │
│ out log path      │ /home/pi/.pm2/logs/FEX-out.log    │
│ pid path          │ /home/pi/.pm2/pids/FEX-7.pid      │
│ interpreter       │ node                              │
│ interpreter args  │ N/A                               │
│ script id         │ 7                                 │
│ exec cwd          │ /home/fex                         │
│ exec mode         │ fork_mode                         │
│ node.js version   │ N/A                               │
│ node env          │ N/A                               │
│ watch & reload    │ ✘                                 │
│ unstable restarts │ 0                                 │
│ created at        │ 2023-01-11T01:49:57.588Z          │
└───────────────────┴───────────────────────────────────┘

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing pm2 start ./bin/www --name FEX and inspect the PM2 daemon log at /home/pi/.pm2/pm2.log, especially the spawn node EACCES and invalid-pid errors. The issue names no source file or test; done would require identifying the failure path and defining a verified fix for this launch scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.