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

Support a cwd option in JSON files #295

Closed
qraynaud opened this issue Feb 7, 2014 · 21 comments
Closed

Support a cwd option in JSON files #295

qraynaud opened this issue Feb 7, 2014 · 21 comments

Comments

@qraynaud
Copy link

qraynaud commented Feb 7, 2014

It would be great to be able to add a cwd parameter in the JSON file just like so :

{
  "name": "myAppName",
  "script": "myApp.js",
  "cwd": "path/to/my/app"
}

That would help a lot. Especially when some modules do require that cwd is proper to work as intended. I have to add some process.chdir(__dirname) in my index.js files to cope with this and don't like it.

@Unitech
Copy link
Owner

Unitech commented Feb 7, 2014

Hello Quentin (:

Yes I think I should switch this line : https://github.com/Unitech/pm2/blob/master/lib/ProcessContainer.js#L63

process.chdir(process.env.PWD || p.dirname(script));

to

process.chdir(p.dirname(script));

@qraynaud
Copy link
Author

qraynaud commented Feb 7, 2014

It seems right at first but I don't think this is that simple. I have some applications where the main file is in a subfolder like server/server.js that do require a cwd at project's root. What you propose is a good quick fix for a lot of cases but it won't be enough to cover all use cases.

I would :

app = Common.resolveAppPaths(app, cwd);

to

app = Common.resolveAppPaths(app, app.cwd || cwd);
process.chdir(process.env.pm_cwd || p.dirname(script));
  • Ensure pm_cwd has the value provided in the JSON file if any (I'm not sure about the code involved there)

@qraynaud
Copy link
Author

qraynaud commented Feb 7, 2014

I updated my previous post to correct an obvious issue.

@Unitech
Copy link
Owner

Unitech commented Feb 8, 2014

Thanks for these advises, I'm looking to implement them

@qraynaud
Copy link
Author

qraynaud commented Feb 8, 2014

You're welcome.
As a second thought, I suppose that some support for this should also be added in fork mode. Probably by simply changing directory right after forking.

@nlaplante
Copy link

👍

@reaktivo
Copy link

This! We need this.

@morficus
Copy link

+1

@Unitech
Copy link
Owner

Unitech commented May 15, 2014

Ok done ! It will be available in the 0.8.7

@Unitech Unitech closed this as completed May 15, 2014
@qraynaud
Copy link
Author

Cool ! Thanks a lot !

@drewolson
Copy link

This correctly launches the app with a relative path but the true cwd of the process seems unaffected. I'm attempting to run a kraken app and it is unable to find the controllers even with cwd specified in the json config unless I run it from the application root.

@jansc
Copy link

jansc commented May 23, 2014

The cwd of the process doesn't seem to change. I have several apps that open log files with relative paths (e.g. logs/api.log), so I need the cwd to be set to the app's root directory. I try to start them with a json-configuration with the cwd set to each app's root directory, so changing the directory before starting pm2 is not option.

Steps to reproduce:
change_pwd

I would expect iminpath1 to log /Users/jans/dev/pm2/pm2/test/fixtures/path1 and iminpath2 to log /Users/jans/dev/pm2/pm2/test/fixtures/path1/path2.

@Unitech Unitech reopened this May 23, 2014
Unitech added a commit that referenced this issue May 23, 2014
@Unitech
Copy link
Owner

Unitech commented May 23, 2014

Could you please use the pm2 in the master and tell me if it works now ?

npm install git://github.com/Unitech/pm2#master -g

Thanks

@jansc
Copy link

jansc commented May 23, 2014

Thank you so much! It seems to work fine now :-)

@Unitech
Copy link
Owner

Unitech commented May 23, 2014

Great ! I just published the 0.8.12 with this fix

@Unitech Unitech closed this as completed May 23, 2014
@stevethibault
Copy link

Not working for me in 1.1.2. cwd is not respecetd...
process.json
cat process.json
{
"apps" : [{
"name" : "wormtownmilers-app",
"watch" : true,
"script" : "mainApp/app.js",
"env": {
"NODE_ENV": "development",
},
"env_production" : {
"NODE_ENV": "production"
}
},
{
"name" : "CriticalMiss",
"watch" : true,
"script" : "CriticalMiss/Spellbook/server.js",
"cwd" : "/home/admin/CriticalMiss/Spellbook/",
"env": {
"NODE_ENV": "development",
},
"env_production" : {
"NODE_ENV": "production"
}
}]
}

running process description:
root@ubuntu:/home/admin# pm2 describe 1
Describing process with id 1 - name CriticalMiss
┌───────────────────┬──────────────────────────────────────────────┐
│ status │ errored │
│ name │ CriticalMiss │
│ restarts │ 485 │
│ uptime │ 0 │
│ script path │ /home/admin/CriticalMiss/Spellbook/server.js │
│ script args │ N/A │
│ error log path │ /root/.pm2/logs/CriticalMiss-error.log │
│ out log path │ /root/.pm2/logs/CriticalMiss-out.log │
│ pid path │ /root/.pm2/pids/CriticalMiss.pid │
│ interpreter │ node │
│ interpreter args │ N/A │
│ script id │ 1 │
│ exec cwd │ /home/admin │
│ exec mode │ fork_mode │
│ node.js version │ 4.2.6 │
│ watch & reload │ ✔ │
│ unstable restarts │ 0 │
│ created at │ N/A │
└───────────────────┴──────────────────────────────────────────────┘

What am I doing wrong?

@vmarchaud
Copy link
Contributor

@stevethibault Could you please show us the error ?

@stevethibault
Copy link

You can see in the post pm2 description command output that the cwd is not
what was specified in the process.json file. Is that the correct behavior
when the cwd property is set in the json?

On Aug 8, 2016 6:03 PM, "vmarchaud" notifications@github.com wrote:

@stevethibault https://github.com/stevethibault Could you please show
us the error ?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#295 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACce_IEKq35u_dfwTQOHPxZZSNTDUj-zks5qd6fEgaJpZM4BgDb_
.

@vmarchaud
Copy link
Contributor

vmarchaud commented Aug 8, 2016

@stevethibault Set the script to server.js only it should work.

@stevethibault
Copy link

Ok.

On Aug 8, 2016 6:26 PM, "vmarchaud" notifications@github.com wrote:

@stevethibault https://github.com/stevethibault Set the script to
server.js it should work.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#295 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACce_It_-6OzmqHuQ_d1bisp3okW-v31ks5qd60tgaJpZM4BgDb_
.

@stevethibault
Copy link

That did the trick. Awesome. Thank you for the help.

On Mon, Aug 8, 2016 at 6:29 PM, Steve Thibault steve@patternsoft.net
wrote:

Ok.

On Aug 8, 2016 6:26 PM, "vmarchaud" notifications@github.com wrote:

@stevethibault https://github.com/stevethibault Set the script to
server.js it should work.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#295 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ACce_It_-6OzmqHuQ_d1bisp3okW-v31ks5qd60tgaJpZM4BgDb_
.

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

No branches or pull requests

10 participants