2

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

Yannick
  • 177
  • 2
  • 13
vikrant chauhan
  • 121
  • 1
  • 1
  • 10

2 Answers2

3

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 &
Ananthapadmanabhan
  • 5,706
  • 6
  • 22
  • 39
  • yes i want something ilke this but iam not able to find any jar file say "yourjarname". you can open my repo link ,previously shared – vikrant chauhan Oct 12 '20 at 05:40
  • @vikrantchauhan From the git hub link that you have kept in the question, it's provided that you can run it as a jar for springboot application. How are you building your application code ? What kind of an application is it ? – Ananthapadmanabhan Oct 12 '20 at 05:45
  • @vikrantchauhan you are using the embedded jetty server to start the application as per the command in the question. But in the link that you provided they have clearly mentioned that this is not the desired approach to run it as a service. Create a war or jar using `mvn clean install` and then deploy that.Read the documentation if you don't understand it is explained there in detailed. Use a springboot jar if you do not want to setup tomcat or anything else to deploy this. – Ananthapadmanabhan Oct 12 '20 at 05:50
  • 1
    Thanks. You might be right ,but as i dont know java at all so i cannot test it right now . – vikrant chauhan Oct 12 '20 at 11:46
2

run it as daemon:

"sudo mvn -e jetty:run &"

The & makes the command run in the background.

From man bash:

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0.

Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53