Reputation: 141
I would like to restart remote tomcat instance using batch file. Is it possible?
flow:
Stop tomcat
execute some sql script
start tomcat
Is it possible? If so, could you please give me some insight to achieve this?
Thanks!
Upvotes: 1
Views: 2893
Reputation: 395
I wrote a ant build script which will restart tomcat and clear the tomcat cache. Just throw the xml file into tomcat/bin. The code used to wait for the server to stop doesn't seem to work on all systems so I just added a target that just waits for 3 minutes.
{code}
<property name="startServer.dir" value="." />
<property name="startServer.cmd.unix" value="startup.sh"/>
<property name="startServer.cmd.windows" value="startup.bat"/>
<property name="stopServer.cmd.unix" value="shutdown.sh"/>
<property name="stopServer.cmd.windows" value="shutdown.bat"/>
<property name="maven.port" value="8080"/>
<property name="deployed.cache" value="../work"/>
<!-- stop web server targets -->
<target name="stop" depends="" description="stop app server which is configured on this system">
<echo message="Attempting to stop app server ${startServer.dir}"/>
<echo message="${stopServer.cmd.unix} / ${stopServer.cmd.windows}"/>
<exec dir="${startServer.dir}" osfamily="unix" executable="sh" timeout="18000">
<arg line="${stopServer.cmd.unix}"/>
</exec>
<exec dir="${startServer.dir}" osfamily="windows" executable="cmd" timeout="18000">
<arg line="/c ${stopServer.cmd.windows}"/>
</exec>
<echo message="waiting for server to stop"/>
<waitfor maxwait="5" maxwaitunit="minute" checkevery="500">
<not>
<http url="http://localhost:${maven.port}"/>
</not>
</waitfor>
</target>
<target name="pause">
<echo message="Pausing for 3 minutes to make sure server is stopped" />
<sleep minutes="3"/>
</target>
<!-- start web server targets -->
<target name="start" description="start app server which is configured on this system">
<echo message="Attempting to start app server server ${startServer.dir}"/>
<echo message="${startServer.cmd.unix} / ${startServer.cmd.windows}"/>
<exec dir="${startServer.dir}" osfamily="unix" executable="sh" spawn="true">
<arg line="${startServer.cmd.unix}"/>
</exec>
<exec dir="${startServer.dir}" osfamily="windows" executable="cmd" spawn="true">
<arg line="/c ${startServer.cmd.windows}"/>
</exec>
</target>
<target name="cleanTomcat" description="Remove tomcat cashe">
<delete dir="${deployed.cache}" verbose="true"/>
</target>
<target name="restart" depends="stop,pause,cleanTomcat,start"/>
{code}
Upvotes: 0
Reputation: 3509
You can remotely deploy, start, stop and restart the tomcat. For this you will have to perform the following steps:
How to remotely operate the tomcat you can use the following link:
http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html
Upvotes: 0
Reputation: 115328
Sure it is possible. On the top of my head:
startup
, shutdown
, catalina
) that you can find in tomcat bin directory. The files extension depends on platform (.bat
for windows, .sh
for UnixUpvotes: 2