Michael
Michael

Reputation: 22947

start up tomcat from ant script

i'm using the following ANT script to run tomcat:

<macrodef name="start-tomcat">
        <sequential>
            <exec executable="/bin/sh" >
                <arg value="-c" />
                <arg value='${tomcat.bin.dir}/startup.sh -Xms128M -Xmx512M' />
            </exec>
        </sequential>
</macrodef>

when i run the tomcat startup script from shell, tomcat starts normally and I see an output like this:

Using CATALINA_BASE:   /u/app
Using CATALINA_HOME:   /u/app/3rdparty/apache-tomcat-6.0.33
Using CATALINA_TMPDIR: /u/app/temp
Using JRE_HOME:        /usr/java/jre1.6.0_13
Using CLASSPATH:       /u/app/3rdparty/apache-tomcat-6.0.33/bin/bootstrap.jar

I have two problems:

  1. How can I tell ant to show me output like the above ? ant only shows me output when there is error.
  2. When i'm running the build.xml file from shell with ant executable tomcat does start up. when running the build file through a CI server - specifically Jenkins (Hudson) tomcat DOESN'T starts up.

I'm finding it hard to understand how to use the <exec> task to run shell scripts, is there anything i'm doing wrong ?

Thanks.

Upvotes: 4

Views: 6310

Answers (3)

Simple-Solution
Simple-Solution

Reputation: 4289

Here is how you can stop tomcat from Ant script: 

build.properties file:

 #----------------------------------------------------
 #Tomcat Configuration
 #----------------------------------------------------
 #Back-end Tomcat 
 tomcat.dir=${branch.dir}/../tomcat
 tomcat.bin.dir=${tomcat.dir}/bin
 tomcat.bootstrap.jar=${tomcat.bin.dir}/bootstrap.jar
 tomcat.jvmarg=-Dcatalina.home

loadproperties file

 <property file="${basedir}/build.properties" />

<!-- Stop tomcat -->
<target name="stop-tomcat" description="Stops back-end tomcat server" depends="prepare">
    <java jar="${tomcat.bootstrap.jar}" fork="true" spawn="false">
        <jvmarg value="${tomcat.jvmarg}=${tomcat.dir}" />
        <arg line="${arg.stop}" />
    </java>
    <echo>+---------------------------------+</echo>
    <echo>|   T O M C A T   S T O P P E D   |</echo>
    <echo>+---------------------------------+</echo>
</target>

Also I have added an element called spawn set to "false", which print execution output onto console. 

Hope this helps :) 

Upvotes: 1

Michael
Michael

Reputation: 22947

The problem had to do with Jenkins feature called ProcessTreeKiller described here.

Basically Jenkins automatically kills all processes spawned by a job by searching the process tree for processes with specific environment variable

All i had to do was to overwrite jenkins env variable called BUILD ID and it worked. I used a Setenv Plugin to set the env var specific for the build.

Upvotes: 2

FailedDev
FailedDev

Reputation: 26930

What about executing the command like this :

<exec executable="bash" >
            <arg value="-c" />
            <arg value='nohup ${tomcat.bin.dir}/startup.sh -Xms128M -Xmx512M &' />
</exec>

Upvotes: 1

Related Questions