10

I realize in advance this is kind of a vague question, but I'm stumped as to what else I can try here...

I've been going through other SO questions and following their recommendations but so far nothing has solved my issue yet.

Here's the specific error I'm getting.

Stopping NodeJS cartridge
Fri Jul 10 2015 10:36:28 GMT-0400 (EDT): Stopping application 'appname' ...
Fri Jul 10 2015 10:36:29 GMT-0400 (EDT): Stopped Node application 'appname'

Starting NodeJS cartridge
Fri Jul 10 2015 10:36:30 GMT-0400 (EDT): Starting application 'appname' ...

Waiting for application port (8080) become available ...

Application 'appname' failed to start (port 8080 not available)

Failed to execute: 'control restart' for /var/lib/openshift/MYID/nodejs

My package.json file is up to date will all my dependencies, has the scripts: { start: 'node server.js' } property and yet I'm still getting this error.

If I SSH in and go to my current/repo directory and run node server.js it works fine. However, I can't just use screen to run it in the background forever.

I've also tried for stopping and restarting, git pushing, and restarting through the browser. I'm stumped as to what else I can try to get my (very simple) node application running on OpenShift.

Any suggestions are much appreciated.

Scheda
  • 526
  • 5
  • 11

2 Answers2

13

For an OpenShift Node app you need to specify the start script as: main: "server.js" instead of using scripts. This is due to the way Node applications are started on OpenShift using node-supervisor.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • 4
    Well, thanks to your comment I took a double look at my `package.json` and instead of a period in the filename under `main` I had a comma. *facepalm* Thanks! – Scheda Jul 10 '15 at 17:00
  • Also, there might be some syntax error in other files that are required with the start. I had an error in a sub file and couldn't make the app start until I fixed the other file. – George Jun 24 '16 at 22:18
12

OpenShift Node apps require you to give the configuration to start your app in package.json under main and scripts.start:

"scripts": {
     "start": "node server.js"
  },
"main": "server.js"

Further it also requires to give it IP and PORT provided by your node environment through environment variables:

for PORT Number       process.env.OPENSHIFT_NODEJS_PORT
for IP                process.env.OPENSHIFT_NODEJS_IP

If these variables not used in app , it shows error which looks like:

Waiting for application port (8080) become available ...
Application 'appname' failed to start (port 8080 not available)

Here is an example to show how to use these environment variables in your node app(from source):

var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'

server.listen(server_port, server_ip_address, function () {
console.log( "Listening on " + server_ip_address + ", server_port " + port )
});

Source: https://blog.openshift.com/run-your-nodejs-projects-on-openshift-in-two-simple-steps/

Related Post: Application 'appname' failed to start (port 8080 not available) on open shift node app

Community
  • 1
  • 1
devprashant
  • 1,285
  • 1
  • 13
  • 23