node.js - How to kill child processes spawned from jenkins after a build? -


while i'm building project using jenkins, need start nodejs server process host files, if start process following, build hang infinitely

<target name="staticserver" description="starts nodejs static server">     <exec executable="node">         <arg value="${env.workspace}staticserver.js"/>     </exec> </target> 

so switched following, , build run fine

<target name="staticserver" description="starts nodejs static server">     <exec executable="cmd.exe">         <arg value="/c"/>         <arg value="start"/>         <arg value="node"/>         <arg value="${env.workspace}staticserver.js"/>     </exec> </target> 

however when jenkins build finishes, node process left alive.

i searched around, seems everyone's problem killing child processes jenkins kills of them...

how should start node process jenkins can kill after build finished? approaching problem wrong angle , need @ different direction?

thanks.

i found 2 ways solve problem first add target kills node.exe, there won't problem if no other node instances needs run on same machine

<target name="stopnode" description="stops instances of node">     <exec executable="taskkill">         <arg value="/im"/>         <arg value="node.exe"/>     </exec> </target> 

the second add timer gets reset when server accessed, , shutdown server when hasn't been accessed in while.

global.timer = {     count: 5,     reset: function() {         this.count = 5;     } };  function countdown() {     global.timer.count = global.timer.count - 1;     //console.log(global.timer.count);     if (global.timer.count <= 0) {         clearinterval(cd);         process.exit(0);     } }  var cd = setinterval(function () { countdown() }, 1000); 

a jsfiddle fun: http://jsfiddle.net/jejkm/


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -