gpt4 book ai didi

java - 在 Jenkins 构建中使用 ssehexec 任务不会停止其执行

转载 作者:太空宇宙 更新时间:2023-11-04 07:40:48 38 4
gpt4 key购买 nike

我在 Jenkins Ant 执行插件中有一个 Ant 任务,作为构建后步骤,在我们的一台服务器中远程运行 shell 脚本。 shell 脚本在后台启动一个 java 进程。当我直接在服务器上执行shell脚本时,它会在后台启动java进程并出来。当我通过 sshexec 任务从 Jenkins 运行它时,shell 脚本会运行,但它永远不会出现,并且 Jenkins Build 会等待。

后来,当我将 timeout 属性添加到 sshexec 时,它会在给定的毫秒数后超时,但 Jenkins 构建显示为失败。如何使 sshexec 任务从 shell 脚本执行中干净地出来?

这是我的 ssheexec 任务

<sshexec host="${deploy.host}" username="${deploy.username}"  password="${deploy.password}" command=". /etc/profile; cd ${deploy.path}; sh start.sh i1" trust="true" timeout="10000" />

start.sh 文件如下:

nohup java -Xms512m -Xmx1024m -cp calculation.jar com.tes.StartCalculation $1 &

echo $! > calculation-$1-java.pid

最佳答案

看起来,ssh 执行的作业没有完全守护进程。在许多情况下,以 nohup 开头是不够的。

请参阅discussion与之相关的(在不同的上下文中)

The issue is that you are not closing your file descriptors when you push something into the background. The & is fine when you are in a shell, but is not enough when you want to disconnect and leave a process running, you need the process to disconnect from the shell.

...修复以更正脚本。

If someone writes a naive service script that does not properly detach from the terminal, I want to know the first time that that script is used in a deployment - the SCM changes will enable the breaking change to be quickly identified.

It is wrong to hide the problem to enable incorrect code to be released to production - and I would not be happy if the first I knew about it was when a production system administrator complained.

如果这是同样的问题,您需要daemonize the script

关于java - 在 Jenkins 构建中使用 ssehexec 任务不会停止其执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16100730/

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