Question

So I have a jenkins build that is calling a forever start with the following command.

sudo NODE_ENV=development forever start -a -l /var/nodejs/app/logs/forever.log -o /var/nodejs/app/logs/output.log -e /var/nodejs/app/logs/error.log /var/nodejs/app/app.js 

This command throws the following error.

running on the development server

fs.js:427
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory 'ssl/gd_bundle.crt'
    at Object.fs.openSync (fs.js:427:18)
    at Object.fs.readFileSync (fs.js:284:15)
    at Object.<anonymous> (/var/nodejs/app/app.js:190:10)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
error: Forever detected script exited with code: 8

I can get the same error when I run it from the command line on the server, however only if I am not in the directory with the app.js file. If I am specifying the path for the app.js file why is forever sensitive to where the file is located.

I also found that forever is not respecting the -p flag or the forever config directory. Any thoughts?

Was it helpful?

Solution

This hasn't got anything to do with Jenkins, as you said you get the same error from command line.

From what I can tell, this is not a problem with "forever [being] sensitive to where the file is located" but rather your nodejs script app.js being sensitive to where it is launched from. The example from Forever uses a path with directories without problems. Try launching your script without forever from incorrect directory, and you will observe the same issue.

Somewhere in your script code, you are relying on current working directory when determining location of ssl/gd_bundle.crt. Without seeing your code source, I can only guess and point fingers.

  • If your location of ssl/gd_bundle.crt is relative to location of the script, then as indicated in this answer: How do I get the path to the current script with Node.js?, you should use __dirname to get directory location of script, which would be same regardless of current working directory.

  • If your location of ssl/gd_bundle.crt is fixed on the file system, you should use an absolute path, starting with / to make sure it is independent of current working directory.

As for the -p being ignored, a quick Google search turn up this: forever -p /var/run/forever is ignored which indicates that it is an open bug.

Edit:
To avoid modifying the nodejs script (if it's not your file), you can simply change to the correct current directory before executing your node command. Works in Jenkins as well as command line:

cd /var/nodejs/app && sudo NODE_ENV=development forever start -a -l logs/forever.log -o logs/output.log -e logs/error.log app.js

(bolded the changed parts)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top