pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

pm2 restart ecosystem.config.js does not reload app details from ecosystem file

Open the-noob opened this issue 7 years ago • 49 comments
trafficstars

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  │
└──────────────┴────┴──────┴─────┴────────┴─────────┴────────┴─────┴────────┴────────┴──────────┘

the-noob avatar Jun 27 '18 10:06 the-noob

me too

gotoin avatar Jul 12 '18 09:07 gotoin

I seem to be having the same issue. Did either of you manage to figure it out?

rossanthony avatar Sep 01 '18 05:09 rossanthony

not really, I am using pm2 kill as we're running a cluster of servers and we will always have one up

the-noob avatar Sep 02 '18 11:09 the-noob

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...

diegofontanabr avatar Sep 14 '18 12:09 diegofontanabr

@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.

roman-yu avatar Sep 19 '18 02:09 roman-yu

+1

danielHin avatar Mar 26 '19 10:03 danielHin

+1

marsch avatar Jul 17 '19 18:07 marsch

pm2 kill && pm2 start ecosystem.config.js

worked for me.

kareha avatar Jul 22 '19 13:07 kareha

Do " pm2 ecosystem" to generate a new ecosystem file

royalbhati avatar Jan 11 '20 09:01 royalbhati

+1

trycontrolmymind avatar Jan 21 '20 07:01 trycontrolmymind

@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.

@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)?

aseques avatar Feb 25 '20 11:02 aseques

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?

simonmaass avatar Mar 20 '20 09:03 simonmaass

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!

cyqsimon avatar May 11 '20 05:05 cyqsimon

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.

stale[bot] avatar Jun 13 '20 08:06 stale[bot]

No, this is not stale.

szepeviktor avatar Jun 13 '20 08:06 szepeviktor

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.

stale[bot] avatar Jul 13 '20 09:07 stale[bot]

@Unitech Could you tell stale bot to stop closing this one?

szepeviktor avatar Jul 13 '20 10:07 szepeviktor

They need a spam bot to counter the stale bot, apparently.

JK

cyqsimon avatar Jul 14 '20 06:07 cyqsimon

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

koneksa-sunny avatar Jul 14 '20 19:07 koneksa-sunny

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.

kuema avatar Jul 15 '20 16:07 kuema

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.

stale[bot] avatar Aug 14 '20 16:08 stale[bot]

No-no, not stale!

szepeviktor avatar Aug 14 '20 17:08 szepeviktor

the problem is still present. pm2 reload ./ecosystem.config.js does not updates configuration

sharpensteel avatar Oct 26 '20 16:10 sharpensteel

hello from 2021 we still experience the issue and cry at night

batrudinych avatar Feb 05 '21 10:02 batrudinych

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.

ghost avatar Mar 08 '21 18:03 ghost

Could you try:

pm2 restart ecosystem.config.js --update-env

Unitech avatar Mar 15 '21 13:03 Unitech

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.

cyqsimon avatar Mar 17 '21 08:03 cyqsimon

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!

ghost avatar Mar 17 '21 12:03 ghost

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 avatar Mar 29 '21 01:03 TheSycamore

@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.

svkrclg avatar Mar 31 '21 08:03 svkrclg