Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep running java aplication on aws?

I am new to Java. I have hapi fhir server running on AWS by cloning this repository (https://github.com/hapifhir/hapi-fhir-jpaserver-starter)

I run my server with follwing command: "sudo mvn -e jetty:run"

--

My Problem:

As soon as I log out of AWS, my server stops. When I am logged in to my AWS instance via the .pem file, AWS instance running with ubuntu 18.04 LTS with nginx server.

Thanks

like image 249
vikrant chauhan Avatar asked Mar 25 '26 04:03

vikrant chauhan


1 Answers

The ideal approach to execute or setup a java application on AWS is to run it as a daemon by setting up systemd script or init in linux.

In your case the application stops as soon as you close the terminal, because you are starting it in the terminal without the nohup command, when the terminal is closed the application is also stopped since the controlling thread is stopped. If you just want to launch the application on a separate background thread without going through the hassle of actually setting it up as a service in linux , you can use the nohup command (setting up a systemd to register the java application as a service is the preferred approach) :

nohup java -jar yourjarName &
like image 82
Ananthapadmanabhan Avatar answered Mar 27 '26 19:03

Ananthapadmanabhan