Linux TCP/IP Socket Programming - linux

I have developed Linux socket server connection which is working fine.
When start from terminal it start from listening from client. but when I close terminal it stops listening.
I need to continue even though the terminal closed by user from started.
how can I run server socket application in Linux as background process?
am run using ./a.out 8888(portno)
again i will connect error will come (connection refused)
now what do i?
Thank You.

On terminal execute the script ending with &.
A task can usually be started and run as a background task by putting a '&' at the end of the command line.
Check this:
Linux Background Job

You can use nohup to keep the program running if the Terminal is closed:
nohup ./a.out 8888 &
(Standard output/error will be written to nohup.out instead of the Terminal.)

Related

Does nohup work as long as the server is running?

I recently decided to migrate my programs from AWS to a local server (Raspberry Pi 3 B+ running Raspbian). I SSH into the now local server where I send the following command (and please correct me if I'm wrong).
nohup ./Eye.sh & nohup ./Hand.sh & nohup ./Foot.sh &
The program does nothing over the weekend (and it is current 2AM on Sunday here) and will not start performing its task until 9:30AM on Monday. I need to know that I will not, hopefully ever, have to SSH back into the server to re-execute the commands, as it is crucial that the programs are running at all times.
Do I have anything to worry about? Will the program run as long as there is power to the system?
Yes. As long as the server is running, you can close out of your SSH connection and your program will continue to run with the nohup command. If your server reboots, for whatever reason, you should consider using respawn.

In Linux, how to make a jar file a daemon and how to add websocket

actually I have 2 jars and 1 ini file. In terminal I can run this java application like that :
"/usr/java/jre1.8.0_121/bin/java" -cp "./eSign.jar:sqlite-jdbc-3.7.2.jar" ./esign.tubitak.applet.SignApplet /home/ugurcan/Desktop/Linux_sign_test/test.ini
And my gui based program works like this. Now; I need to make this program run without any terminal commands like an exe as a session(which runs in backgraound always). Additionally , I need to add a websocket for the server to program makes a connection between the server and the computer which runs the program.
Thank you for your thoughts !!!
To run a command in background you can use:
nohup COMMAND &. nohup - makes your program immune to terminal hangup, and & runs it in background.
Can't figure out what do you mean 'to add a websocket for the server to program makes a connection between the server and the computer which runs the program'. Websocket support should be added in your application. But without any further detail we can't help you.

Geddy CLI closes on SSH drop

In a remote CentOS VM Geddy application with MonogoDB wrapper is deployed. The application starts and listen to port 80 when below command is executed.
geddy -e production &
The problem in this CLI command is when the SSH connection to VM was disconnected the process automatically gets closed. To make application working SSH needs to be opened always which is not possible. Is there any alternative method to keep it running as background service.
This happens because processes that are merely backgrounded will be sent a SIGHUP signal when their controlling terminal (the SSH connection) is closed.
The traditional method of preventing this is using the nohup utility:
nohup geddy -e production &
Alternatively, you can use terminal multiplexers like screen or tmux to create persistent terminal sessions (ones that remain active when you log out, and that can be reattached when you log in again at a later time).

Turn off Node.js Server Once Running on Localhost

This is probably a simple question but I can't find a clear answer anywhere. I am trying Hello World on node.js. I have a node.js server running on port 8000 of the localhost, turned on via the command line e.g. "node helloworld.js". Helloworld.js runs fine via localhost:8000. Now when I try turn on another server on port 8000 though I get the error "listen EADDRINUSE" because the first server is still running. So how do I turn off the first node server?
Just kill the process by doing ctrl-c...
If you still have the original terminal in which you run the Nodejs server, then simply press ctrl + C can kill the process.
However, if you lost the terminal, then you can open another terminal and run taskkill /F /IM node.exe. (/F to force the kill, /IM to specify which script you want to kill). Note that the command would kill every node server running.
If you no longer have access to your terminal, then go to your task manager on Windows or 'Force Quit' on Mac and end the 'Node.Js...' process.
This is the cleanest way to do it (if no terminal window), in my opinion.

nodejs server - mac terminal crash every one hour

I got a live server running nodejs chat app. I connect to server using terminal on mac. I start the server by typing server.js.
the problem is, my terminal always hung after one hour running, and there are no error outputs. when it hangs, I press ctrl+c I got the message [process completed].
note: My terminal runs node apps locally without any problems.
And my current chat app run well when I initiate it with WinSCP in windows platform.
Try launching your node process on the remote server using a tool like nohup.
bash$ nohup /path/to/node server.js > out.txt 2> err.txt &
[1] 53032
# Now you can logout of the remote server without
# killing the "node" process and chat server.
[Edit]
Note that the number printed by "nohup" (e.g. 53032) is the id of detached process, so if you need to terminate it you can do something like "kill -9 53032". If you forgot to record that number then you'll have to find it by using a program such as "ps"; for example, you can run "ps auxwww | grep node" (the flags will vary depending on your system) and you'll see output similar to this:
maerics 81694 0.6 0.5 2543604 21216 s000 S+ 10:34AM 0:09.45 /Users/maerics/opt/node/node server.js
In this example, on my system, the number in the second column is the process id.

Resources