Wrong visualization of Sails.js project deployed on Openshift - node.js

I deployed my Sails project on Openshift.
It works but I receive errors with websockets and I don't able to load pages built on ejs.
I found these links enough explanatory about grunt/openshift, but I am not able to solve the problem.
Deploying Sails.js On Openshift
Deploy Sails.js on Openshift ... app restarting over and over
My nodejs.log is:
DEBUG: Running node-supervisor with
DEBUG: program 'app.js'
DEBUG: --watch '/var/lib/openshift/537b5ae8500446c95900057f/app-root/data/.nodewatch'
DEBUG: --ignore 'undefined'
DEBUG: --extensions 'node|js|coffee'
DEBUG: --exec 'node'
DEBUG: Starting child process with 'node app.js'
DEBUG: Watching directory '/var/lib/openshift/537b5ae8500446c95900057f/app-root/data/.nodewatch' for changes.
Warning: connection.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
^[[32minfo^[[39m:
^[[32minfo^[[39m:
^[[32minfo^[[39m: Sails.js <|
^[[32minfo^[[39m: v0.9.16 |\
^[[32minfo^[[39m: /|.\
^[[32minfo^[[39m: / || \
^[[32minfo^[[39m: ,' |' \
^[[32minfo^[[39m: .-'.-==|/_--'
^[[32minfo^[[39m: `--'-------'
^[[32minfo^[[39m: __---___--___---___--___---___--___
^[[32minfo^[[39m: ____---___--___---___--___---___--___-__
^[[32minfo^[[39m:
^[[32minfo^[[39m: Server lifted in `/var/lib/openshift/537b5ae8500446c95900057f/app-root/runtime/repo`
^[[32minfo^[[39m: To see your app, visit http://127.2.95.129:8080
^[[32minfo^[[39m: To shut down Sails, press <CTRL> + C at any time.
^[[34mdebug^[[39m: --------------------------------------------------------
^[[34mdebug^[[39m: :: Wed May 21 2014 14:26:01 GMT-0400 (EDT)
^[[34mdebug^[[39m:
^[[34mdebug^[[39m: Environment : production
^[[34mdebug^[[39m: Host : 127.2.95.129
^[[34mdebug^[[39m: Port : 8080
^[[34mdebug^[[39m: --------------------------------------------------------
^[[31merror^[[39m: Server doesn't seem to be starting.
^[[31merror^[[39m: Perhaps something else is already running on port 8080 with hostname 127.2.95.129?
^[[32minfo^[[39m: handshake authorized qR_aOT3qx40k6X34CF-2
^[[32minfo^[[39m: handshake authorized tnAUouwi-d32h82rCF-3
^[[33mwarn^[[39m: websocket connection invalid
^[[32minfo^[[39m: transport end (undefined)
^[[31merror^[[39m: Error rendering view at :: /var/lib/openshift/537b5ae8500446c95900057f/app-root/runtime/repo/views/viewshows/index
^[[31merror^[[39m: Using layout located at :: /var/lib/openshift/537b5ae8500446c95900057f/app-root/runtime/repo/views/layout
^[[31merror^[[39m: Error: Failed to lookup view "viewshows/index"
at Function.app.render (/var/lib/openshift/537b5ae8500446c95900057f/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/application.js:495:17)
at ServerResponse.res.render (/var/lib/openshift/537b5ae8500446c95900057f/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/response.js:798:7)
at ServerResponse._addResViewMethod.res.view (/var/lib/openshift/537b5ae8500446c95900057f/app-root/runtime/repo/node_modules/sails/lib/hooks/views/index.js:297:15)
at module.exports.index (/var/lib/openshift/537b5ae8500446c95900057f/app-root/runtime/repo/api/controllers/ViewShowsController.js:32:13)
at _bind.enhancedFn (/var/lib/openshift/537b5ae8500446c95900057f/app-root/runtime/repo/node_modules/sails/lib/router/bind.js:375:4)
at callbacks (/var/lib/openshift/537b5ae8500446c95900057f/app-root/runtime/repo/node_modules/sails/node_modules/express/lib/router/index.js:164:37)
Here my app.js:
require('sails').lift(require('optimist').argv);
Here my local.js:
module.exports = {
host: process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1",
port: process.env.OPENSHIFT_NODEJS_PORT || 8080,
environment: process.env.NODE_ENV || 'development'
}
Calling 'env | grep OPENSHIFT_NODEJS_PORT' on openshift console I receive:
OPENSHIFT_NODEJS_PORT=8080
In my opinion the problem isn't the port. The server start and answer correctly.
But when I call a page built on ejs it answer me with a piece of json...
{"view":{"name":"viewshows/index","root":"/var/lib/openshift/537b5ae8500446c95900057f/app-root/runtime/repo/views","defaultEngine":"ejs","ext":".ejs"}}
...and print the error above in the server log.
Any suggestion?
Thanks

I'm fairly certain that openshift requires your application to listen to a specific port, specified by an environmental variable, not 8080
You're going to want to change your app.js to to use the hostname and port env variables in this openshift doc

Related

how to remove sails js default log messages

Please how to remove this default log messages that are displayed when "sails lift" that also written to my external log files :
info: Starting app...
debug: Deprecation warning: Support for `sails.config.sockets.onConnect` will be
removed in an upcoming release. See the v0.11 migration guide for more informat
ion and alternate options.
info:
info: .-..-.
info:
info: Sails <| .-..-.
info: v0.12.4 |\
info: /|.\
info: / || \
info: ,' |' \
info: .-'.-==|/_--'
info: `--'-------'
info: __---___--___---___--___---___--___
info: ____---___--___---___--___---___--___-__
info:
info: Server lifted in `E:\Orange\sailsJS_workspace\server`
info: To see your app, visit http://localhost:1337
info: To shut down Sails, press <CTRL> + C at any time.
debug: -------------------------------------------------------
debug: :: Wed Nov 02 2016 12:03:45 GMT+0200 (Egypt Standard Time)
debug: Environment : development
debug: Port : 1337
debug: -------------------------------------------------------
Just add:
noShip: true
To file: config/log.js
For other default log messages play with "level", it's documented in comments at beginning of file.
Set level: to silent in the log.js
Ex:
module.exports.log = {
custom: blahblahBlah,
inspect: false
level: 'info'
};

Why is my application not being deployed on OpenShift?

I believe I have everything set up properly for my server but I keep getting this error
Starting NodeJS cartridge
Tue Jan 05 2016 10:49:19 GMT-0500 (EST): Starting application 'squadstream' ...
Waiting for application port (8080) become available ...
Application 'squadstream' failed to start (port 8080 not available)
-------------------------
Git Post-Receive Result: failure
Activation status: failure
Activation failed for the following gears:
568be5b67628e1805b0000f2 (Error activating gear: CLIENT_ERROR: Failed to
execute: 'control start' for /var/lib/openshift/568be5b67628e1805b0000f2/nodejs
#<IO:0x0000000082d2a0>
#<IO:0x0000000082d228>
)
Deployment completed with status: failure
postreceive failed
I have my git repo set up with all the steps followed properly.
https://github.com/ammark47/SquadStreamServer
Edit: I have another app on openshift that is on 8080. I'm not sure if that makes a difference.
If the other application is running on the same gear, then it is binding to port 8080 first, making it unavailable for your second application. You will need to run each application on it's own gear. Also, you need to make sure that you are binding to port 8080 on the correct IP address for your gear, you can't bind to 0.0.0.0 or 127.0.0.1

Openshift app is getting SIGTERM each 6 hours

I am playing with node.js in OpenShift. I have realized that my app is getting SIGTERM periodically each 6 hours.
Log looks like this:
DEBUG: Sending SIGTERM to child...
DEBUG: Running node-supervisor with
DEBUG: program 'app/run.js'
DEBUG: --watch '/var/lib/openshift/<appId>/app-root/data/.nodewatch'
DEBUG: --ignore 'undefined'
DEBUG: --extensions 'node|js|coffee'
DEBUG: --exec 'node'
DEBUG: Starting child process with 'node app/run.js'
DEBUG: Watching directory '/var/lib/openshift/<appId>/app-root/data/.nodewatch' for changes.
Is this an OpenShift feature? How can I disable it?

Starting NodeJS on OpenShift without EADDRINUSE errors

I am trying to get NodeJS to run on OpenShift, do encounter the same issue though no matter what. Here is an example:
UPDATE with more details <<<<<
FIRST:
This piece of code works fine straight out of Cloud9
var port = process.env.PORT || "127.0.0.1";
var ipaddress = process.env.IP || 8080;
console.log("Getting started here!");
var http = require('http');
var server = http.createServer(function(request, response) {
console.log((new Date()) + ' Received request for ' + request.url);
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write("Welcome to Node.js on OpenShift!\n\n");
response.end("Thanks for visiting us!!!! \n");
});
server.listen( port, ipaddress, function() {
console.log((new Date()) + ' Server is listening on port 8080');
});
console.log("Listening to " + ipaddress + ":" + port + "...");
However as soon as I push it to my OpenShift account changing the port and ipaddress variables to:
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
... I am getting this on the OpenShift VM when I SSH over, change to app-root/runtime/repo and run node server.js:
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:901:11)
at Server._listen2 (net.js:1020:19)
at listen (net.js:1061:10)
at Server.listen (net.js:1129:5)
That would indicate the port is in use already, right? I changed the port to 15550 as I have read somewhere here on stackoverflow I assume that a specific port range is not directly available - only via port forwarding.
Guess what, I just get a different error (EACCES).
Here are the processes running on my OpenShift VM (as far as I can see with my account):
PID TTY STAT TIME COMMAND
177800 ? S 0:00 sshd: XXXX#pts/1
177801 pts/1 Ss 0:00 /bin/bash --init-file /usr/bin/rhcsh -i
210176 pts/1 R+ 0:00 ps ax
SECOND:
I wonder how I can cut down the build process? When I push my code to OpenShift this is what I get:
remote: /bin/sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
remote: /bin/bash: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
remote: /bin/bash: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
remote: sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
remote: sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
remote: Stopping NodeJS cartridge
remote: Wed Mar 18 2015 07:27:49 GMT-0400 (EDT): Stopping application 'nodejs' ...
remote: Wed Mar 18 2015 07:27:50 GMT-0400 (EDT): Stopped Node application 'nodejs'
remote: /bin/sh: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
remote: /bin/bash: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
remote: /bin/bash: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8)
remote: Saving away previously installed Node modules
remote: Building git ref 'master', commit e8239d1
remote: Building NodeJS cartridge
The whole process takes like 10 seconds or more. I am not sure what exactly is happening behind the scenes but it seems to be a lot.
So my second questions, is there a way to cut that build time down?
I tried to create an empty file in the .opengit/markers directory as I have read somewhere, but it did not help to improve anything.
Thanks for your help!
z4c
.. I am getting this on the OpenShift VM when I SSH over, change to app-root/runtime/repo and run node server.js
Don't manually run the server yourself. When you push your code to OpenShift, it stops the server, does the build, deploys the code, and starts the server.
So the server is already running. That's why you're getting Error: listen EADDRINUSE try running it yourself. It won't let you run on your own port. That's why you're getting (EACCES) trying to run it on 15550.
If you need to start/stop/restart the server, use OpenShift's rhc command or from the admin console.
For your 2nd question: is there a way to cut that build time down?
The answer is yes. Setting up hot deploy will save you few seconds (by creating an empty file .openshift/markers/hot_deploy) or change the script not to do the build but that's not a good idea. It's doing what it's supposed to do. The right way to cut down the down time to 0 (unless OpenShift is down) is to use the load balancing feature OpenShift offers. It can run 2+ servers at a time. So when you push your code, it stops 1 server while the other servers are still taking requests. Once the 1st server is back up, it'll rebounce the 2nd (and the rest of the servers)

OpenShift socket.io : express deprecated app.configure: Check app.get('env')

After setting client and server side of socket.io, what I think are the right links, now something else sprung up.
My assumption is - I am using an old express version or one that is too new for the code I have?
DEBUG: Program node server.js exited with code 0
DEBUG: Starting child process with 'node server.js' Tue, 29 Jul 2014 13:51:04 GMT express deprecated app.configure: Check app.get('env') in an if statement at server.js:11:5 info: socket.io started warn: error raised: Error: listen EACCES
DEBUG: Program node server.js exited with code 0
DEBUG: Starting child process with 'node server.js' Tue, 29 Jul 2014 13:51:06 GMT express deprecated app.configure: Check app.get('env') in an if statement at server.js:11:5 info: socket.io started warn: error raised: Error: listen EACCES
Any guidance?
For the deprecated function app.configure just use app.use without using app.configure, and for the error Error: listen EACCES check if you have anything listening in the port you are trying to start your server.js

Resources