Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 368
philip_nunoo Avatar asked Jul 11 '15 15:07

philip_nunoo


3 Answers

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.

like image 117
codebased Avatar answered Nov 16 '22 02:11

codebased


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

like image 6
Mihai Avatar answered Nov 16 '22 02:11

Mihai


solved the issue by setting my mongo db username and password

like image 1
philip_nunoo Avatar answered Nov 16 '22 04:11

philip_nunoo