Unable to deploy Node app to Openshift - javascript

I'm trying to deploy a simple ExpressJS app I have to Openshift using the command line tools. I've provided a debug trace below:
>npm info ok
Preparing build for deployment
Deployment id is 5e2abc99
Activating deployment
HAProxy already running
HAProxy instance is started
Starting NodeJS cartridge
Sat Aug 15 2015 15:17:47 GMT-0400 (EDT): Starting application 'xxxxx' ...
Waiting for application port (8080) become available ...
Application 'xxxxx' failed to start (port 8080 not available)
and
Git Post-Receive Result: failure
Activation status: failure
Activation failed for the following gears:
55cf8fc589f5cf9dbf00023c (Error activating gear: CLIENT_ERROR: Failed to execute: 'control start' for /var/lib/openshift/55cf8fc589f5cf9dbf00023c/nodejs
#<IO:0x00000001ec7290>
#<IO:0x00000001ec7218>
>)
Deployment completed with status: failure
postreceive failed
However my app is listening on port 8080:
app.listen(process.env.OPENSHIFT_NODEJS_PORT || 8080);
Can anyone help?
Deploying an empty application doesn't seem to throw any errors.

Have you checked the log on the server? I was encountering a similar issue and it was because I had syntax errors in my script. If you SSH into your application and
tail app-root/logs/nodejs.log
you can see the console output for the app. Use -n [# of lines] to view more of the log if 10 isn't enough or use less and press shift + g to view the document starting at the bottom if you want to scroll up and down through it all.

Try to login via ssh to your openshift node. I use the rhc tool. Run your code and you will see where the problem is.

Related

Error 1016 when executing Argo Tunnel from Node child_process

Cloudflare Argo Tunnel from Node child_process
I have an electron app from which I would like to spawn a child process that executes
cloudflared tunnel --url localhost:3000
inside a certain directory. Executing this from cmd inside that directory instantiates the argo tunnel as expected, and the url works while the process is running. This is how I am executing the command from the electron app:
const { spawn } = require('child_process')
let tunnel = spawn('cloudflared', ['tunnel', '--url', 'localhost:4000'], {
stdio: 'inherit', // Will use process .stdout, .stdin, .stderr
cwd: 'c://cloudflare'
})
I can see the normal console output from cloudflare indicating that the tunnel has been established and my server is responding at some-random-name.trycloudflare.com. However, when the process is started from within the electron app, I get Error 1016 displayed on a cloudflare error page.
Does anyone have experience with Argo Tunnel and child_process?
I was able to get your setup to work on my Mac without issue, so you need to look further into the details of your setup. Here is what I did:
Installed Electron Fiddle v0.9.0 from GitHub
Installed cloudflared version 2019.8.4 via homebrew with
brew install cloudflare/cloudflare/cloudflared
From the command line (Terminal window), ran
cloudflared tunnel --url localhost:3000
cloudflared had some complaints:
Cannot determine default configuration path. No file [config.yml config.yaml] in [~/.cloudflared ~/.cloudflare-warp ~/cloudflare-warp /usr/local/etc/cloudflared /etc/cloudflared]
cloudflared will not automatically update when run from the shell
unable to connect to the origin error="Get http://localhost:3000: dial tcp [::1]:3000: connect: connection refused"
Started a web server on localhost:3000 with
python -m SimpleHTTPServer 3000
Loaded the page http://localhost:3000 in my browser
Again ran
cloudflared tunnel --url localhost:3000
Same complaints, except this time it was able to connect:
Proxying tunnel requests to http://localhost:3000
Further output from cloudflared indicated it was bringing up 4 tunnels. For each tunnel, it output
+-----------------------------------------------------------+
| Your free tunnel has started! Visit it: |
| https://sides-universe-gym-metadata.trycloudflare.com |
+-----------------------------------------------------------+
Route propagating, it may take up to 1 minute for your new route to become functional
Note that I did not change or obfuscate the URL, that is exactly what was output, and cloudflared output the same URL 4 times, once for each tunnel.
I went to https://sides-universe-gym-metadata.trycloudflare.com and verified it displayed the same website I had brought up on localhost:3000.
I quit cloudflared by typing ctrl-c in the Terminal window where it was running. It took quite some time to shut down, but I waited until it quit.
I went to https://sides-universe-gym-metadata.trycloudflare.com and verified it displayed an error. It displayed "Error 1016" and "Origin DNS error".
In Electron Fiddle, I selected Electron v6.0.6 and used the default, pre-installed main.js, index.html, and renderer.js. In main.js, I added at the bottom
const { spawn } = require('child_process')
let tunnel = spawn('cloudflared', ['tunnel', '--url', 'localhost:3000'], {
stdio: 'inherit', // Will use process .stdout, .stdin, .stderr
cwd: '/Users/user/development'
})
I clicked "Run" on Electron Fiddle. The "Hello World!" page came up. The Electron Console showed output from cloudflared.
Again cloudflared brought up 4 tunnels, each with the URL https://citysearch-celebs-generator-history.trycloudflare.com
cloudflared then logged:
cloudflared has been updated to version 2019.8.4
PID of the new process is 81076
Quitting...
Metrics server stopped
I have no idea why it "updated" from "2019.8.4" to "2019.8.4". Maybe it has something to do with not having a default configuration, maybe it had something to do with Electron Fiddle running it from a non-standard location. I suspect it is because the command line did not include --is-autoupdated=true.
Immediately after "Metrics server stopped" cloudflared started logging its startup messages, just as before.
Again it brought up 4 tunnels, this time with URL https://gifts-jpg-treasury-correct.trycloudflare.com
Total time elapsed from start through restart to last stable tunnel up: 14 seconds.
I went to https://gifts-jpg-treasury-correct.trycloudflare.com in my local browser and again got the site I was hosting at localhost:3000.
I hit "Stop" in Electron. The Electron server stopped, but cloudflared kept running. I could still load https://gifts-jpg-treasury-correct.trycloudflare.com/
I hit "Run" in Electron. Again cloudflared brought up 4 tunnels. This time it did not auto-update or restart. The 4 new tunnels all had the same new URL: https://reject-pride-built-twisted.trycloudflare.com/
I went to https://reject-pride-built-twisted.trycloudflare.com/ in my local browser and again got the site I was hosting at localhost:3000. I tried https://gifts-jpg-treasury-correct.trycloudflare.com and it, too, was still working.
So I cannot reproduce your problem. Possible issues are that you may have been looking at the first tunnel that came up but cloudflared had updated, closed that tunnel, and started a different one. This worked for me on Mac but it seems you are working on Windows so it could be some Windows-specific issue. It could be that you do not have a server running on localhost:4000 or that your Electron app cannot access C://clouflare.
You need to provide more information, such as the log output of your Electron app running cloudflared and details about the server running at localhost:4000 and any cloudflared configuration files you have set up.
Common cause
Cloudflare cannot resolve the origin web server’s IP address.
Common causes for Error 1016 are:
A missing DNS A record that mentions the origin IP address.
A CNAME record in Cloudflare DNS points to an unresolvable external domain.
The origin host names (CNAMEs) in your Cloudflare Load Balancer default, region, and fallback pools are unresolvable. Use a fallback pool configured with an origin IP as a backup in case all other pools are unavailable.
Resolution
To resolve error 1016:
1) Verify your Cloudflare DNS settings include an A record that points to a valid IP address that resolves via a DNS lookup tool.
2) For a CNAME record pointing to a different domain, ensure that the target domain resolves via a DNS lookup tool.

how can I connect to a http://localhost:4200 using browser which is a aws ec2

I am learning node.js in an online course to build up a web server and app
before the teaching started, the teacher told me to set up your coding environment, and it got a direction to told me what to do step by step.
Because I using Chromebook, So I started an aws ec2 serve which is ubuntu 18.04 and using cloud9 for my ide
I installed node.js successful on the ec2
And the direction told me to type on those on the terminal
git clone https://github.com/OpenClassrooms-Student-Center/5614116-front-end-app.git frontend
You can then do the following:
cd frontend
npm install
ng serve
This will install all the dependencies needed by the front end app and will launch the development server. Now, if you navigate to http://localhost:4200 , you should see the following (assuming you've followed the steps above successfully):
the direction say if I successfully followed the step, will see something on http://localhost:4200
On the terminal, at last show me
ℹ 「wdm」: Compiled successfully.
But how can I connect to http://localhost:4200 which was an ec2?
I tried using IP:4200, the browser keeps on loading the page and nothing shows up on the browser
----------------------------------------
I found out that the program that teacher gave me to install set the URL to http://localhost:4200
because cloud9 says the program was running, but running at a URL call http://localhost:4200
what should I do?
Localhost refers to your local machine. But as mentionedd that your node.js running on ec2 and want to connect to it from your browser, get the IP of the ec2 and type in your browser- IP:4200
And it should work
The only problem here is you have to add port 4200 in your aws ec2 instance security group to allow inbound traffic.
STEPS:
1. Go to your EC2 instance.
2. Click security group from Description below.
3. Click Inbound then Edit.
4. Click Add Rule
5. Select Custom TCP , Port - 4200 , IP - 0.0.0.0/0
6. Then SAVE.
After that try <EC2-IP:Port> in your browser it will work fine.

keep getting "? Something is already running on port 3000" when I do npm start on react app

I keep on getting "? Something is already running on port 3000" message in my terminal when I start up my react server when there is absolutely nothing running on my port 3000
What I have tried to solve with:
Restart the macOS.
checking my "http://localhost:3000" on chrome browser. (Nothing: This site can’t be reached)
Go to chrome://serviceworker-internals and chrome://appcache-internals, search for localhost:3000 (Nothing found)
I also tried almost every command lines I found on Google regarding this issue
I also created another express.js app, and it was successfully launch on port 3000 while React said there is something running on 3000. React on my computer just keeping thinking there is something running on port 3000.
If you are a windows user you can try using
npx kill-port 3000
in your console. I was having the same problem and it worked for me.
Not sure about MAC.
Open cmd and write this
netstat -a -o -n
You will get list of active connections then find 3000 by hitting
Cntrl + f
Copy the PID of that port and hit this command
taskkill /F /PID PID_of_port
Edit
This guide is for windows.
Kill Node.Js process from Task Manager.
Step 1: Open Task Manager by clicking ctrl+shift+delete
Step 2: Open Prcesses tab
Step 3: Search for Node.JS process and right click on that then click on End Task
Step 4: Now you can start again.
As #khurram khan suggested terminating the process may be the best option for you, This work for me on linux:
$ lsof -i tcp:3000
$ kill -9 PID
the first command should give you the PID number to enter in the second command as PID.
I had this problem on Mac and I solved by running:
npx kill-port 3000
I had stuck with this one for few hours, and the end I had found the solution
There was incorrect mapping to the local host in the hosts file and didn't had any relation to the port taken something like
10.2.224.130 localhost
Just Change it back to
127.0.0.1 localhost
Host file locations
https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/
In case anyone comes across this and the above solutions didn't help, make sure your /etc/hosts has:
127.0.0.1 localhost
For some reason this was wiped from my hosts file and CRA's dependency for checking ports (detect-port-alt) checks localhost:[PORT] to see if it's available. If it errors out, you'll always get the "Something is already running..." error when checking a specific port but not when using a random port (since that's picked by the dependency).
kill node.js from the background processes. that would soleve the probelem. alterntively, you could restart your system
for window use this in package.json
"start": "set PORT=3006 && react-scripts start"
for Linux and MacOS
"start": "PORT=3006 react-scripts start"
This worked for me on windows pc. This one is for those are not seeing the port when you run this command netstat -a -o -n on your command prompt.
Open your command prompt in administrator mode and run this command
net stop winnat
you'll get this response:
The Windows NAT Driver service was stopped successfully.
Them you run this next:
net start winnat
then you will get this response:
The Windows NAT Driver service was started successfully.
once you do that. Start the react server and it would work. Same too if your backend server doesn't run on 3000
It's very simple. You can fix it in 2 easy steps.
Check your environment variables if there is a key/entry with name "PORT".
If found delete that entry or rename it to something else.
It turns out that some other program is using that variable. Usually when you start react-scripts it will look for an environment variable with that title PORT.
Date: Sat 07, October 2020
Windows: Microsoft Windows 10 Pro Build 19041
Node: 12.16.1
NPM: 6.14.8
Something similar was happening to me on my Windows machine. Tried a lot of things suggested here on StackOverflow and other places.
In my case, I was following a video course that was suggesting adding --script-version 1.1.5 (as illustrated below) when creating a new React app.
create-react-app app-name --scripts-version 1.1.5
Here's the package.json scripts versions:
React: 17.0.1
React DOM: 17.0.1
React Scripts: 1.1.5
After running the command npm start and typing y to try to use a different port, the terminal will stay stucked until it was canceled.
Then I created a new React app without --scripts-version 1.1.5 and after trying to running it, it was still running into Something is already running on port 3000 but after typing y, the app will run with no problem on a different port.
Here's the package.json scripts versions (when it was running successfully):
React: 17.0.1
React-Dom: 17.0.1
React-Scripts: 4.0.0
Starting with the reason you do not see anything on localhost:3000, is because there must be a proper webapp or a website/server running on that port, but the port:3000 is currently running some process, just not of a server/site/app.
This out of the way, depending on your type of OS, it is quite easy to check if there is in-fact a process on port:3000 or not. For MacOS, opening a terminal and running sudo lsof -i ':3000' will list the current process on port 3000.
Note that we need to run command as sudo or root
Once you see what process is running, note the PID and run kill -9 {PID}, which should kill the process with PID (i.e distruptive process on port:3000). Now doing a npm start should get your app built, compiled and served on localhost:3000
Mostly what might've happened is that you had a npm start running which you either interrupted, or closed in the foreground. Doing a fg in your terminal will open any background tasks, so if this opens a npm start instance, it was this process stopping your flow. You can then properly end the session making sure all processes on port:3000 are killed.
Happy coding
If you are on linux you can try
pkill -f node
to terminate the processs
The error occurs when a task is left running on the port properly killing it.
this error can occur on both ports. Your react app and your node server.
To solve this you can run the following commands.
netstat -anp tcp | grep 3000
This command in the terminal will give you the list of activities on port 3000
npx kill-port 3000
This command will kill all the running servers on port 3000.
Now if you have the same problem for your Node server. You can follow the same steps.
netstat -anp tcp | grep 5000
Then
npx kill-port 5000
You don't need the first command. it's just to list out the running activities on the port.
just change the port number for any other port number.
This is the output you get after running the commands.
I am using Git bash on windows.
For me, this works every time (macOS): sudo kill -9 $(sudo lsof -t -i:3000)
Simple and Easy solution
close your current terminal and open a new one.
If you are running it in VS Code just create a new terminal and delete the old one.
On React - you can run an already created React single-page application (SPA) by
npm start command.
That may start your locally hosting development server and runs your app at:
http://localhost:3000/ which is equivalent to: 127.0.0.1:3000 address
127.0.0.1 is the default localhost IP number while the default port number set by
create-react-app package is 3000.
When getting: “Something is already running on port 3000" failure error message you may think that the port captured by another process running on your machine but you’ll find that it is captured permanently as if it runs on 0.0.0.0:3000 address
Solution:
In your project libraries created by create-react-app script navigate to:
node_modules/react-scripts/scripts/start.js
While running npm start command - the start.js script is being called and executed
There at start.js file in you editor find the above line:
const HOST = process.env.HOST || '0.0.0.0';
and change it to:
const HOST = process.env.HOST || '127.0.0.1';
save and run your web app again at: http://localhost:3000/ or http://127.0.0.1:3000

Meteor deployed on server, but browser says site can't be reached

So I've deployed my meteor app, and have it up and running on an instance.
I've used the following environment variables:
MONGO_URL='mongodb://localhost:27017/meteor'
ROOT_URL='http://<my static ip>'
PORT=3000
And I run the program using the following command:
node bundle/main.js
It prints my "Meteor is starting up" that is printed using the console.log command, and then doesn't error out, but when I navigate to http://< my static ip >:3000 in a browser, I get an ERR_CONNECTION_REFUSED result.
My open mongod terminal says it's connecting fine to the MongoDB database.
Does anyone have any ideas on how to start debugging this issue?
Thanks.
In server you don't need to run meteor application on port 3000. You can run it on port 80 if the port is not being used by any other program.
If you are using port 80 make sure port 80 is opened by the network security rules.
If you are using port 3000 or any other port you will have to make sure that port is opened by the network security rules as above. Additionally you will have to mention the IP in your url, like http://<your_ip>:<port>

MONGO_URL for running multiple Meteor apps on one server

I have one Meteor application running on my Ubuntu server (Digital Ocean). I use Meteor Up (MUP) to deploy and keep the app running. Everything works fine.
However, when I try to deploy a second app on the same server, something goes wrong in connecting to the MongoDB. I get a long and unreadable error message that starts "Invoking deployment process: FAILED" and then ends with
Waiting for MongoDB to initialize. (5 minutes)
connected
myapp start/running, process 25053
Waiting for 15 seconds while app is booting up
Checking is app booted or not?
myapp stop/waiting
myapp start/running, process 25114
And the app refuses to run. I have tried a number of things to fix this and will edit this post if more info is requested, but I'm not sure what's relevant. Essentially I don't understand the Error message, so I need to know what the heck is going on?
EDIT:
I want to add that my app runs fine if I go into the project folder and use the "meteor" command. Everything runs as expected. It is only when I try to deploy it for long-term production mode with MUP that I get this error.
EDIT:
I moved on to trying mupx instead of mup. This time I can't even get past the installation process, I get the following error message:
[Neal] x Installing MongoDB: FAILED
-----------------------------------STDERR-----------------------------------
Error response from daemon: no such id: mongodb
Error: failed to remove containers: [mongodb]
Error response from daemon: Cannot start container c2c538d34c15103d1d07bcc60b56a54bd3d23e50ae7a8e4f9f7831df0d77dc56: failed to create endpoint mongodb on network bridge: Error starting userland proxy: listen tcp 127.0.0.1:27017: bind: address already in use
But I don't understand why! Mongod is clearly already running on port 27017 and a second application should just add a new database to that instance, correct? I don't know what I'm missing here, why MUP can't access MongoDB.
It's tricky without your mup.json to see what's going on here. Given what you said, it looks like your 2nd app deployment tries to override/boot mongodb over the 1st one which is locked, the mongodb environment fails to boot, causing then the fail. You should tackle this different ways:
If your objective is to share your mongoDB, point the MONGO_URL from your 2nd mup.jon on your first mongodb instance. It's generally something along the 2701X ports. As it's a shared DB, changes in one database could affect the other.
meteor-up oversees the deployment of your app from a meteor-nice-to-test thing to a node+mongodb environment. You can spawn another mongod instance with :
mongod --port 2701X --dbpath /your/dbpath --fork --logpath /log/path on your DO server and then point MONGO_URL there.
Last but not least, mupx having docker under the hood. Using mupx for your deployments should isolate both apps from each other.

Categories