Reload PM2 configuration file
Asked Answered
C

3

21

I have problems with reloading PM2 configuration file after editing it:

{
    "apps": [
        ...
        {
            "name": "foo",
            "script": "foo/index.js",
            "cwd": "foo",
            "watch": false
        }
    ]
}

I previously did

pm2 restart config.json

and

pm2 reload config.json

and

pm2 gracefulReload config.json

but they didn't reload the configuration for existing apps (the changes in app config did not apply). The only way that worked for me was:

pm2 delete foo
pm2 restart config.json

How is this supposed to be done?

Corm answered 12/6, 2017 at 20:37 Comment(0)
C
34

As the reference states, configurations are no longer reloaded:

Starting PM2 v2.1.X, environnements are immutable by default, that means they will never be updated unless you tell PM2 to do so, to update configurations, you will need to use --update-env options.

So this should be

pm2 startOrReload config.js --update-env
Corm answered 12/6, 2017 at 20:41 Comment(2)
Just to update the reference above .. this is where you can find the info --update-envClepsydra
This worked well for a pm2 config file reload to change arguments passed to the started script of the process I was targeting. Just a quick note I had to use the full path to the configuration file. pm2 will not find the file unless told specifically where to look for it.Sosanna
F
8

If you are using pm2 for local development and have problems with reloading the config you should run:

$ pm2 delete ecosystem.config.js

This deletes existing services (don't worry, no files will be deleted). Then to reload the configuration run:

$ pm2 start ecosystem.config.js

(Tip: you may need to replace ecosystem.config.js with your config file name)

This is a very rough way of reloading, but it's good if you want a clean slate. It's effective to solve some issues, like I had with node-config - I was getting NODE_APP_INSTANCE warnings even though I added instance_var to my ecosystem config.

Footrope answered 23/6, 2020 at 14:30 Comment(1)
does this delete wipe out all the logs for that instance so far?Blades
Q
5

If you need a COMPLETE PURGE and restart of the configuration:

pm2 kill                                 # kill ongoing pm2 processes
pm2 flush                                # OPTIONAL if logs need to be removed
pm2 start /path/to/ecosystem.config.js   # load config file
pm2 save                                 # save current process list / save changes after loading config file

This can be useful if you keep getting pm2 feedback: status: errored.

If you only want to reload i.e. "refresh" the configuration use this:

pm2 startOrReload config.js --update-env

You should try reload first and if the configuration is still not refreshed, try the complete purge.

Quarrel answered 2/8, 2022 at 9:54 Comment(3)
that is pure wrong. u kill all process just to update 1Matriarch
The answer mentions "kill ongoing pm2 processes" which means a COMPLETE PURGE. And it does answer the question to "Reload PM2 configuration file".Quarrel
elephant in development as is xDCalycine

© 2022 - 2024 — McMap. All rights reserved.