jenkins 的 ProcessTreeKiller

根据下面介绍,合适的解决方案是:

BUILD_ID=dontKillMe bash /home/app/opt/apache-tomcat-6.0.37/deploy-bin/deploy_test.sh

----------------

最近用jenkins执行服务器上的脚本,启动tomcat总是不成功,问了谷哥之后,发现是下面一个特性在作怪:

http://wiki.hudson-ci.org/display/HUDSON/ProcessTreeKiller

 

This feature is available since 1.260

 

To reliably kill processes spawned by a job during a build, Hudson 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.ProcessTreeKiller.disable" to the value "true".

 

This can be done as a parameter to the "java" binary when starting Hudson:

 

 java -Dhudson.util.ProcessTreeKiller.disable=true -jar hudson.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.

 

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 Hudson's ProcessTreeKiller is looking for. This will cause Hudson to assume that your daemon is not spawned by the Hudson build. For example:

 

BUILD_ID=dontKillMe /usr/apache/bin/httpd

 

---------------------

来自stackoverflow的问答:

http://stackoverflow.com/questions/5728899/tomcat-script-not-working-when-run-from-hudson

http://stackoverflow.com/questions/7703156/start-up-tomcat-from-ant-script

----------------------

The problem had to do with Jenkins feature called ProcessTreeKiller described here.

Basically Jenkins automatically kills all processes spawned by a job by searching the process tree for processes with specific environment variable

All i had to do was to overwrite jenkins env variable called BUILD ID and it worked. I used a Setenv Plugin to set the env var specific for the build.

-----

What about executing the command like this :

<execexecutable="bash"><argvalue="-c"/><argvalue='nohup ${tomcat.bin.dir}/startup.sh -Xms128M -Xmx512M &'/></exec>
---

uild.properties file:

 #----------------------------------------------------
 #Tomcat Configuration
 #----------------------------------------------------
 #Back-end Tomcat 
 tomcat.dir=${branch.dir}/../tomcat
 tomcat.bin.dir=${tomcat.dir}/bin
 tomcat.bootstrap.jar=${tomcat.bin.dir}/bootstrap.jar
 tomcat.jvmarg=-Dcatalina.home

loadproperties file

<propertyfile="${basedir}/build.properties"/><!-- Stop tomcat --><targetname="stop-tomcat"description="Stops back-end tomcat server"depends="prepare"><javajar="${tomcat.bootstrap.jar}"fork="true"spawn="false"><jvmargvalue="${tomcat.jvmarg}=${tomcat.dir}"/><argline="${arg.stop}"/></java><echo>+---------------------------------+</echo><echo>|   T O M C A T   S T O P P E D   |</echo><echo>+---------------------------------+</echo></target>

Also I have added an element called spawn set to "false", which print execution output onto console. 

Hope this helps :) 
 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值