Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload PM2 configuration file

Tags:

node.js

pm2

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?

like image 366
Estus Flask Avatar asked Jun 12 '17 20:06

Estus Flask


People also ask

How do I reload a pm2 app?

Restart on file change To totally disable the watch feature, do: pm2 stop app --watch or toggle the watch option on application restart via pm2 restart app --watch .

What does pm2 reload do?

With reload, pm2 restarts all processes one by one, always keeping at least one process running. It also states that: If the reload system hasn't managed to reload your application, a timeout will fallback to a classic restart.

Where is pm2 config file?

The default configuration file is ecosystem. core3. config. js , and is located in the root folder of lisk-service : It contains a configuration to connect to a local Lisk Core node.

Does pm2 auto restart on file change?

PM2 is an advanced, production process manager for Node. js that auto-restarts Node apps after crashes or file changes.


2 Answers

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
like image 188
Estus Flask Avatar answered Sep 19 '22 14:09

Estus Flask


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.

like image 42
Jan Grz Avatar answered Sep 18 '22 14:09

Jan Grz