"pm2 update" never ends when running it from a bash script
What's going wrong?
I'm running a script that install/updates many things including PM2, but when I try to update it. the script just freezes and I had to manually terminate it.
However, when I run the same commands directly on the terminal, it works fine.
How could we reproduce this issue?
Create a script with the following content:
npm install pm2@latest -g
pm2 update
And run it from the console
sudo bash that_script.sh
Having pm2 already installed, we update it and we end up having a different version on the local computer and on memory. the pm2 update doesn't finish.
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Fri Feb 26 2021 15:34:51 GMT-0300 (Uruguay Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 4.5.4
node version : 12.20.1
node path : not found
argv : /usr/bin/node,/usr/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : root
uid : 0
gid : 0
uptime : 333min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 4.5.5
node version : 12.21.0
node path : /usr/bin/pm2
argv : /usr/bin/node,/usr/bin/pm2,report
argv0 : node
user : root
uid : 0
gid : 0
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
cpus nb : 6
freemem : 683810816
totalmem : 6222090240
home : /root
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼───────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ bacon_health_check │ default │ 1.0.0 │ fork │ 53344 │ 4m │ 0 │ online │ 0% │ 46.3mb │ root │ disabled │
└─────┴───────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/root/.pm2/pm2.log last 20 lines:
PM2 | 2021-02-26T15:30:05: PM2 log: Stopping app:bacon_health_check id:0
PM2 | 2021-02-26T15:30:05: PM2 log: App [bacon_health_check:0] exited with code [0] via signal [SIGINT]
PM2 | 2021-02-26T15:30:05: PM2 log: pid=923 msg=process killed
PM2 | 2021-02-26T15:30:05: PM2 log: App [bacon_health_check:0] starting in -fork mode-
PM2 | 2021-02-26T15:30:06: PM2 log: App [bacon_health_check:0] online
Does anybody know why this is happening?
Thanks in advance!!
Happening to me too. I have to kill the older process and the update then proceeds.
It's like the older process is blocking the update.
Super annoying when you have 1000's of machines.
Somehow, on the same underlying image, it works occasionally, but it gets stuck on most.
I have the same issue, I used pm2 with systemd, and when I do pm2 update sometimes freezes and sometimes not. In the meantime, the pm2 systemd daemon is down.
These are the logs:
Jan 18 07:42:05 instance pm2[7121]: [PM2] [appName](1) ✓
Jan 18 07:42:05 instance pm2[7121]: [PM2] [appName](0) ✓
Jan 18 07:42:05 instance pm2[7121]: [PM2] [v] All Applications Stopped
Jan 18 07:42:06 instance pm2[7121]: [PM2] [v] PM2 Daemon Stopped
Jan 18 07:42:06 instance systemd[196]: pm2.service: Succeeded.
I have this problem too. Is there a workaround to use pm2 update in a shell script so it doesn't hang?
I had same problem to workaround don't use pm2 update instead of that just use npm install pm2@latest -g pm2 stop all pm2 kill pm2 start [process_name]
this approach will be lengthy but will be alternative for pm2 update
Bumping this, as this is quite a major issue in pm2. It causes downtime in production, when updating pm2.