Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy a war to tomcat

In the past 10 years or so, I had the opportunity to deploy web applications into a tomcat countless times. I also wrote several scripts trying to do that automatically, but never managed to completely automate it.

Here is the issue. I am trying to deploy a new war, with the same name as an existing war in the webapps of my tomcat.

Option 1: The naive approach - just copy the war and wait for it to update the exploded directory. This sometimes work. Many times - the exploded directory is not updated in a reasonable time.
Option 2: The through approach - stop the tomcat, delete all the wars and temporary files. copy the war and start the tomcat. This usually involves stopping the tomcat, waiting for a while - and then checking to see if the process is still alive and killing it.
Option 3: The manual approach - This might be surprising, but I found it to work many of the times - copy the war, wait for the exploded directory to be updated, and once it does - restart the tomcat. if it doesn't - you can try to delete the temporary work files, and that sometimes help.

I also tried many options - with different order and subset of the actions - restart, stop, delete war, delete exploded, delete localhost context, delete localhost work directory, copy war, sleep, compare dates, ask the tomcat politely to reload, etc. Nothing seemed to just work.

It might be something that I am doing wrong, but I've heard the same experience from numerous people, so I'm here to get some advice - what say you? What is the best way to deploy a new war to a tomcat?

Thanks!

like image 250
krakover Avatar asked Mar 31 '12 00:03

krakover


3 Answers

you can easily automate this in a shell script with curl

on tomcat 6:

curl --upload-file deployme.war "http://tomcat:s3cret@localhost:8088/manager/deploy?path=/deployme&update=true"

on tomcat 7

curl -T "deployme.war" "http://tomcat:s3cret@localhost:8080/manager/text/deploy?path=/deployme&update=true"

or via almost any porgramming language. I posted a java based solution here

like image 188
systemkern Avatar answered Nov 20 '22 03:11

systemkern


I tend to go for Option 2. If there is a project I am working on in the ide especially with a debugger attached, I find things eventually start getting messed up. Might be chasing a red herring for an hour before I discover clearing everything away makes the problem go away. Then it is nice to have a script on the side that I can occasionally launch to clear everything up:

  • shutdown force with a 60s timeout
  • clear out the log, temp, work directories
  • clear out the webapp folder
  • copy in the new war file from the build location
  • explode the new war file
  • if necessary, run an awk script to customize machine specific values in the properties files (hence the previous explode)
  • startup with the CATALINA_PID environment variable set (to enable the shutdown force)

Normally things shutdown nicely. If not, then there is usually a background thread that was started up but missing a shutdown hook (say a memecached client) and needs to be hunted down. Normally, just dropping in the new war seems to work to. But if in a dev environment, a script for doing the full blown restart is nice.

like image 9
Glenn Avatar answered Nov 20 '22 02:11

Glenn


Cargo - http://cargo.codehaus.org/ - can be used to remotely deploy WAR files to a number of web containers, Tomcat included.

See http://cargo.codehaus.org/Quick+start for examples in Java. Ant and Maven support is also available.

like image 4
Thorbjørn Ravn Andersen Avatar answered Nov 20 '22 04:11

Thorbjørn Ravn Andersen