参考:
http://goddyzhao.tumblr.com/post/9338574551/spawn-a-process-from-a-build-that-lives-longer-than-the
http://software.clapper.org/daemonize/
问题描述:
-------------------------------------------------------
http://goddyzhao.tumblr.com/post/9338574551/spawn-a-process-from-a-build-that-lives-longer-than-the
http://software.clapper.org/daemonize/
问题描述:
-------------------------------------------------------
如何解决这个问题呢?第一反应就是build过程中,想办法调用一个shell脚本,然后利用linux/unix的后台运行能力来解决这个问题。(利用nohup 或者 &):
- 创建一个shell脚本: #!/bin/bash nohup ant runserver &
- 在jenkins中,build过程中创建一个shell build step,然后直接调用这个shell脚本
感觉好像解决问题了,但是,jenkins会报错:“descriptor leak”
为什么会这样呢?官方给出了这个问题的解释:主要原因是jenkins和子进程之间是通过管道(stdin/stdout/stderr)来连接的。这样,jenkins就可以抓到子进程的输出,将它打印在自己的进程中。也正是由于这样,jenkins会一直等待子进程发送EOF信号,它才会认为子进程结束了。而利用linux的后台运行能力,主进程等不到这个EOF,于是就导致了“descriptor leak”的问题。
-------------------------------------------------------------------
[popexizhi]问题相似不过是c的server
解决:
难道我们就束手无策了吗?其实,官方同样给出了不同系统的解决方案,其中linux就是利用 daemonize工具。这个工具主要可以把程序当成unix的daemon程序来处理,它会自动去关闭所有打开的文件描述符(file descriptor)。
有了它之后,jenkins的build进程就能够正常接收到EOF信号,并且正确的认为子进程已经结束了。然后,就可以把整个build进程结束了。具体做法就是:
- 在shell脚本中,直接调用: daemonize -o output-file absolute_path_of_the_shell_file
----------------------
[popexizhi]
ademonize 安装linux
git clone http://github.com/bmc/daemonize.git
$ sh configure
$ make
$ sudo make install
PS:
- 在shell脚本中,直接调用: daemonize -o output-file absolute_path_of_the_shell_file
没有评论:
发表评论