Open boutell opened 12 years ago
I can reproduce this.
I am having trouble with --sourceDir also... It does not seem to work..
This should be fixed. There are tests that confirm this works.
Why was this closed?
Just to add my 2 cents, I just started experiencing this problem. Perhaps it has regressed?
I'll investigate, will reopen
Also seeing this issue. When forever is run from a script that references an absolute path, process.cwd() returns the script directory instead of the local directory.
An easy way to reproduce the problem is to use the express-config module (https://github.com/blahed/express-config) and then run forever from any directory except the one with the application
+1
+1
currenlty we patch it with performing cd
always before running forever
0.11.0 worked well, but 0.11.1 broke it again; solved by fixing version on 0.11.0
is forever still maintained? any alternatives?
+1
+1
I can confirm this is still a problem in the latest version.
+1
C:\Users\guorong841>C:\Users\guorong841\AppData\Roaming\npm\forever.cmd --minUpt ime 1000ms --spinSleepTime 1000ms D:\workspace\jee\activity\server.js error: Cannot start forever error: script C:\Users\guorong841\D:\workspace\jee\activity\server.js does not exist.
We did not experience this issue in v0.11.1, but today when we started up some new servers and they started using v0.12.0, we had this issue. We had an absolute path to our script and it changed the CWD to /
I'm not sure of the history, but the way the code is now written the CWD for the spawned process will always be set to '/' if the specified script path begins with '/'. For example:
$ forever start /path/to/my/script # CWD will be '/'
This is due to the logic in forever\cli.js, line 237: options.sourceDir = options.sourceDir || (file && file[0] !== '/' ? process.cwd() : '/'); if (options.sourceDir) { options.spawnWith = {cwd: options.sourceDir}; }
Looking at this code, you can see that if --sourceDir is specified, it will be used as the CWD:
$ forever --sourceDir /path/to/my start script # CWD will be '/path/to/my'
...but that seems to be a bug (or at least an undocumented side-effect), given that the documented effect of --sourceDir is to set "The source directory for which SCRIPT is relative to". It's not at all obvious that this should actually affect the CWD for the process running the script.
Because the tryStart() method builds the full script path by joining the --sourceDir with the given script name (as per the documentation), you can't use an absolute path for your script. And so, there is no way to both specify the CWD for a script and use absolute paths.
The workaround with the current code base is to (a) set --sourceDir to the desired CWD, and (b) specify SCRIPT as a path relative to --sourceDir.
$ #desired CWD: /home/myuser $ #path to script: /usr/local/bin/myscript $ forever --sourceDir /home/myuser start ../../usr/local/bin/myscript
Personally, I think the correct approach is to treat CWD as completely independent of --sourceDir, and having an option like --cwd that can be used to specify this explicitly is probably the cleanest solution.
This solved my problem, maybe it will be useful for someone:
forever start --sourceDir /var/www/html/sitedir scriptname.js
If I use:
The current working directory is changed to / by forever before the script is run (verified with process.cwd()).
If I use:
I do not see this problem, the current working directory is left alone.
I am not sure if the
--sourceDir
option is meant to help with this, but it does not appear to.Thanks for an excellent process babysitter!