Restarting Tomcat after a successful deployment with Jenkins

How can I start a Jenkins instance of Tomcat after a successful deployment?

I have already tried using the script package, but the Tomcat instance is killed when the build is complete.

+5
source share
2 answers

Your answer lies in the Jenkins ProcessTreeKiller . more detailed explanation here .

This is a design solution to destroy any processes created by the assembly to maintain a clean environment. Unfortunately, this means that you cannot leave a process (such as Tomcat) running after the build.

You can disable this functionality globally (not recommended) by running Jenkins as follows:
java -Dhudson.util.ProcessTree.disable=true -jar jenkins.war

Or you can disable it for each case by starting the process with the changed environment variable:
BUILD_ID=dontKillMe ./catalina restart

Some people report, however, that changing the BUILD_ID not enough. They also recommend disabling:
JENKINS_COOKIE
JENKINS_SERVER_COOKIE

Edit:
Another problem that may be in the game is that when you connect to a remote shell and start a process in that remote shell session, as soon as you (Jenkins) disconnect, the session will be killed and all processes generated by the session will also be killed. To work around this problem, you need to disconnect the process from the shell session.

One of the methods:

nohup ./catalina restart &

+5
source

This is how I restart Tomcat after deployment through jenkins.

I have two DEV and QA servers where I need to deploy and restart tomcat. I have Jenkins installed on a DEV server.

  • First you need to set up the Create plugin build task in Jenkins.
  • Then create this tomcat-restart.ksh on the server where tomcat is installed.

#!/bin/bash echo "*********************Restarting Tomcat70.******************" sh /apps/apache/sss-tomcat70.ksh status echo "Trying to stop Tomcat." sh /apps/apache/sss-tomcat70.ksh stop echo "Getting Tomcat Status." sh /apps/apache/sss-tomcat70.ksh status echo "Trying to Start Tomcat" sh /apps/apache/sss-tomcat70.ksh start sleep 2 echo "Getting Tomcat Status" sh /apps/apache/sss-tomcat70.ksh status

Restarting Tomcat on the DEV server.

Since Jenkins and Tomcat are installed on the same computer, I directly call the script.

In Jenkins, go to Add post-build action and select Post build task , and in the Script text box add the following: /apps/apache/tomcat-restart.ksh

Restarting Tomcat on the QA server.

Since Jenkins is installed on a different server, I invoke a script to restart Tomcat through Secure Shell.

In Jenkins, go to Add post-build action select Post build task and in the script text field add the following:
sshpass -p 'myPassword' ssh -tt username@hostname sudo sh /apps/apache/tomcat-restart.ksh

You need to install sshpass if it is not already installed.

If all goes well, then you can see something similar in your Jenkins magazine.

 Running script : /apps/apache/tomcat-restart.ksh [workspace] $ /bin/sh -xe /tmp/hudson43653169595828207.sh + /apps/apache/tomcat-restart.ksh *********************Restarting Tomcat70.********************* Tomcat v7.0 is running as process ID 3552 *********************Trying to stop Tomcat.********************* Stopping Tomcat v7.0 running as process ID 3552... *********************Getting Tomcat Status.********************* Tomcat v7.0 is not running *********************Trying to Start Tomcat********************* Starting Tomcat v7.0 server... *********************Getting Tomcat Status********************* Tomcat v7.0 is running as process ID 17969 

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1204324/


All Articles