ProcessTreeKiller Jenkins任务启动的后台进程被自动kill

摘要:
https://www.whatled.com/post-6467.htmldocker将此参数直接添加到中启动脚本的路径中,然后重新启动Jenkins容器[root@0249a3be5bc0bin]#grepdisable/usr/local/bin/jenkins.shexecjava-Dudson.util.ProcessTree.disable=true Duser.home=“$JENK”

https://www.whatled.com/post-6467.html

docker中启动脚本的路径,直接加上这个参数即可,然后重启Jenkins容器

[root@0249a3be5bc0 bin]# grep disable /usr/local/bin/jenkins.sh
exec java -Dhudson.util.ProcessTree.disable=true -Duser.home="$JENKINS_HOME" "${java_opts_array[@]}" -jar ${JENKINS_WAR} "${jenkins_opts_array[@]}" "$@"
[root@0249a3be5bc0 bin]#

ProcessTreeKiller官方原文如下:

This feature is available since 1.260

To reliably kill processes spawned by a job during a build, Jenkins contains a bit of native code to list up such processes and kill them. This is tested on several platforms and architectures, but if you find a show-stopper problem because of this, you can disable this feature by setting a Java property named “hudson.util.ProcessTree.disable” to the value “true”.

This can be done as a parameter to the “java” binary when starting Jenkins:

Depending on how you run your container, this can be different. In the distributed build environment, this system property needs to be set on slave JVMs.

Older versions of Hudson (<1.315) used the Java Property hudson.util.ProcessTreeKiller.disable, but the class ProcessTreeKiller has been depecated since. For compatibility reasons, currently both property names are supported (as of version 1.404).

How it works

The ProcessTreeKiller takes advantage of the fact that by default a new process gets a copy of the environment variables of its spawning/creating process.

It sets a specific environment variable in the process executing the build job. Later, when the user requests to stop the build job’s process it gets a list of all processes running on the computer and their environment variables, and looks for the environment variable that it initially set for the build job’s process.

Every job with that environment variable in its environment is then terminated.

If your build wants to leave a daemon running behind…

A convenient way to achieve that is to change the environment variable BUILD_ID which Jenkins‘s ProcessTreeKiller is looking for. This will cause Jenkins to assume that your daemon is not spawned by the Jenkins build. For example:

BUILD_ID=dontKillMe /usr/apache/bin/httpd

In case of Jenkins Pipeline use JENKINS_NODE_COOKIE instead of BUILD_ID

意思就大概是Jenkins每次构建完了后要自动杀掉部署过程中的子进程。

Jenkins使用processTreeKiller杀掉了所有子进程,而且这是Jenkins的默认行为。当一次build异常结束,或被人终止时,必然需要结束所有这次build启动的子进程。

解决jenkins自动杀掉衍生进程参照原文可以知道:

BUILD_ID=dontKillMe /usr/apache/bin/httpd

1.在执行 shell输入框中加入BUILD_ID=dontKillMe ,即可防止jenkins杀死启动的进程

ProcessTreeKiller Jenkins任务启动的后台进程被自动kill

  1. OLD_BUILD_ID=$BUILD_ID
  2. echo $OLD_BUILD_ID
  3. BUILD_ID=dontKillMe
  4. sh run.sh
  5. #改回原来的BUILD_ID值
  6. BUILD_ID=$OLD_BUILD_ID
  7. echo $BUILD_ID

2.临时改变BUILD_ID值,使得jenkins不会找到并结束掉run.sh启动的后台进程

ProcessTreeKiller Jenkins任务启动的后台进程被自动kill

 

免责声明:文章转载自《ProcessTreeKiller Jenkins任务启动的后台进程被自动kill》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇服务器上Ubuntu系统安装(译)碰撞检测和收集物品:如何使用cocos2d制作基于tiled地图的游戏:第二部分下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

[Jenkins]Jenkins构建时提示java.io.IOException: No space left on device

突然发现Jenkins的Job全部都停了,打开Jenkins发现所有的slave机器,均提示: 点开Dead(!),提示Thread has died,如下图: 看图好像说是Jenkins所在的服务器空间不够。 那进入Jenkins安装的服务器看一眼,df -h后,发现/dev/sda7的Used是357G,Avail是0G,原来是磁盘空间满了。 一般...

windows环境下简单Jenkins持续集成搭建

Jenkins是基于Java开发的持续集成工具,所以在安装Jenkins之前我们要确定电脑上已经安装了Java JDK并且环境变量配置正确,否则在启动使用java -jar Jenkins.war启动jenkins时,由于没有Java环境,将提示java非内部命令,无法启动。 java版本:jdk-8u162-windows-i586 jenkins版本:...

jenkins初始化和安装插件

1.find / -name 'default.json' 2. sed -i 's/http://updates.jenkins-ci.org/download/https://mirrors.tuna.tsinghua.edu.cn/jenkins/g' /var/lib/jenkins/updates/default.json &&...

基于Jmeter+maven+Jenkins构建性能自动化测试平台

  一、目的: 为能够将相关系统性能测试做为常规化测试任务执行,且可自动无人值守定时执行并输出性能测试结果报告及统计数据,因此基于Jmeter+maven+Jenkins构建了一套性能自动化测试平台 二、环境准备: 1、选定Linux服务器(一台或多台均可,目前为10.0.4.109),安装jmeter(直接解压缩已下载好的jmeter zip包即可使用)...

Jenkins 打包 java项目时 丢失 配置文件(resource)

使用IDEA开发的spring boot 项目在本地打包运行可以,但是利用Jenkins打包运行提示读取不到配置文件中的变量,打开jar包发现里面没有配置文件。解决方法是在pom中增加如下配置 <build> <resources> <resource> <directory&g...

Jenkins使用jenkins-cli.jar进行远程调用时出现“ERROR: No such job 'test'”或者权限不够等问题解决(Windows)

网上最提倡的解决办法是用SSH的key进行登录,但是我发觉Linux上非常容易实现,但是Windows压根不知道在哪里设置。 原文:https://issues.jenkins-ci.org/browse/JENKINS-12543 国外参考:http://stackoverflow.com/questions/21609589/jenkins-cli-b...