首页 / 更多教程 / 解决jenkins自动杀掉衍生进程
解决jenkins自动杀掉衍生进程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了解决jenkins自动杀掉衍生进程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3111字,纯文字阅读大概需要5分钟。
内容图文
解决jenkins自动杀掉衍生进程
背景
今天用jenkins来部署tomcat工程,没有使用tomcat-deploy插件,直接写了个shell脚本,用脚本来停止、换包、启动tomcat,但是当jenkins Pipeline job执行完成后,发现后台tomcat进程没有了;
查看官方文档
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:
java -Dhudson.util.ProcessTree.disable=true -jar jenkins.war
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版本号
Jenkins ver. 2.150.1
Pipeline job解决办法
设置JENKINS_NODE_COOKIE 参数的值,使用方法如下
在pipeline的job中,执行启动tomcat的时候,用下面的方法即可
withEnv([‘JENKINS_NODE_COOKIE=dontkillme’]) {
sh ‘sh ${tomcatHome}/bin/startup.sh’
}
enkins普通job(非Pipeline job)
在执行 shell输入框中加入BUILD_ID=dontKillMe ,即可防止jenkins杀死启动的进程
临时改变BUILD_ID值,使得jenkins不会找到并结束掉run.sh启动的后台进程
样例如下:
…
OLD_BUILD_ID=$BUILD_ID
echo $OLD_BUILD_ID
export BUILD_ID=dontKillMe
#执行tomcat启动脚本
sh KaTeX parse error: Expected 'EOF', got '#' at position 29: …bin/startup.sh
#?改回原来的BUILD_ID值
…OLD_BUILD_ID
echo $BUILD_ID
…
内容总结
以上是互联网集市为您收集整理的解决jenkins自动杀掉衍生进程全部内容,希望文章能够帮你解决解决jenkins自动杀掉衍生进程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。