简体   繁体   English

如何在 Linux (Centos 7) shell 上在后台正确运行 Spring Boot Batch 应用程序?

[英]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.

相关问题 如何在端口 80 上运行 Spring Boot 应用程序 - How can I run a Spring Boot application on port 80 为什么我可以在 CLI 中运行我的应用程序 VSCode 但不能正确运行?它是一个 spring 启动应用程序 - Why can I run my app VSCode but not correctly in CLI?, its a spring boot application 如何使用腻子从Linux运行Spring Boot应用程序 - how to run a spring boot application from linux using putty 使用输入参数在centos中在后台运行Spring批处理应用程序的jar文件 - Running jar file of Spring batch application in background in centos with input arguments 如何在执行测试时阻止我的 Spring Boot Batch 应用程序运行? - How can I prevent my Spring Boot Batch application from running when executing test? 我们能否在通过Spring Boot应用程序运行的spring批处理中的两个作业之间传递参数 - Can we pass parameters between two jobs in spring batch which run via spring boot application 我可以从 Spring 引导应用程序将文件写入 CentOS usr/share/files/ 吗? - Can I write file to CentOS usr/share/files/ from a Spring boot application? 如何在 Spring 批处理应用程序中制作 List OR ArrayList 对象单例。 如何在java spring batch/boot中将字段注释为单例 - How can I make a List OR ArrayList object singleton in Spring batch application. How can I annotate a field as singleton in java spring batch/boot 当我将 Spring Boot 应用程序部署到 Linux 服务器时,ProcessBuilder 无法正常工作 - ProcessBuilder is not working correctly when I deploy my Spring boot Application to a Linux server 我可以运行一个空的 spring 引导应用程序而不会出现错误吗? - Can I run an empty spring boot application without getting an Error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM