Error deploying a node.js app to Elastic Beanstalk on Amazon Linux 2 - node.js

I am trying to have a node js app on Elastic Beanstalk.
On Amazon Linux Image the environment gets created and works smooth.In order to get it done I followed the instructions given in the AWS documentation itself. It works on single instance.Also,using Nginx and have terminated HTTPS on the instance by following the info here
The root directory of the app contains:
.ebextensions
index.js
package.json
By following all those instructions step by step given in AWS documentation the environment is created and the app is deployed successfully(For Amazon Linux Image).
However, been trying to deploy it to Amazon Linux 2.And the deployment fails with the Health status for the environment being "DEGRADED".
A snippet of the eb-engine.log:
[INFO]
> grpc#1.24.3 install /var/app/staging/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library
Failed to execute '/opt/elasticbeanstalk/node-install/node-v10.15.1-linux-x64/bin/node /opt/elasticbeanstalk/node-install/node-v10.15.1-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --library=static_library --module=/var/app/staging/node_modules/grpc/src/node/extension_binary/node-v64-linux-x64-glibc/grpc_node.node --module_name=grpc_node --module_path=/var/app/staging/node_modules/grpc/src/node/extension_binary/node-v64-linux-x64-glibc --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
Snippet of the web.stdout.log:
Sep 13 12:55:31 ip-172-31-1-73 web: > nodetryapp#1.0.0 start /var/app/current
Sep 13 12:55:31 ip-172-31-1-73 web: > node index.js
Sep 13 12:55:31 ip-172-31-1-73 web: [DEFAULT]
Sep 13 12:55:32 ip-172-31-1-73 web: events.js:174
Sep 13 12:55:32 ip-172-31-1-73 web: throw er; // Unhandled 'error' event
Sep 13 12:55:32 ip-172-31-1-73 web: ^
Sep 13 12:55:32 ip-172-31-1-73 web: Error: listen EACCES: permission denied 0.0.0.0:80
Sep 13 12:55:32 ip-172-31-1-73 web: at Server.setupListenHandle [as _listen2] (net.js:1260:19)
Snippet from nginx/error.log:
2020/09/13 13:06:31 [alert] 4023#0: *1021 1024 worker_connections are not enough while connecting to upstream, client: 127.0.0.1, server: , request: "GET /hudson HTTP/1.1", upstream: "http://127.0.0.1:80/hudson", host: "*SOME IP ADDRESS*"
For deploying the app on Amazon Linux 2 Elastic beanstalk the root folder of the app consists of the following files/folders:
.ebextensions/https-instance.config and .ebextensions/https-instance-single.config
.platform/nginx/conf.d/extendnginx.conf (In order to extend the nginx config so as to terminate the https at the instance)
index.js
package.json
The instance type is a Single instance, t2.micro.

You cannot run your application on port 80 and 443 because these ports are exclusive for Nginx/Apache service inside Beanstalk AMI. Instead of using these ports, use 8080 for HTTP connections and 8443 to HTTPS connections.

Yes, now it is working!So followed what #Raul Barreto said in his answer above.
Made the following changes:
The 'port' environment variable is now set to 8080.
In the .platform/nginx/conf.d/extendnginx.conf file added
upstream nodejs {
server 127.0.0.1:8080;
}
instead of
upstream nodejs {
server 127.0.0.1:80;
}

Related

OpenVPN client is not working on Windows computer?

I try to run my OpenVPN client on my windows 10 machine in order to connect to a remote OpenVPN CentOS 7 server but it does not work. I get the error below:
Options error: --capath fails with 'C:\Users\Desktop\OpenVPN\ca.crt': No such process (errno=3)
Options error: --cert fails with 'C:\Users\Desktop\OpenVPN\Win10client.crt': No such process (errno=3)
Fri Mar 22 22:56:20 2019 WARNING: cannot stat file 'C:\Users\Desktop\OpenVPN\Win10client.key': No such process (errno=3)
Options error: --key fails with 'C:\Users\Desktop\OpenVPN\Win10client.key'
Fri Mar 22 22:56:20 2019 WARNING: cannot stat file 'C:\Users\Desktop\OpenVPN\myvpn.tlsauth': No such process (errno=3)
Options error: --tls-crypt fails with 'C:\Users\Desktop\OpenVPN\myvpn.tlsauth': No such process (errno=3)
This is the config that I have on my ovpn file:
client
tls-client
--capath C:\\Users\\Desktop\\OpenVPN\\ca.crt
--cert C:\\Users\\Desktop\\OpenVPN\\Win10client.crt
--key C:\\Users\\Desktop\\OpenVPN\\Win10client.key
--tls-crypt C:\\Users\\Desktop\\OpenVPN\\myvpn.tlsauth
remote-cert-eku "TLS Web Client Authentication"
proto udp
remote serveraddress 1194 udp
dev tun
topology subnet
pull
Assuming your config file is well done. Try to reinstall openvpn, and put your config file to the c:/program files/openvpn/config folder. Then you can start the openvpn Service. Therefore you dont need to use the Openvpn gui.

Create Docker image for NodeJS + PostgreSQL web application

I've been reading Docker's documentation, but I can't get around creating an image that will work.
I have a NodeJS application that uses PostgreSQL as database:
var connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/db';
var pg = require('pg');
var pgp = require('pg-promise')();
var db = pgp(connectionString);
db.func('some_storedProcedure').then(//...)
//...
I first created a Dockerfile according to Node's documentation for it:
FROM node:argon
# Create app directory
RUN mkdir -p /app
WORKDIR /app
# Install app dependencies
COPY package.json /app
RUN npm install
# Bundle app source
COPY . /app
EXPOSE 5000
CMD [ "npm", "start" ]
I then followed this post regarding connecting the database to it with docker-compose. the docker-compose.yml file looks like:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/app
links:
- db
environment:
DATABASE_URL: postgres://myuser:mypass#db:5432/db
db:
image: postgres
environment:
POSTGRES_USER: myuser
POSTGRES_PASSWORD: mypass
This is (some) of what is returned when I run docker-compose up with these files, after creating the image.
npm info ok
---> 87dbbae35721
Removing intermediate container c73f826a0b3d
Step 6 : COPY . /app
---> ec56bfc11d3c
Removing intermediate container 745ddf82d742
Step 7 : EXPOSE 5000
---> Running in b2be5aecd9d6
---> a7d126a7ea5e
Removing intermediate container b2be5aecd9d6
Step 8 : CMD npm start
---> Running in 0379d512c688
---> 266517f47311
Removing intermediate container 0379d512c688
Successfully built 266517f47311
WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Starting imagename_db_1
Creating imagename_web_1
Attaching to imagename_db_1, imagename_web_1
web_1 | npm info it worked if it ends with ok
web_1 | npm info using npm#2.15.1
web_1 | npm info using node#v4.4.3
web_1 | npm info prestart SharedServer#5.8.0
web_1 | npm info start SharedServer#5.8.0
web_1 |
web_1 | > SharedServer#5.8.0 start /app
web_1 | > node index.js
web_1 |
web_1 | Wed, 27 Apr 2016 00:41:19 GMT body-parser deprecated bodyParser: use individual json/urlencoded middlewares at index.js:13:9
web_1 | Wed, 27 Apr 2016 00:41:19 GMT body-parser deprecated undefined extended: provide extended option at node_modules/body-parser/index.js:105:29
web_1 | Node app is running on port 5000
db_1 | LOG: database system was interrupted; last known up at 2016-04-25 00:17:59 UTC
db_1 | LOG: database system was not properly shut down; automatic recovery in progress
db_1 | LOG: invalid record length at 0/17076E8
db_1 | LOG: redo is not required
db_1 | LOG: MultiXact member wraparound protections are now enabled
db_1 | LOG: database system is ready to accept connections
db_1 | LOG: autovacuum launcher started
When I access http://localhost:5000, I see the web application running, but whenever I fire up something that tries to access the database, I get a HTTP 500 error with the following body
code: "28P01"
file: "auth.c"
length: 98
line: "285"
name: "error"
routine: "auth_failed"
severity: "FATAL"
What am I doing wrong? I'm not sure I understand what I'm doing with Docker, and the only thing I have for documentation are simple recipes to build specific environments (or at least, that's what I've understood)
Thanks.
Check your pg_hba.conf in $PGDATA allows connections from node.js.
By default the pg_hba.conf is like so:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
This is fine for your standard psql connectivity via the OS owner as it allows local connections trusted for localhost IP address 127.0.0.1. However if you have an IP address set on the server, which I'm guessing you do then you need to allow an entry for that because in your node.js configuration you're referring to a host of "DB". So ping "DB" and add that IP address:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
host db myuser <ip-for-db-host> md5
Once you've changed that file you will need to perform a pg_ctl reload.

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

Restarted my server and started getting this error: Forever detected script exited with code: 8

I resized my Digital ocean droplet (Permanently) This required I powered off my droplet and then powered on again. When I visit the webpage I get a typical NGINX page saying that I have succesfully installed NGINX, the web app can no longer be seen
I did a mup logs -f to see what is going on and I am continually getting this error.
I am not sure what is wrong and it looks like something is off with my cron jobs but I am not sure what. Any ideas:
error: Forever detected script exited with code: 8
[xxx.xxx.xxx.xx] error: Script restart attempt #75[xxx.xxx.xxx.xx]
[xxx.xxx.xxx.xx] {"line":"63","file":"synced-cron-server.js","message":"SyncedCron: Scheduled \"Email Weekly Todos for Mentors\" next run #Mon Nov 30 2015 07:00:00 GMT-0500 (EST)","time":{"$date":1448741207434},"level":"info"}[xxx.xxx.xxx.xx]
[xxx.xxx.xxx.xx] {"line":"63","file":"synced-cron-server.js","message":"SyncedCron: Scheduled \"Weekly Push Notifications to students\" next run #Sun Nov 29 2015 10:00:00 GMT-0500 (EST)","time":{"$date":1448741207437},"level":"info"}[xxx.xxx.xxx.xx]
[xxx.xxx.xxx.xx]
[xxx.xxx.xxx.xx] events.js:72[xxx.xxx.xxx.xx]
[xxx.xxx.xxx.xx] throw er; // Unhandled 'error' event
[xxx.xxx.xxx.xx] [xxx.xxx.xxx.xx] ^
Error: listen EADDRINUSE
at errnoException (net.js:905:11)
at Server._listen2 (net.js:1043:14)
at listen (net.js:1065:10)
at net.js:1147:9
at dns.js:72:18
at process._tickCallback (node.js:442:13)
error: Forever detected script exited with code: 8[xxx.xxx.xxx.xx]
Any ideas would help a lot
I fixed the issues by setting the app file in sites-enabled folder to listen to port 3000. I think it was listening to 80 by default and conflicting with nginx

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