What does "app started" in cloudfoundry mean - node.js

I read the cloudfoundry documents on how to push/start application:
Starting Applications
Deploy an Application
But neither of them tells when the cf push command or cf start command exits.
Starting app locally
For example, I have a nodejs application which can be started by command npm start which will keep blocking when running on local machine like:
$ npm start
> my-app#0.0.1 start /example-deployment-cf
> node index.js
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
I never know when the nodejs listens to tcp port except I print out something in my application by kind of event handler for "start" event.
pushing app to cloudfoundry
$ cf push
...
1 of 1 instances running
App started
Showing health and status for app shawnzhu-test-node in org me#example.com / space dev as me#example.com...
OK
requested state: started
instances: 1/1
usage: 512M x 1 instances
urls: shawnzhu-test-node.pivotal.io
state since cpu memory disk
#0 running 2014-05-12 02:32:05 PM 0.0% 56.1M of 512M 26.4M of 1G
it just simply (and magically) tells "App started" but didn't tell when (and why).
In real world, there will be lots of function calls in npm start like page generation and the app may not ready after cf push command exits. So I still need to use event handlers in code to print out log entries like "finished generating pages".
So my simple question is, what is the actual meaning of "app started" in cloudfoundry (before reading its code).

If a route is assigned to the pushed app (like shawnzhu-test-node.pivotal.io in your case), then Cloud Foundry will check that the URL returns a 200 and report that it is running as soon as it does.
You can also do "cf logs shawnzhu-test-node" to see more detailed output from the app startup process.

Related

Safely Undeploying / Redeploying on MERN Stack using PM2 and yarn?

I am running a web service on a reasonably standard MERN stack on a Ubuntu server. I am not overly familiar with web deployment or web programming but I have found myself with this project.
The web service has a pretty extensive list of instructions on how to deploy the service, but it has no instructions on how to undeploy / redeploy it. In addition, it was the sellers of the service's code that deployed it on our server.
I have made some minor changes to the code (fixing spelling, removing / adding functionality) and I cannot seem to work out how to safely undeploy or redeploy the service.
The list of instructions for deployment is, essentially:
yarn
yarn build
yarn start:prod
pm2 start dist/main.js
Doing this as-is while the old service is running obviously doesn't work as the port that I am trying to relaunch on is being watched. Stopping the pm2 process allowed me to redeploy using the above method but has now caused a 502 Gateway error when I relaunch the process.
What is the safe method to undeploy and / or redeploy a service using this tech stack?
You first may want to have a look around on your ubuntu server.
PM2 is like a service manager. To get a list of running services, run this command.
pm2 ls
A typical output:
Typically when you install an update, you just need to restart them.
pm2 restart <service-name>
e.g. pm2 restart cache in my example

node-opcua-samples - simple_client.js does not connect to simple_server.js

i'm trying to gain deeper knowledge of using opc. So i installed node js and then node-opcua-samples via npm.
Afterwards i went to powershell, changed cwd to the bin directory of node-opcua-samples and started simple_server.js with
node simple_server.js
The server is starting and prints
server now waiting for connections. CTRL+C to stop
to the console. Then it prints
contacting discovery server backoff opc.tcp://localhost:4840 attempt # 0 retrying in 2 seconds
server registration is still pending (is Local Discovery Server up and running ?)
From the output i expect to be able to connect to the running server, even though it shows the warning concerning the discovery server. Am i right?
The next step is to start simple_client.js in a second powershell by changeing the cwd to the bin directory of node-opcua-samples and then use
node simple_client.js >endpointUrl printed by server<
At this point i'm expecting the client to connect to the started server and complete the test cases build in. But the client seemingly is not able to connect to the server and prints
backoff attempt # 0 retrying in 2 seconds
Following the hint given inside of simple_client.js and running simple_client_ts.ts with ts-node results in the same behavior.
So where is my mistake?
Any hints or questions will be appreciated.
Regards
Gregor
Systemdetails for reproduction:
Windows 10
Node Version 12.13.0
node-opcua-samples Version 2.5.7
Ok, i solved the problem....
Instead of using the endpointUrl printed by the server, i had to start the client with the endpoint opc.tcp://localhost:26543. The used port is the default port set in simple_server.js.
The warning about the discovery server vanished after setting registerServerMethod in simple_server.js from RegisterServerMethod.LDS to RegisterServerMethod.HIDDEN.
Best regards
Gregor

How to increase deployment timeout for openshift nodejs app?

When I do git push and rhc tail <appname> in other terminal I can see that my server still does not start, but I have Application '<appname>' failed to start (port 8080 not available) in git push output.
When I use no-scaling app it wasn't a problem – all working good, but now, with scalable app I should manually restart haproxy after my server started (I can see it by rhc tail).
I know that solution present, at least for JBoss applications. It's here. But can I use it for my case or else what I should use?
Thanks for your attention.

Openshift Layer4 connection, App Won't Start

I recently pushed a set of node.js changes to an app on Openshift. The app runs fine on my local machine and is pretty close to the vanilla example deployed by Openshift. The Openshift haproxy log has this final line:
[fbaradar-hydrasale.rhcloud.com logs]> [WARNING] 169/002631 (93881) :
Server express/local-gear is DOWN, reason: Layer4 connection problem,
info: "Connection refused", check duration: 0ms. 0 active and 0 backup
servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
The nodejs.log has this final line and no error mesages before this line: DEBUG: Program node server.js exited with code 8
I have searched high and low and can't seem to find anyone with a similar problem or hints at how to resolve this issue. Obviously, the above result in a 503 Service Unavailable when trying to access the app over the web.
Looking at the question I think it is happening because you don't have any routes configured at root '/'. 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
Create an index.html and push it to OpenShift application
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.
Thanks for the response! However, I just discovered what the issue was by rolling back and making one change at a time. There was a buried npm dependency down in a subfile. This dependency had not been added to the package.json file and Openshift was failing to rebuild node appropriately. Once the dependency was added everything started to run again. The log errors were a bit of a red herring and simply a side effect of not having a good application to start!

how to keep a node server app running on windows server

I'm working on a project and I have modified node.js' 'simple chat room' sample application for my need, it works fine.
I have to call the server app's url (the .js file) to start it before opening the client page in the browser, so far everything works fine. But if the node server app goes down for any reason (server restart, iis restart, etc), the client page returns an error .
My question is, how can I keep the node server app alive all the time even after it interrupted. How can I do that without having a monitor or a script which runs every x minutes.
I'm using IIS 7.5 and iisnode module.
Thanks
Run your script file, as a service, with nssm.
Pretty sure you'll want jesus
Installation
$ npm install -g jesus
Usage
Start monitoring server
$ jesus daemon /path/to/server.log
To start a process
$ jesus start <id> node /path/to/my-app/index.js
To stop one
$ jesus stop <id>
To stop all
$ jesus stopall
I'm not sure about running node in iis. However, you can take a look at the node packages forever, pm2, and nodemon, which will recover the instance in case of failure.
Here's how to install node.js as a service
Here's something on installing node in iis 7.5
Just an update.
I've been using iisnode at work for the better part of a year. I would recommend it if you are deploying to Windows.
https://github.com/isaacs/node-supervisor and https://github.com/remy/nodemon have slightly different feature sets, but aren't Windows specific and still work on Windows unlike many of the other more popular, yet incomplete options such as forever and eternity (as of today anyway).

Resources