如何调用Shell脚本来启动后端Java进程? [英] How can I call a shell script to start a backend Java process?

查看:353
本文介绍了如何调用Shell脚本来启动后端Java进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完成Jenkins任务后,我将使用Jenkins的后置条件配置部分来执行Linux Shell脚本.

After completing a Jenkins task, I execute a Linux shell script by using Jenkins' post-condition configuration section.

此Linux Shell脚本希望在后端启动备用服务,并且不会导致Jenkins暂停.

This Linux shell script wants to launch a standby service on the backend and can NOT cause Jenkins to pause.

我尝试使用"nohup +&"等,但是它不起作用.

I tried to use "nohup+&", etc., but it does not work.

有什么好方法吗?

推荐答案

Jenkins可能正在等待关闭某些管道.您的后台进程继承了一些文件描述符,并一直保持打开状态.

Jenkins is probably waiting for some pipes to close. Your background process has inherited some file descriptors and is keeping them open for as long as it runs.

如果幸运的话,唯一的文件描述符是0、1和2(标准文件描述符).您可能想使用lsof -p PID检查后台进程的文件描述符,其中PID是后台进程的进程ID.

If you are lucky, the only file descriptors are 0, 1 and 2 (the standard ones.) You might want to check the file descriptors of the background process using lsof -p PID where PID is the process id of the background process.

您应确保将所有这些文件描述符(输入和输出)都重定向到后台进程,因此应使用类似以下的命令来启动它:

You should make sure all of those file descriptors (both inputs and outputs) are redirected for the background process, so start it with something like:

nohup daemon </dev/null >/dev/null 2>&1 &

可以随意将输出定向到/dev/null以外的文件,但请确保保留重定向的顺序.顺序很重要.

Feel free to direct the output to a file other than /dev/null but make sure you keep the order of the redirections. The order is important.

如果您计划从Jenkins作业启动后台进程,请注意,在构建结束时Jenkins将终止后台进程.参见 https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller如何避免这种情况.

If you plan to start background processes from a Jenkins job, be advised that Jenkins will kill background processes when build ends. See https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller on how to prevent that.

这篇关于如何调用Shell脚本来启动后端Java进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆