Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary to use Forever.js on OpenShift?

I've deployed my first Node.js app on OpenShift's free tier, and it works great.

Will OpenShift automatically restart my Node app when it crashes, or do I have to set up Forever.js? I tried setting it up, and it would not work. After running node_modules/forever/bin/forever start app.js (working dir was app-root/repo, with local copy of forever) I got this output:

warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: app.js

fs.js:240
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory '/var/lib/openshift/5397416f5004466c0b000080/.forever/VQMF.log'
    at Object.openSync (fs.js:240:18)
    at Object.startDaemon (/var/lib/openshift/5397416f5004466c0b000080/app-root/runtime/repo/node_modules/forever/lib/forever.js:406:14)
    at /var/lib/openshift/5397416f5004466c0b000080/app-root/runtime/repo/node_modules/forever/lib/forever/cli.js:258:13
    at /var/lib/openshift/5397416f5004466c0b000080/app-root/runtime/repo/node_modules/forever/lib/forever/cli.js:145:5
    at Object.oncomplete (/var/lib/openshift/5397416f5004466c0b000080/app-root/runtime/repo/node_modules/forever/lib/forever.js:358:11)

So, does OpenShift manage my app's health for me, or will I need to get Forever working? If so, any idea as to the error I got?

like image 925
Jeff Avatar asked Jun 24 '14 19:06

Jeff


2 Answers

Yes, OpenShift does automatically restart your Node app when it crashes. OpenShift doesn't use forever.js but it uses node-supervisor. Your can test it by requiring something that doesn't exist. Fix it quick though because the log can grow fast restarting the app. Here is the log in nodejs.log on OpenShift which shows that it's running node-supervisor:

DEBUG: Running node-supervisor with
DEBUG:   program 'server.js'
DEBUG:   --watch '/var/lib/openshift/53a9e06ae0b8cde26300008e/app-root/data/.nodewatch'
DEBUG:   --ignore 'undefined'
DEBUG:   --extensions 'node|js|coffee'
DEBUG:   --exec 'node'
DEBUG: Starting child process with 'node server.js'
DEBUG: Watching directory '/var/lib/openshift/53a9e06ae0b8cde26300008e/app-root/data/.nodewatch' for changes.
like image 164
Ben Avatar answered Oct 20 '22 08:10

Ben


Currently, OpenShift's default behavior involves using supervisor to start, watch, and restart your nodejs applications.

Here is a quick outline of the various init options for nodejs:

  1. If your app includes a valid package.json file with a main entry (containing the name of your server script), then OpenShift will initialize your app by using supervisor to start that script.
  2. If your app includes the force_npm_deploy marker file (an empty file in .openshift/markers/use_npm) - then OpenShift will just run npm start. This runs whatever is defined in your package.json file's scripts.start entity.
  3. If all else fails, OpenShift will try to run server.js using supervisor (as a fallback option).

Some additional notes are available here: https://www.openshift.com/blogs/10-reasons-openshift-is-the-best-place-to-host-your-nodejs-app#npm

like image 41
ʀɣαɳĵ Avatar answered Oct 20 '22 10:10

ʀɣαɳĵ