2

I have deployed a working NodeJS REST service (built with Restify) that is properly started on Openshift, as I can read the log:

listening at http://127.2.188.1:8080

I have used the usual environment parameters to bind the IP and port:

vars.ipaddress = process.env.OPENSHIFT_NODEJS_IP;
vars.port = process.env.OPENSHIFT_NODEJS_PORT || '8080';

In fact, if I call my REST service while I am logged with ssh, I get the right response:

curl http://127.2.188.1:8080/something/1337

If I call the same endpoint (/something/1337) on the public URL of my application (http://myapp-myusername.rhcloud.com), I get a 503, No server is available to handle this request.

Since my application is scaled, could it be some configuration issue, and if so, how can I solve it?

frapontillo
  • 10,499
  • 11
  • 43
  • 54
  • Why is the IP `127.2.188.1`? Does openshift route things on the loopback device to an external IP? If not, you won't be able to get to it externally without routing it yourself, or binding to a non-loopback device. – Spencer Rathbun Apr 29 '14 at 12:13
  • It should do so, but it looks like something is not properly configured by default. – frapontillo Apr 29 '14 at 12:20

1 Answers1

5

The reason this is happening is because OpenShift uses HAProxy as a load balancer in scalable applications. HAProxy is configured to ping root '/' url for health checks to determine whether your application is up or down. In your application, you have not configured anything at the root url so when HAProxy pings '/' it gets 503, hence your application behaves like this. There are two ways you can fix this problem

  1. Create an index.html and push it to OpenShift application
  2. The better solution is to configure HAProxy configuration file. SSH into the main gear using rhc ssh --app command, then change directory to haproxy/conf, and then update option httpchk GET / to option httpchk GET /valid_location, and finally restart the HAProxy using rhc cartridge-restart --cartridge haproxy. You can check the status of your gears by going to http://myapp-myusername.rhcloud.com/haproxy-status.

Hope this will help you.

Shekhar
  • 5,771
  • 10
  • 42
  • 48
  • 1
    It's working, thank you! I have created a `/ping` endpoint and used that as a reference for HAProxy's `httpchk`. – frapontillo Apr 29 '14 at 13:58
  • I can't explain how lost i was, and how clearly I understand the problem after reading this answer. – oooyaya Mar 04 '15 at 16:55