Pm2: Node args not preserved when restarting app with pm2 restart <app>

Created on 16 Nov 2018  Β·  6Comments  Β·  Source: Unitech/pm2

This issue only manifests in version 3.2.X, (only checked with node 10.X)

What's going wrong?

node-args not preserved on pm2 restart

How could we reproduce this issue?

// pm2dummy.js
let i = 0;
setInterval(() => {
  console.log(i++);
  if (i === 5) {
    process.exit(1);
  }
}, 1000);

pm2 start pm2dummy.js --node-args "--max-old-space-size=1000"

Do pm2 restart pm2dummy, then pm2 show pm2dummy

Should display

interpreter args | --max-old-space-size=1000

Instead display

interpreter args | N/A

Supporting information

===============================================================================
--- PM2 REPORT (Fri Nov 16 2018 09:38:50 GMT-0800 (Pacific Standard Time)) ----
===============================================================================
--- Daemon --------------------------------------------------------------------
pm2d version         : 3.2.0
node version         : 10.13.0
node path            : /home/peter.parkour/.nvm/versions/node/v10.13.0/bin/pm2
argv                 : /home/peter.parkour/.nvm/versions/node/v10.13.0/bin/node,/home/peter.parkour/.nvm/versions/node/v10.13.0/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : peter.parkour
uid                  : 1000
gid                  : 1000
uptime               : 32min
===============================================================================
--- CLI -----------------------------------------------------------------------
local pm2            : 3.2.0
node version         : 10.13.0
node path            : /home/peter.parkour/.nvm/versions/node/v10.13.0/bin/pm2
argv                 : /home/peter.parkour/.nvm/versions/node/v10.13.0/bin/node,/home/peter.parkour/.nvm/versions/node/v10.13.0/bin/pm2,report
argv0                : node
user                 : peter.parkour
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info ---------------------------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
cpus nb              : 8
freemem              : 1038581760
totalmem             : 16731594752
home                 : /home/peter.parkour
===============================================================================
--- PM2 list ------------------------------------------------------------------
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ App name β”‚ id β”‚ version β”‚ mode β”‚ pid   β”‚ status β”‚ restart β”‚ uptime β”‚ cpu β”‚ mem       β”‚ user β”‚ watching β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ pm2dummy β”‚ 0  β”‚ N/A     β”‚ fork β”‚ 30206 β”‚ online β”‚ 91      β”‚ 1s     β”‚ 0%  β”‚ 34.8 MB   β”‚ peter.parkour β”‚ disabled β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
===============================================================================

Most helpful comment

Fixed in pm2 2.3.3:

npm install pm2@latest -g
pm2 update

https://github.com/Unitech/pm2/commit/213f48641beedd1a9b84f74a0f9d963a114eea14

All 6 comments

Yes, I have the following process.yml file, node_args and watch are not preserved anymore between process restarts.

apps:
  - script    : app.js
    name      : web
    exec_mode : fork
    # instances : 0
    watch     : true
    ignore_watch :
      - 'node_modules'
      - 'logs'
    node_args : '--inspect=5858'
    env       :
      NODE_ENV: "development"
  - script    : scripts/cron-download-pixart.js
    name      : download
    exec_mode : fork
    watch     : true
    ignore_watch :
      - 'node_modules'
      - 'logs'
    node_args : '--inspect=5859'
    env       :
      NODE_ENV: "development"

Actually, watch is only lost when stopping and starting, not on restart.

I believe I've isolated the issue down to this commit

https://github.com/Unitech/pm2/commit/ccb35ef8ca437043f84f3651e0fc56534d37a143

npm install -g https://github.com/Unitech/pm2#ccb35ef

pm2 restart does not preserve the args

but the previous commit is fine

npm install -g https://github.com/Unitech/pm2#b4708e7

Both versions 3.1.3

@andy-ganchrow your PR solves the issue, I don't know if there's a better way to go about it though.

For one, the issue with watching persists, and by the way also for some reason also the execution mode always goes back to cluster for me, even if in the configuration it was fork. I think there's some bigger problem where the configuration is not loaded properly somehow or is overwritten by the the execution of pm2 itself.

Thanks @mcdado

I don’t know the pm2 code well at all so I was just doing console.log at different places in the infected commit until I saw the arguments disappear. My hope was the PR fixes this one issue without side effects. And I’m assuming if it does the watch issue won’t be hard to fix

Fixed in pm2 2.3.3:

npm install pm2@latest -g
pm2 update

https://github.com/Unitech/pm2/commit/213f48641beedd1a9b84f74a0f9d963a114eea14

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lefam picture lefam  Β·  3Comments

FujiHaruka picture FujiHaruka  Β·  3Comments

cchan picture cchan  Β·  3Comments

getvega picture getvega  Β·  3Comments

morfies picture morfies  Β·  3Comments