pm2
pm2 copied to clipboard
pm2 restart ecosystem.config.js does not reload app details from ecosystem file
I've seen slightly similar issues reported ( #3677, #3587 ) and I would like to add more detail
What's going wrong?
None of the restart | startOrRestart | startOrReload read updates from an ecosystem file.
I.e. changing the script path and running pm2 restart ecosystem.config.js --env production --update-env doesn't update the process process info
How could we reproduce this issue?
pm2 startOrReload ecosystem.config.js --env production --update-env
module.exports = {
apps: [{
name: "Internal API",
script: "./internal_api/bundle.js",
watch: true,
kill_timeout: 10000,
wait_ready: true,
env_production: {
NODE_ENV: "production",
NODE_CONFIG_DIR: "./config"
},
}],
};
pm2 info 0
status │ online │
│ name │ Internal API │
│ restarts │ 15 │
│ uptime │ 75s │
│ script path │ /home/centos/internal_api/bundle.js │
│ script args │ N/A │
│ error log path │ /home/centos/.pm2/logs/Internal-API-error-0.log │
│ out log path │ /home/centos/.pm2/logs/Internal-API-out-0.log │
│ pid path │ /home/centos/.pm2/pids/Internal-API-0.pid │
│ interpreter │ node │
│ interpreter args │ N/A │
│ script id │ 0 │
│ exec cwd │ /home/centos │
│ exec mode │ fork_mode │
│ node.js version │ 8.11.3 │
│ watch & reload │ ✔ │
│ unstable restarts │ 0 │
│ created at │ N/A
Update the ecosystem.config.js and change script path to script: "./internal-api/bundle.js" (hyphen instead of underscore), run pm2 startOrReload ecosystem.config.js --env production --update-env (same for reload, startOrRestart)
$ pm2 startOrReload ecosystem.config.js --env production --update-env
[PM2] Applying action reloadProcessId on app [Internal API](ids: 0)
[PM2] [Internal API](0) ✓
pm2 info 0 will show the old script path
│ script path │ /home/centos/internal_api/bundle.js
Edit: Also, more of a question, but I would've expected that supplying an ecosystem file will enforce whatever apps are running? I.e if I change the name of an app in the ecosystem file the it will be registered as a new process and the old one will keep running instead of killing everything except what's in the ecosystem.
Supporting information
$ pm2 report
[centos@ip-10-0-19-234 ~]$ pm2 report
===============================================================================
--- PM2 REPORT (Wed Jun 27 2018 10:03:50 GMT+0000 (UTC)) ----------------------
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 2.10.4
node version : 8.11.3
node path : /usr/local/lib/npm/bin/pm2
argv : /usr/bin/node,/usr/local/lib/npm/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : centos
uid : 1000
gid : 1000
uptime : 5min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 2.10.4
node version : 8.11.3
node path : /usr/local/lib/npm/bin/pm2
argv : /usr/bin/node,/usr/local/lib/npm/bin/pm2,report
argv0 : node
user : centos
uid : 1000
gid : 1000
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
cpus nb : 1
freemem : 389451776
totalmem : 1038929920
home : /home/centos
===============================================================================
--- PM2 list -----------------------------------------------
┌──────────────┬────┬──────┬─────┬────────┬─────────┬────────┬─────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────────┼────┼──────┼─────┼────────┼─────────┼────────┼─────┼────────┼────────┼──────────┤
│ Internal API │ 0 │ fork │ 0 │ online │ 31 │ 58s │ 0% │ 0 B │ centos │ enabled │
└──────────────┴────┴──────┴─────┴────────┴─────────┴────────┴─────┴────────┴────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
┌──────────────┬────┬──────┬─────┬────────┬─────────┬────────┬─────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────────┼────┼──────┼─────┼────────┼─────────┼────────┼─────┼────────┼────────┼──────────┤
│ Internal API │ 0 │ fork │ 0 │ online │ 31 │ 58s │ 0% │ 0 B │ centos │ enabled │
└──────────────┴────┴──────┴─────┴────────┴─────────┴────────┴─────┴────────┴────────┴──────────┘
me too
I seem to be having the same issue. Did either of you manage to figure it out?
not really, I am using pm2 kill as we're running a cluster of servers and we will always have one up
please, make a new command to "full-reload" the ecosystem file..... i am sick of having to kill and start app over and over again during development...
@the-noob from PM2 docs: updating-running-conf
Starting PM2 v2.1.X, environments are immutable by default, that means the environment will never be updated unless you tell PM2 to do so, to update configurations, you will need to use --update-env options. Please note that some options will not be updated (options that are listed under General Attributes below).
script won't be updated with --update-env, I am also searching ways to update interpreter without downtime.
+1
+1
pm2 kill && pm2 start ecosystem.config.js
worked for me.
Do " pm2 ecosystem" to generate a new ecosystem file
+1
@the-noob from PM2 docs: updating-running-conf
Starting PM2 v2.1.X, environments are immutable by default, that means the environment will never be updated unless you tell PM2 to do so, to update configurations, you will need to use --update-env options. Please note that some options will not be updated (options that are listed under General Attributes below).
scriptwon't be updated with--update-env, I am also searching ways to updateinterpreterwithout downtime.
@roman-yu this makes total sense with the observed behavior, but this quote does no longer appear in the documentation, does it mean that could have been changes (couldn't find them)?
i am facing the same issue.. running
pm2 reload ecosystem.json
code updates dont seem to be present in reloaded pm2 processes eventhou there has been new code pushed to server - any help here?
Currently pm2 kill and pm2 resurrect seems to reload ecosystem file. It's a makeshift solution if you're fine with restarting all your other applications, or if you have none other running.
Edit: don't forget to run pm2 save before you restart!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
No, this is not stale.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@Unitech Could you tell stale bot to stop closing this one?
They need a spam bot to counter the stale bot, apparently.
JK
I'm having this issue too. I have two pm2 processes running and I only want to reload one of them with an updated ecosystem.config file. There doesn't seem to be a way to do this
I stumbled upon the same issue when I updated the script property of one of my apps in my ecosystem file.
Just doing the reload part with pm2 reload ~/.pm2/ecosystem.config.js --only myapp1 didn't use the new script path either.
But I have found a workaround for me.
Assuming the app in question has id myapp1
First delete the application from the runtime:
pm2 delete myapp1
Re-add the app with:
pm2 reload ~/.pm2/ecosystem.config.js --only myapp1
That kept all other running apps untouched and just reloaded/restarted the changed one.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
No-no, not stale!
the problem is still present.
pm2 reload ./ecosystem.config.js does not updates configuration
hello from 2021 we still experience the issue and cry at night
Any update on this? I've run into this now, too. As a new PM2 user each time I learn a new thing and want to apply it I have to have downtime for my app because I must delete and restart the ecosystem file. Please provide a way to reload and update the config in place. For example the nginx configtest and reload interfaces are great and could be used an example here.
Could you try:
pm2 restart ecosystem.config.js --update-env
Could you try:
pm2 restart ecosystem.config.js --update-env
This is literally what people tried 3 years ago, as described in the original post. AFAIK there has been no change of behaviour of the --update-env flag.
Could you try:
pm2 restart ecosystem.config.js --update-env
Tested this again with --update-env. No change in behavior. Looking at previous comments it seems some attributes can be updated via --update-env and some cannot. If the documentation could please be updated to have something such as the following that would at least make it more clear what the expected functionality is:
"The following ecosystem file attributes cannot be updated without downtime...." or "Downtime is required in order to update the following attributes in an ecosystem file...."
Thanks!
I'm also having this issue. A big pain when trying to setup CI. Am currently having to:
pm2 delete all
pm2 start ecosystem.config.js
pm2 save
systemctl restart pm2-<whatever>.service
Although with the above, as my webhook is a service being managed by pm2 when the pm2 delete all is executed the rest of my script doesn't execute because its a child process. Working my way around this.
EDIT:
For anyone interested I found you need to execute the CI script as a grandchild so when child process is killed by pm2 delete all, the grandchild process will be inherited by init resulting in the rest of the script executing successfully.
See: https://stackoverflow.com/a/20338327/4515324
@TheSycamore This command will not restart the process gracefully. Suppose you have 2 processes, out of which one needs to complete the ongoing job, the second will be stopped and will wait for the first process to get killed.