File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Restarting Tomcat service on a remote machine from Hudson Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Restarting Tomcat service on a remote machine from Hudson" Watch "Restarting Tomcat service on a remote machine from Hudson" New topic

Restarting Tomcat service on a remote machine from Hudson

AmitDBond Sethi

Joined: Jun 06, 2008
Posts: 11

We are using Hudson as CI tool. Our requirement is such that, If the build is successfull in hudson, we want to deploy the application war to a tomcat service.
The tomcat service and Hudson are running on different machines (devserver2 and devserver1 respectively) in the same network. For this purpose, I have created an ant script which stops the tomcat service, copy the war in the webapp directory and then start the tomcat service again.
The ant script I have written are like this (only stop and start service targets are mentioned here).

<target name="stoptomcatdevsvr2" description="Stops the ${service}">
<exec executable="sc.exe">
<arg value="\\goshcc-devsvr2"/>
<arg value="stop"/>
<arg value="tomcat6"/>

<target name="starttomcatdevsvr2" description="Stops the ${service}">
<exec executable="sc.exe">
<arg value="\\goshcc-devsvr2"/>
<arg value="start"/>
<arg value="tomcat6"/>

Every thing works fine if the ant is executed out side the Hudson. But when I execute the ant using Hudson's Ant configuration, I get the below problem.

[exec] [SC] OpenService FAILED 5:
[exec] Access is denied.

devserver1 has access to start/stop services at devserver2 remotely. This I am 100% sure as I can execute below commands from the command prompt.

sc \\goshcc-devsvr2 stop Tomcat6
sc \\goshcc-devsvr2 start Tomcat6

I am not sure why the same ant does not work when running under Hudson.
Can someone please help me.

Thanks and Regards,
Amit Sethi
Misha Ver
Ranch Hand

Joined: Mar 03, 2008
Posts: 470
I wonder why you are not using this Executing Manager Commands With Ant
It is sorta covered in the JavaRanch Style Guide.
subject: Restarting Tomcat service on a remote machine from Hudson
Similar Threads
Starting Tomcat from ANT
Which IDE support JSP 2.0
Problem with
ANT script running a WIN cmd with start??
Stop/Start Tomcat within eclipse