19

I have written a node restify server in coffee and I can't seem to get it running.

While deploying I get the following error:

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

after which I do get the following error

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

If coffeescript seems to be the problem is there a work around it. I would not want to change back to js.

My server code is:

restify = require 'restify'
Bunyan = require 'bunyan'

server = restify.createServer
    name: 'APPNAME'
    version: '0.0.1'
    log: Bunyan.createLogger
        name: 'api'
        serializers: 
            req: ()->
                return "bad"

# Usercontroller.access calls a function to process the request
server.post '/user/access', UserController.access

server = create.createServer()
server.listen server_port, ->
    console.log "Http server listening on #{server_port}"
    require('./document')(server.router.mounts, 'restify')
    return
rdjs
  • 594
  • 2
  • 18
philip_nunoo
  • 920
  • 3
  • 10
  • 21
  • Can we see the code you are using to start your http server? – Preston Van Loon Jul 11 '15 at 15:59
  • 1
    I believe you can't specify what port you want to use on openshift. try using `process.env.OPENSHIFT_NODEJS_PORT` as your port. – dmlittle Jul 11 '15 at 16:55
  • 1
    change the port and the ip address to the following but still shows the above error. `server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080 server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1' ` – philip_nunoo Jul 11 '15 at 17:23
  • @dmlittle i've also tried adding the node package cloud-env so i could `config = require 'cloud-env' ` and using `server.listen config.PORT, config.IP, ()->' but still getting the same error – philip_nunoo Jul 11 '15 at 18:01
  • the fact that you're getting the same error tells me that `process.env.OPENSHIFT_NODEJS_PORT` is not defined and therefore relying on 8080. try `console.log process.env` to check where openshift is setting the port – dmlittle Jul 11 '15 at 18:04

9 Answers9

29

The very first step that you need to check is look at the log under ~/app-root/logs/nodejs.log

In my case there was no issue with package or any kind of access. The only information that I have got in log is:

Error: listen EACCES at errnoException (net.js:905:11) at Server._listen2 (net.js:1024:19)

If you cannot find any reason apart from the front console says that it is unable to access 8080 then make sure that you have specified IP ADDRESS along with PORT Number.

This is how I have fixed it.

var express = require('express');
var app = express();
var http = require('http');

app.set('port', process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 3002);
app.set('ip', process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1");


http.createServer(app).listen(app.get('port') ,app.get('ip'), function () {
    console.log("✔ Express server listening at %s:%d ", app.get('ip'),app.get('port'));
    server();
});

As stated the app.get('ip') is very important when listening. Otherwise, openshift is unable to start your application.

UPDATED:

How to get into log directory:

  1. SSH into your gear with the command rhc ssh
  2. Once you are logged in type cd $OPENSHIFT_LOG_DIR

There you have logs files stored by Openshift environment.

AstroCB
  • 12,337
  • 20
  • 57
  • 73
codebased
  • 6,945
  • 9
  • 50
  • 84
6

It can be for a number of reasons. If nodejs does not start correctly, the PaaS seems to be trying to continuously start it. It either creates a collision for the port or the error has nothing to do with the problem itself. In my case there was a dependency missing. The best way to solve your problem is to ssh in the app container and watch the log file: tail -f ~/app-root/logs/nodejs.log

Mihai
  • 61
  • 2
  • This helped me. The log told me exactly what was wrong. Thanks! +1 for including the *nix command for viewing the log, too – Alex311 Sep 17 '15 at 02:14
1

solved the issue by setting my mongo db username and password

philip_nunoo
  • 920
  • 3
  • 10
  • 21
1

I got the same error and it was to do with the branch I was pointing to on github.

Master was my main branch (first one created) and when I pointed to that it built but I would get the error if I pointed to any other branch.

Lorna Kelly
  • 99
  • 2
  • 12
1

Node App on Openshift is a 2 Step process:

  1. Create entry in package.json to how to launch your server(entry point to app):

    "scripts": {
    "start": "node server.js"
    },
    "main": "server.js"
    
  2. Use OPENSHIFT environment variables to get IP and PORT:

    process.env.OPENSHIFT_NODEJS_PORT
    process.env.OPENSHIFT_NODEJS_IP
    

For more details check: OpenShift: "Failed to execute control start" on node application

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

rhc app create ... --from-code ... and getting 8080 not available?

.

Just like Mihai explained in his answer the (port 8080 not available) doesn't need to be related to how you set up your ports - hence it may occur even if you're using the process.env.OPENSHIFT_NODEJS_PORT and process.env.OPENSHIFT_NODEJS_IP correctly.

An advice to look at the ~/app-root/logs/nodejs.log is helping a lot but what if the error happens on rhc app create ... --from-code ...? The app will not get created hence you can't ssh and look at nodejs.log.

Try to push your app in a limited version - comment out as much code as you can.

For me it worked to start with only the express app initialising and listening. Then, once I had the openshift app created, I've been uncommenting code bit by bit, pushing and checking the nodejs.log file.

This way I found that my mongoDb name was "APPNAME_"+process.env.NODE_ENV while openshift created mongoDb database called only APPNAME

.

Apologies for not directly answering the question, but the 8080 not available seems to be caused by all sorts of setup, maybe this will help someone.

Community
  • 1
  • 1
Voy
  • 5,286
  • 1
  • 49
  • 59
1

If you using express: app.listen(process.env.OPENSHIFT_NODEJS_PORT, process.env.OPENSHIFT_NODEJS_IP);

Or:

var port = process.env.OPENSHIFT_NODEJS_PORT;
var ip = process.env.OPENSHIFT_NODEJS_IP;
app.listen(port, ip);
oxixes
  • 101
  • 1
  • 10
0

In my case I'm getting following error checked using rhc ssh as suggested above.

Unhandled rejection Error: getaddrinfo ENOTFOUND
    at errnoException (dns.js:37:11)
    at Object.onanswer [as oncomplete] (dns.js:124:16)

I get rid of my problem by setting the

mongo_url = process.env.OPENSHIFT_MONGODB_DB_URL;

to mongoose uri.I was trying with following but

mongo_url = "mongodb://admin:pass@$OPENSHIFT_MONGODB_DB_HOST:$OPENSHIFT_MONGODB_DB_PORT/mydbname"

this was not working.

Hope this helps someone.

Sandeep Sharma
  • 1,855
  • 3
  • 19
  • 34
0

The best way to solve it is checking your logs folder. SSH to your server, find the nodejs.log file, you can use cat nodejs.log to see its content.

The reason could be:

  • Syntax error in other files
  • Missing Port environment variable
  • Missing IP environment variable (These 2 last stated on other answers)

Even though it says "Port 8080 not available", the error could be in a file that couldn't be executed properly, thus you should check the recent changes or just check directly the log and find where the error is.

George
  • 6,886
  • 3
  • 44
  • 56