[英]How can I correctly run in background a Spring Boot Batch application on a Linux (Centos 7) shell?
I have to run a Java Spring Boot application on a Linux machine (Centos 7).我必须在 Linux 机器 (Centos 7) 上运行 Java Spring Boot 应用程序。 I am connecting to a shell via SSH. This application is in jar format and implement a batch application and containins itself its scheduler.我正在通过 SSH 连接到 shell。此应用程序采用jar格式并实现批处理应用程序并包含其调度程序。
I have to run it in background on a remote server in order that after that I quit the shell it is still run.我必须在远程服务器的后台运行它,以便之后我退出 shell 它仍在运行。
I have performed this command in order to run my application in background:我执行了此命令以便在后台运行我的应用程序:
java -Xms256m -Xmx1024m -jar UpdateInfoBatch-0.0.1-SNAPSHOT.jar &
then I clicked on CTRL+C on my keyboard in order to obtain again the keyboard prompt on my shell.然后我在键盘上单击CTRL+C以再次获得 shell 上的键盘提示。
and here the first trange behavior: I obtain again the shell prompt and the possibility to insert command but if the application log something it is appearing on the shell. Why?这是第一个奇怪的行为:我再次获得 shell 提示和插入命令的可能性,但是如果应用程序记录它出现在 shell 上的内容。为什么? I expected that my application still run in background.我希望我的应用程序仍在后台运行。
Anyway I now prompt this command in the my shell in order to check if my application is running:无论如何,我现在在我的 shell 中提示这个命令,以检查我的应用程序是否正在运行:
xxx@xxx.yyy.it [~/zzz-import-data-batch]# ps aux | xxx@xxx.yyy.it [~/zzz-import-data-batch]# ps aux | grep java xxx 23307 15.3 1.6 4871172 418980 pts/0 Sl 10:23 0:22 java -Xms256m -Xmx1024m -jar UpdateInfoBatch-0.0.1-SNAPSHOT.jar webadmin 23522 0.0 0.0 112812 980 pts/0 S+ 10:25 0:00 grep --color=auto java grep java xxx 23307 15.3 1.6 4871172 418980 pts/0 Sl 10:23 0:22 java -Xms256m -Xmx1024m -jar UpdateInfoBatch-0.0.1-SNAPSHOT.jar webadmin 23522 0.0 0.0 112812 980 pts/0 S+ 10:25 0:00 grep --color=自动 java
And yes my application seems to correctly run (the first one).是的,我的应用程序似乎可以正确运行(第一个)。
Then I close the connection to my shell, I log into it again and I perform again the previous command but now I obtain this:然后我关闭与我的 shell 的连接,我再次登录并再次执行之前的命令,但现在我得到了这个:
xxx@xxx.spaccount.it [~/zzz-import-data-batch]# ps aux | xxx@xxx.spaccount.it [~/zzz-导入数据批]# ps aux | grep java xxx 23919 0.0 0.0 112812 980 pts/0 S+ 10:27 0:00 grep --color=auto java grep java xxx 23919 0.0 0.0 112812 980 点/0 S+ 10:27 0:00 grep --color=auto java
As you can see after that I disconnect from the shell, when I do a new login my batch application seems that it is not running (and infact my job application doesn't runned).如您所见,之后我与 shell 断开连接,当我重新登录时,我的批处理应用程序似乎没有运行(实际上我的工作应用程序没有运行)。
What is wrong?怎么了? What am I missing?我错过了什么? What could be a good way to run in background my java jar batch application?在后台运行我的 java jar 批处理应用程序的好方法是什么?
Generally you will want to redirect output, and you can use the nohup command to spawn it to the background.通常你会想要重定向 output,你可以使用 nohup 命令将其生成到后台。 If you don't care about capturing stdout or stderr, you can direct those to /dev/null如果您不关心捕获 stdout 或 stderr,您可以将它们定向到 /dev/null
nohup java -Xms256m -Xmx1024m -jar UpdateInfoBatch-0.0.1-SNAPSHOT.jar >/dev/null 2>&1 &
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.