How to run a program autonomously on a server, how to run a java program indefinitely on a server?

I have a jar executable that I am trying to run before stopping on the linux server. I tried to take a look at the Java Wrapper API, but it was very difficult, and I'm not even sure what I want. Is there a way to run the program on the server so that when the program exits the program continues to work? I use ssh to enter the server and the command line to start banks. Thanks!

+4
source share
4 answers

Run:

nohup java -jar myjar.jar & 

Ampersand at the end will run it in a new forked process, so it will continue after logging out. nohup prevents it from freezing when its owner logs out.

+7
source

If you have the ability to install the server as a daemon, you can do this. If not, you can try using a program such as a screen to create a virtual terminal.

 sudo apt-get install screen screen java -jar myJar.jar 

if you want to use your terminal:

 screen -r 
+3
source

If you want to run it as a service, check out daemontools .

It will start your program when the machine boots, reboot it, if it works, stop it when the machine turns off.

Ubuntu just quit.

+2
source

Why yes, there is! (keep in mind that this can only work on the server, and not on your personal computer) Use the linux 'screen' command to create a virtual terminal that will continue after logging out, instructions here .

basically use:

 $ screen 

to launch a new virtual terminal window. Start your code, and as soon as you run it, type "control + a" and then "d" to disconnect from the window. After disconnecting, you can exit the system, and your program will still work on the server. To return to it, enter:

 $ screen -r 

and you will return to your program. Very simple! Instructions

+1
source

Source: https://habr.com/ru/post/1446119/


All Articles