Spring 引导和云部署

Spring Boot and Cloud deployment

我目前正在开发具有 Spring 启动功能的 REST API。我希望它部署在 google 云(计算引擎)上。 我创建了一个虚拟 linux 机器,安装了 java 8 并将我的 spring 启动应用程序放入其中。 它工作正常但是: 我的应用程序是一个 jar 文件(嵌入 Tomcat)。我用这个启动它: java-罐子myApp.jar 它工作正常。 但是当我在 google 云上关闭 shell 时,我的应用程序不再可用。 我希望我的应用程序始终可用,而不必在每次退出 shell 时都启动它。可能吗?

image of cloud shell

如果您使用虚拟机(google 计算引擎),您可以使用脚本(windows 中的 bat 或 linux 中的 sh)来执行 java -jar 命令,但您也可以使用容器引擎并使用您的应用程序创建一个 docker 容器。配置 docker 文件并部署。容器环境 运行 你的应用自动

我认为这与 Unix Thread.

是同一个问题

快速回答是您的进程已链接到终端。当你关闭它时,进程被杀死。如果我引用 this answer :

What nohup does, on the other hand, is to effectively separate the process from the terminal:

  • It closes standard input (the program will not be able to read any >input, even if it is run in the foreground. it is not halted, but will receive an error code or EOF).
  • It redirects standard output and standard error to the file nohup.out, so the program won't fail for writing to standard output if the terminal fails, so whatever the process writes is not lost.
  • It prevents the process from receiving a SIGHUP (thus the name).

所以,试试

nohup  java -jar myApp.jar &