Hello! Thank you for the PM2 project, it's great!
I've got a question about pm2.log and pm2.pid files. As far as I know these files are always located in ~/.pm2/ directory and there is now way to change it via configuration.
Is it possible to add customization for the location of these files?
It would be great to have separate path settings for pm2.log and pm2.pid respectively.
For example:
/var/log/my_project/pm2.log
/var/run/my_project/pm2.pid
Thank you!
https://github.com/Unitech/pm2#json-app-declaration
Yes, I've tried this, but these settings affect only child processes, their logs and pids. But the pm2.log and pm2.pid which belongs to main PM2 process are still present in ~/.pm2/ folder.
I've seen that their path is hardcoded in constants.js file:
PM2_LOG_FILE_PATH : p.join(p.resolve(process.env.HOME, '.pm2'), 'pm2.log'),
PM2_PID_FILE_PATH : p.join(p.resolve(process.env.HOME, '.pm2'), 'pm2.pid'),
Is my understanding right?
process.env.HOME is the user home directory maybe you could try playing with that?
I know there are issues about pm2 user: #431, #260, #268 (even a PR #329) but could worth trying. Atm there is no way of changing the master pid/logs path.
Sorry that I misunderstood the question, re-opening.
Thanks for reopening an issue and for advice about $HOME env variable.
It's a good point about PM2 user. But even changing $HOME or PM2 user doesn't fully suite my issue.
I've found in constants.js that web interface port, for example, is done this way:
WEB_INTERFACE : parseInt(process.env.PM2_API_PORT) || 9615,
That means that if I want to set the web interface port I should simply define $PM2_API_PORT variable, otherwise the system takes the default 9615 value.
If it's possible to make the same with pm2.log and pm2.pid files:
PM2_LOG_FILE_PATH : p.join(process.env.PM2_LOG_DIR || p.resolve(process.env.HOME, '.pm2'), 'pm2.log')
PM2_PID_FILE_PATH : p.join(process.env.PM2_PID_DIR || p.resolve(process.env.HOME, '.pm2'), 'pm2.pid')
In this case it's possible to set a separate paths for pm2.log and pm2.pid files using $PM2_LOG_DIR and $PM2_PID_DIR variables.
Does it make sense from your point of view?
Or there are some architectural concerns?
+1 it does make sense to me
Thank you for the quick fix!
The It's magically working now (?).--error, --log and --output options seem to be completely ignored too.
It seems that when transfering parts of the constants from constants.js to sample-conf.js the introduced functionality implemented in aa19782 has been removed. Could these two lines be added again to be able to set the pm2 log path via an env variable?
Will this functionality ever be restored again?
Thank you.
O.
Feel free to send a PR on dev branch (https://github.com/Unitech/pm2/blob/development/paths.js) for this feature to land on PM2 2.0
Otherwise we will do it on PM2 > 2.0
Thanks for this fix! when will it be released?
Most helpful comment
It seems that when transfering parts of the constants from
constants.jstosample-conf.jsthe introduced functionality implemented inaa19782has been removed. Could these two lines be added again to be able to set the pm2 log path via an env variable?