I tried a lot of times with differnent combinations but still seems not very stable and smart solution. Hence I am listing some of the logic I can think of something which may be you can apply and monitor the result as you upgrading and writing the scripts.
Basically in my situation we have a bunch of applications running under Node. So things getting complex when you need PM2
to launch anothe application that also installed under Node Version Managers, like NVM
Ex. I have
nvm ls
-> v14.17.6
PM2 is installed under:
which pm2
~/.nvm/versions/node/v14.17.6/bin/pm2
Since I am using App1 (a NodeJS app managed by npm). I got:
which App1
~/.nvm/versions/node/v14.17.6/bin/App1
So every time I upgrade using nvm:
nvm install --lts --reinstall-packages-from=14 --latest-npm
Then nvm using a newer version in this console. e.g. 14.7.999999
Perhapse I (at most of the time) needs to get my PM2 plus other applications upgrade at the same maintenance window, I use ncu, ncu -g
and upgrade them.
Now, the applications end up with all new version. Ex. a new PM2 instance (local) and an old PM2 running (In Memory) with old comsumer applications (App1) in an old node folder. New version of App1 now exists in new Node application folder but not running.
In memory PM2 version: 5.1.0
Local PM2 version: 5.1.1
Anyway, if you don't have an upgraded version of PM2, you probably still looking for a new path of PM2 installed under your new Node folder. If not, you can install PM2 again with the upgraded node
npm i -g pm2
The thing getting worse is PM2 is in system startup scripts which needs to be re-written. Ex.
/etc/systemd/system/pm2-xx.service
So I endup with vanishing all applications:
pm2 stop app1 && pm2 delete app1
pm2 stop app2 (verdaccio json startup config) && pm2 delete app2
...
pm2 stop appN && pm2 delete appN
Then do:
pm2 update
To swap to the new PM2 instance
Then re-provision all the applications
pm2 start app1, app2, ... appN
Then do
pm2 update
To update the list of applications, check if correct Node path is used.
If all applciation paths are corrected
Do
pm2 startup systemd
And copy and run the suggested Startup Script
sudo env PATH=$PATH:/....
Finally run
pm2 save
To freeze the list on startup.