Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifying log path in ecosystem.config.js is not reflected when restarting pm2 #3164

Closed
nitrocode opened this issue Sep 21, 2017 · 4 comments

Comments

@nitrocode
Copy link

nitrocode commented Sep 21, 2017

What's going wrong?

My log path doesn't change after modifying

from

      error_file: `/var/log/app/err/${os.hostname()}.log`,
      out_file: `/var/log/app/app/${os.hostname()}.log`,

to

      error_file: `/data/app/err/${os.hostname()}.log`,
      out_file: `/data/app/app/${os.hostname()}.log`,

I tried running pm2 reload all and tried pm2 stop all with a subsequent pm2 ecosystem.config.js --env dev

How could we reproduce this issue?

Use the above from config, run pm2 start all and then after it's logging for a bit, change the path to the above to config and run pm2 reload all and watch as it continues to the log to the original path.

Supporting information

$ node_modules/.bin/pm2 report
===============================================================================
--- PM2 REPORT (Thu Sep 21 2017 02:50:22 GMT+0000 (UTC)) ----------------------
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 2.6.1
node version         : 8.4.0
node path            : /home/app/node_modules/.bin/pm2
argv                 : /home/app/.nvm/versions/node/v8.4.0/bin/node,/home/app/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : app
uid                  : 1001
gid                  : 1001
uptime               : 9187min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 2.6.1
node version         : 8.4.0
node path            : node_modules/.bin/pm2
argv                 : /home/app/.nvm/versions/node/v8.4.0/bin/node,/home/app/node_modules/.bin/pm2,report
argv0                : node
user                 : app
uid                  : 1001
gid                  : 1001
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
cpus nb              : 4
freemem              : 13889986560
totalmem             : 16388919296
home                 : /home/app
===============================================================================
--- PM2 list -----------------------------------------------
┌──────────┬────┬─────────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
│ App name │ id │ mode    │ pid   │ status │ restart │ uptime │ cpu │ mem       │ user │ watching │
├──────────┼────┼─────────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
│ app     │ 1  │ cluster │ 14139 │ online │ 37      │ 8m     │ 0%  │ 55.0 MB   │ app │ disabled │
│ app     │ 2  │ cluster │ 14144 │ online │ 37      │ 8m     │ 0%  │ 55.2 MB   │ app │ disabled │
│ app     │ 3  │ cluster │ 14151 │ online │ 37      │ 8m     │ 1%  │ 56.4 MB   │ app │ disabled │
│ app     │ 4  │ cluster │ 14156 │ online │ 37      │ 8m     │ 0%  │ 55.3 MB   │ app │ disabled │
└──────────┴────┴─────────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘
 Module activated
┌───────────────┬─────────┬────────────┬────────┬─────────┬─────┬─────────────┬──────┐
│ Module        │ version │ target PID │ status │ restart │ cpu │ memory      │ user │
├───────────────┼─────────┼────────────┼────────┼─────────┼─────┼─────────────┼──────┤
│ pm2-logrotate │ 2.2.0   │ N/A        │ online │ 4       │ 0%  │ 47.656 MB   │ app │
└───────────────┴─────────┴────────────┴────────┴─────────┴─────┴─────────────┴──────┘
===============================================================================
--- Daemon logs --------------------------------------------
/home/app/.pm2/pm2.log last 20 lines:
PM2        | 2017-09-21 02:41:26: Stopping app:app id:3
PM2        | 2017-09-21 02:41:26: 4
PM2        | 2017-09-21 02:41:26: Stopping app:app id:4
PM2        | 2017-09-21 02:41:26: App name:app id:3 disconnected
PM2        | 2017-09-21 02:41:26: App [app] with id [3] and pid [12775], exited with code [0] via signal [SIGINT]
PM2        | 2017-09-21 02:41:26: App [app] with id [4] and pid [12780], exited with code [0] via signal [SIGINT]
PM2        | 2017-09-21 02:41:26: pid=12775 msg=process killed
PM2        | 2017-09-21 02:41:26: pid=12780 msg=process killed
PM2        | 2017-09-21 02:41:59: Starting execution sequence in -cluster mode- for app name:app id:1
PM2        | 2017-09-21 02:41:59: Starting execution sequence in -cluster mode- for app name:app id:2
PM2        | 2017-09-21 02:42:00: App name:app id:2 online
PM2        | 2017-09-21 02:42:00: (node:8967) [DEP0007] DeprecationWarning: worker.suicide is deprecated. Please use worker.exitedAfterDisconnect.
PM2        | 2017-09-21 02:42:00: App name:app id:1 online
PM2        | 2017-09-21 02:42:00: (node:8967) [DEP0007] DeprecationWarning: worker.suicide is deprecated. Please use worker.exitedAfterDisconnect.
PM2        | 2017-09-21 02:42:00: Starting execution sequence in -cluster mode- for app name:app id:3
PM2        | 2017-09-21 02:42:00: Starting execution sequence in -cluster mode- for app name:app id:4
PM2        | 2017-09-21 02:42:00: App name:app id:3 online
PM2        | 2017-09-21 02:42:00: (node:8967) [DEP0007] DeprecationWarning: worker.suicide is deprecated. Please use worker.exitedAfterDisconnect.
PM2        | 2017-09-21 02:42:00: App name:app id:4 online
PM2        | 2017-09-21 02:42:00: (node:8967) [DEP0007] DeprecationWarning: worker.suicide is deprecated. Please use worker.exitedAfterDisconnect.
@vmarchaud
Copy link
Contributor

By default PM2 avoid modifying environment when reloading, you need to pass the flag --update-env to tell PM2 to update it, note that if you want to pick up the chance inside the ecosystem file, you need to reload with the file like : pm2 reload ecosystem.config.js --update-env

@nitrocode
Copy link
Author

nitrocode commented Sep 21, 2017

@vmarchaud I tried this command:

 ./node_modules/.bin/pm2 reload ecosystem.config.js --update-env --env dev

It's still logging to the original directory. Is there a good way to step through this? Or if it is an environment variable, is there a way to see it in bash?

Here is more of my config if this helps

      name: 'app',
      script: 'server.js',
      instances: 'max',
      exec_mode: 'cluster',
      error_file: `/data/app/err/${os.hostname()}.log`,
      out_file: `/data/app/app/${os.hostname()}.log`,
      merge_logs: false,
      env: {
        ...
      },
      env_dev: {
        NODE_ENV: 'dev',
        AWS_PROFILE: 'default',
        ...
      },

@nitrocode
Copy link
Author

@vmarchaud I ran the following to make it work

# stop pm2
./node_modules/.bin/pm2 stop all
pkill pm2
pkill pm2-logrotate
# rm all node_modules
rm -rf node_modules/
# rm all pm2
rm -rf .pm2
# reinstall
npm install
# reinstall logrotate stuff
...
# start app
./node_modules/.bin/pm2 start ecosystem.config.js --update-env --env dev

Unsure what was causing it to not re-read the updated config file but now it works. I'm wondering if this is caused by running a local version of pm2 instead of a global version... ?

@jquinter
Copy link

jquinter commented Oct 22, 2018

@vmarchaud I ran the following to make it work

# stop pm2
./node_modules/.bin/pm2 stop all
pkill pm2
pkill pm2-logrotate
# rm all node_modules
rm -rf node_modules/
# rm all pm2
rm -rf .pm2
# reinstall
npm install
# reinstall logrotate stuff
...
# start app
./node_modules/.bin/pm2 start ecosystem.config.js --update-env --env dev

Unsure what was causing it to not re-read the updated config file but now it works. I'm wondering if this is caused by running a local version of pm2 instead of a global version... ?

Hey man, sorry if it's too late:

it seems that in order to make changes work, you need to delete the current process running. I figured out it after reading this answer.

In my case, it worked after deleting the process/version/app I wanted to update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants