In the use of Jenkins, we encountered a scenario is: After the Web code changes, can be automatically deployed to the test server, we wrote the run.sh script to restart the service, in the use of Jenkins's task to automatically run the scripts found that the service is not up. began to think that it was a run.sh script problem, but the direct execution is not a problem, and then always check the operating environment differences, found that this is not the reason; until later, it was suspected that the Jenkins task ended automatically shut down all child processes. The following shell script fragment solves the problem:
#临时改变BUILD_ID值 So Jenkins will not find and end the background process that run.sh started
Old_build_id= $BUILD _id
Echo $OLD _build_id
Build_id=dontkillme
./run.sh Restart
#改回原来的BUILD_ID值
Build_id= $OLD _build_id
Echo $BUILD _id
The root of the problem is that Jenkins uses Processtreekiller to kill all child processes, and this is the default behavior of Jenkins. In fact, looking back at this problem, we found that Jenkins's approach is very reasonable. When a build exception ends, or is terminated, it is necessary to end all the child processes that were started by this build. The link below provides more details, as well as workarounds. Https://wiki.jenkins-ci.org/display/JENKINS/ProcessTreeKiller
The background process started by the Jenkins task is automatically kill