简体   繁体   中英

Reload PM2 configuration file

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?

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

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.

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 ie "refresh" the configuration use this:

pm2 startOrReload config.js --update-env

You should try reload first and if you still have issues try the complete purge.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM