Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

jar

I have a jar executable that I'm trying to run until stop on a linux server. I've tried looking at the Java Service Wrapper API, but it was really difficult and I'm not even sure that's what I want. Is there a way I can run a program on the server so that when I log off the program keeps running? I'm using ssh to login to the server and commandline to run the jar. Thanks!

like image 505
user1747935 Avatar asked Dec 12 '22 20:12

user1747935


2 Answers

Run:

 nohup java -jar myjar.jar &

The ampersand at the end will run it in a new forked process, so it will continue after you log out. nohup prevents it from hanging up when its owner logs out.

like image 104
Adam Avatar answered Dec 14 '22 10:12

Adam


If you have the ability to set the Server as a Daemon you can do so. If not you can try to use a programm like screen to create a virtual Terminal.

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

if you want to reatach your terminal:

screen -r
like image 41
nukebauer Avatar answered Dec 14 '22 09:12

nukebauer