NodeJS process disconnects on SSH session logout - node.js

I am doing SSH on the server, which is Ubuntu 14.04 server. I tried various things to keep the Node server running. But as soon as I type exit and disconnect the server from my Ubuntu Desktop the Node server is also disconnected.
Though it is running on the server. When I SSH into the server I can access it.
I have tried these :
nohup node server.js &
nohup node server.js > /dev/null 2> error.log < /dev/null &
sudo nohup supervisor server.js &
forever start server.js
Also I tried using tmux and screen. Its the same problem with all of these. As soon as I disconnect the SSH the node server is not available. But when I just login to the server, it is available again.
What am I missing?

Though it is running on the server
seems to contradict
As soon I disconnect the ssh, it terminates
Are you doing anything special with your ssh session? ( like forwarding server port to a client ) How do you check if server is running?
Possible reasons:
1) You test using server's localhost when on server and server IP from client: check you are binding your server to "0.0.0.0" address and not 127.0.0.1
2) You have some kind of port forwarding and connect to server vi client localhost:forvarded_port -> ssh -> server localhost:remote forward side port. - Checj you are listening on 0.0.0.0, that server IP is not blocked by firewall and try to access it via direct ip/port

Related

Connect to a VNC inside a docker which is on remote server

I have an Amazon Linux AMI server on AWS EC2, i have deployed "selenium docker" on it "https://github.com/elgalu/docker-selenium", the docker have a VNC running inside it.
Now how i could access this VNC?
I did some google search but did not found anything, also i tried to connect to the server ip and give the VNC display number but it gives connection refused.
I have added the VNC port as a rule on the server security rules.
Thanks.
Since you have already specified the firewall rules for your VNC server the problem is most likely in VNC port listening.
first, make sure that VNC is running on localhost run
nc localhost 5901
nc = netcat (you may need to install the package)
change 5901 to your port no
you can also view the running VNC instances by :
vncserver -list
now if everything seems to be working run this command to show the port stats
sudo netstat -ntpl | grep 5901
change 5901 to your portname.
if something like
127.0.0.1:5901 is assigned to tcp then that's the problem , we need to make sure VNC is running on
0.0.0.0:5901
which means it should accept all the traffic and not just localhost !
finally kill the vncserver by running vncserver -kill :1 (display name), run the command :
vncserver -localhost no
P.S its an old question but may help future answer seekers.

Running node app digitalocean and accessing it

Im running my node app with grunt on a DO droplet. I start the server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:3000
But when I navigate to my dropletIP:3000 I cannot see the app, I get:
This site can’t be reached
mydropletIP refused to connect.
Shouldn't my app be available? I don't have nginx or anything installed.
I was having similar problem but the solution was simple. Change from 'localhost' to '0.0.0.0' i.e
.listen(8080, '0.0.0.0');
And then to test your api just enter your static ip of droplet with port that you have entered i.e droplet-ip:8080
Check the particular port is opened or not ,using following command
sudo ufw status
If any Firewall enabled and any port is block means you can see that.
netstat -an | grep "LISTEN " ( List of listening port on server)
I need this info ,then only we can find a problem

offering mysql on localhost via a ssh layer

I have 2 machines: One has a mysql server that runs on localhost.The second one has no mysql server. I want to access the mysql server from the first machine on the second machine also on localhost. It should be something like a virtual localhost.
The first machine should log in the second machine via secure socket and should emulate the server there somehow.
Is something like this possible, how is it called , and how does it work.
Is this what is called a tunnel?
Yes, this is what is called a tunnel.
Assuming host A is running the mysql server and host B is the one that dose not.
To create the tunnel enter the following on host B:
ssh -L 3306:localhost:3306 username#A
(Add -f -N to the command to not execute any command on the remote host and immediately background the ssh connection).
This creates a listening port 3306 on host B which is forwarded over the ssh tunnel to localhost:3306 on host A.
Now just run mysql on host B and you should be able to connect to the mysql server on host A.
Hope it helps!

How can I find where node.js is running?

I have a VPS with node.js installed, I already uploaded a basic example to test it on the server, so I tried doing this:
I access by SSH, navigate to my project folder and run
node app.js
I get this message
Express server listening on port 8080
I thought i could see my app here
example.com:8080 or server.example:8080... but nothing. Then I tried with the info from os.networkInterfaces(); and os.host(); and still nothing happen
could you help me out? as you can see I am a total noob on node.js. What I'm doing wrong? or what should I do before running my app? Something related to DNS's? i have no idea
How do you ssh to your host? with ip or name? Is it something like:
ssh root#example.com
if so then at least you know your DNS is ok.
Once on the server do a
netstat -a
if you find *:8080 then your server is listening in the default ip. If you see something like 12.23.45.67:8080 then this number is the ip your server is listening.
ifconfig
will give you the servers ip. This should be the same as the ip of example.com. If not then maybe there is some router/firewall in front of your server and you have to configure that to allow port 8080 to reach your server.
if someone ever has the same problem this is how i solved on CentOS:
Open this file
/ Etc / csf / csf.conf
Add the required port
Allow incoming TCP ports
TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,26"
Allow outgoing TCP ports
TCP_OUT = "20,21,22,25,37,43,53,80,110,113,443,587,873"
Restart
# # Csf-r

Accessing application in browser over SSH proxy on localhost.

I have SSH access to a web server that is hosting an application on port 8080. I have a SSH session setup and a proxy configured on Chrome to redirect requests to SSH tunnel. I basically configured it using these instructions: http://drewsymo.com/2013/11/ssh-tunnel-in-30-seconds-mac-osx-linux/
I can confirm using Whats My IP that my IP is that of the SSH session and that is working correctly.
But I cannot figure out how to access the local application on the web server that I am SSHed into. When I try localhost:8080 the SSH session gives me an error "channel X: open failed: connect failed: Connection refused"
Any idea what is going on?
You can just create a port-specific tunnel:
ssh -L18080:localhost:8080 username#theothermachine
and then go to localhost:18080 on your local machine. The tunnel will forward your request to port 8080 of the localhost on the other end (and of course, localhost on the other end is the other machine itself). If that doesn't work for some reason, then replace localhost by 127.0.0.1 in the ssh command.

Resources