如何在AWS上保持Java应用程序的持续运行?

huangapple go评论76阅读模式
英文:

How to keep running java aplication on aws?

问题

我对Java还不熟悉。我通过克隆这个仓库(https://github.com/hapifhir/hapi-fhir-jpaserver-starter)在AWS上运行了hapi fhir服务器。

我使用以下命令运行服务器:"sudo mvn -e jetty:run"

--

我的问题:

一旦我从AWS注销,我的服务器就会停止。当我通过.pem文件登录到我的AWS实例时,AWS实例在运行Ubuntu 18.04 LTS和nginx服务器。

谢谢。

英文:

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

答案1

得分: 3

在AWS上执行或设置Java应用程序的理想方法是通过设置systemd脚本或在Linux中设置init来将其作为守护进程运行。

在您的情况下,应用程序会在您关闭终端时立即停止,这是因为您在终端中启动它而没有使用nohup命令,当终端关闭时,应用程序也会停止,因为控制线程被停止。如果您只想在单独的后台线程上启动应用程序,而不想费力地在Linux中设置它作为服务,您可以使用nohup命令(将Java应用程序设置为服务并在systemd中进行注册是首选方法):

nohup java -jar yourjarName &

英文:

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 &

答案2

得分: 2

以守护进程方式运行:

"sudo mvn -e jetty:run &"

& 符号使命令在后台运行。

根据 bash 手册:

如果一个命令以控制操作符 & 结束,Shell 会在子Shell中将命令作为后台进程运行。Shell 不会等待命令执行完成,返回状态为 0。

英文:

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.

huangapple
  • 本文由 发表于 2020年10月12日 13:16:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/64312047.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定