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

时间秒杀一切 提交于 2019-11-28 08:17:51
codebased

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.

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

solved the issue by setting my mongo db username and password

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.

devprashant

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

Voy

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.

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);

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!