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.
source share