The process started with execute shell in jenkins will be killed.
In jenkins, the process started through execute shell will be killed.
When you configure an automatic update deployment project in jenkins, if you use execute shell to start/Close tomcat, you will find that tomcat can be disabled, but tomcat cannot be started, although the build will show that the execution is successful, however, tomcat is not started when you view the process. This is because Jenkins will Kill all derivative processes after Build. The following configurations are required to avoid this problem:
1. Reset the environment variable build_id
Add BUILD_ID = dontkillme to the execute shell input box to prevent jenkins from killing started tomcat processes.
2. Disable jenkins from killing derivative processes when starting jenkins.
Modify the/etc/sysconfig/jenkins configuration and add-Dhudson. util. ProcessTree. disable = true to JENKINS_JAVA_OPTIONS.
Multiple values, separated by Spaces
Jenkins needs to be restarted to take effect
After this method is configured once, no BUILD_ID is required for all jobs to prevent jenkins from killing started tomcat processes.
-Example:
BUILD_ID=DONTKILLMEps -ef |grep tomcat8 |awk '{print $2}'|xargs kill -9cd /opt/tomcat8/binsh ./shutdown.shsleep 40scd /opt/var/kms_conf/sh ./tinykms.shcd /opt/tomcat8/binsh ./startup.sh
From time to time, some people in the tribe may ask why tomcat cannot be started in execute shell or in windows batch. In most cases, tomcat cannot be started, however, after the job is started, the process is killed, resulting in the illusion that the job cannot be started. From the tomcat log, although the solution is also provided, it does not answer the essential question, use the weekend and evening time to explore this issue and summarize it for your reference. To effectively kill the child processes created during job running, Jenkins provides some native code to locate and kill them. This is very reasonable, when a job ends, it is necessary to kill the processes started during the running period. Otherwise, many zombie processes will be left in the system. Although Jenkins claims that this feature has been tested in various environments, Jenkins provides a way to disable this feature to cope with special circumstances in special environments. Although Jenkins's practice is reasonable, it also causes some problems. For example, we want to continue running the web application started in execute shell or windows batch after the job is completed, you can use either of the following methods to reach this directory. Method 1: Disable the sub-process killing feature through the startup parameters provided by Jenkins
Jenkins provides hudson. util. ProcessTree. disabl
The hudson. util. ProcessTreeKiller. disable attribute controls some features. If it is set to true, this feature is disabled. Hudson. util. processTree. disable is used from Jenkins 1.260, whereas Hudson before 1.315 can only be used. util. processTreeKiller. disable. For version compatibility, these two attributes may be used after Jenkins 1.260. We recommend that Jenkins users of Jenkins 1.260 use hudson. util. processTree. disable attribute.
This method needs to be set before Jenkins starts. The following describes how to set it based on the author's experience. If you have any omissions, please add them and correct them.
Start with java-jar,-Dhudson. util. ProcessTree. disable = true-jar jenkins. war
Start with Tomcat and modify catalina in Linux. sh. Add JAVA_OPTS = "$ JAVA_OPTS-Dhudson before the script starts. util. processTree. disable = true "; # modify catalina in Windows. bat. After the environment variable description, add set JAVA_OPTS = % JAVA_OPTS % "-Dhudson before the script starts. util. processTree. disable = true "; modify the Tomcat configuration file and restart Tomcat.
In most cases, disabling this feature thoroughly may not be the expected result. This method is not recommended at work. For the recommended method, refer to "method 2"
Method 2: Modify the Jenkins environment variable BUILD_ID so that Jenkins does not think that the background process you started is created by the job.
In the execute shell or windows batch input box, add the following code before executing the command that expects the job to continue after it ends (take tomcat as an example ):
Linux:
OLD_BUILD_ID = B U I L D I D E C H O "Role =" presentation "> BUILDIDecho B U I L D I D E C H O OLD_BUILD_ID
BUILD_ID = DONTKILLME // "DONTKILLME" is written only for readability. It can be replaced by any content you want.
Startup. sh // modify the startup command path according to the actual situation.
BUILD_ID = O L D B U I L D I D E C H O "Role =" presentation "> OLDBUILDIDecho O L D B U I L D I D E C H O BUILD_ID
Windows
OLD_BUILD_ID = % BUILD_ID % echo % OLD_BUILD_ID % BUILD_ID = DONTKILLME startup. bat // modify the startup command path BUILD_ID = % OLD_BUILD_ID % echo % BUILD_ID % according to the actual situation