gpt4 book ai didi

spring - 如何在 Ubuntu 服务器上安装 Spring Boot 应用程序?

转载 作者:行者123 更新时间:2023-12-04 18:35:37 25 4
gpt4 key购买 nike

我在 Digital Ocean 上有 Ubuntu 服务器,我编写了 Spring Web 应用程序,现在我想将它投入生产。

我通过 FTP 将其上传到服务器,然后通过 Putty 打开控制台并使用以下命令:

java -jar name.jar

之后 Spring 启动,当我打开我的 Web 应用程序时一切正常,但是当我关闭我的 Putty session 时,我的 Spring Web 应用程序不再工作。似乎当我关闭我的 Putty session 时,Spring Web 应用程序也关闭了。

如何解决这个问题?

最佳答案

而什么KLHauser建议的将起作用,但如果 vm 在云中重新启动(发生这种情况),您的应用程序将不会自动重新启动。还可以使用 kill -9 停止您的应用程序容易出错且危险,因为您可能不小心杀死了错误的进程。

参见 Spring Boot 的作为 Linux 服务运行部分关于如何做到这一点的文档。

If you’ve configured Spring Boot’s Maven or Gradle plugin to generate a fully executable jar, and you’re not using a custom embeddedLaunchScript, then your application can be used as an init.d service. Simply symlink the jar to init.d to support the standard start, stop, restart and status commands.

The script supports the following features:

  • Starts the services as the user that owns the jar file
  • Tracks application’s PID using /var/run//.pid
  • Writes console logs to /var/log/.log

Assuming that you have a Spring Boot application installed in /var/myapp, to install a Spring Boot application as an init.d service simply create a symlink:

$ sudo ln -s /var/myapp/myapp.jar /etc/init.d/myapp Once installed, you can start and stop the service in the usual way. For example, on a Debian based system:

$ service myapp start

关于spring - 如何在 Ubuntu 服务器上安装 Spring Boot 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42970534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com