Tomcat autodeploy sometimes explodes only partial WAR

858 Views Asked by At

Part of our web app management process is to create a WAR on a dropbox directory that is shared with our web server (running in Amazon EC2). We have a .NET script running on the web server that watches for WAR files to appear in the dropbox folder, and then move them (not copy) into the Tomcat webapps folder. The relevant bit of .NET code is:

$action = { $path = $Event.SourceEventArgs.FullPath
            $changeType = $Event.SourceEventArgs.ChangeType
            Write-Host "Found new WAR file: $path"
            ### Wait until file is not in use, e.g. copy/move is complete
            while (!(IsFileAccessible $path)) {
              Write-Host "Waiting for WAR file to be unused."
              Start-Sleep -s 10
            }
            ### Move the new WAR file to the server deployment folder.
            ### Tomcat will detect the new file and deploy it automatically.
            Move-Item "$path" "C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps" -force
            Write-Host "WAR file moved to deployment directory."
          }  

Usually this works fine, but once in a while Tomcat fails to explode the entire WAR leaving the web site crippled (missing index.html, for example). Some of the files and folders are there, but not all of them. Just deleting the deployment folder and letting Tomcat deploy again solves the problem (so this shows all the files are in the WAR that got moved).

I guess I don't actually know if (1) Tomcat failed to cleanup all the files of the prior deployment and did NO explode at all, or (2) it did not extract all the files of the WAR.

Any idea what could cause this behavior?

1

There are 1 best solutions below

0
On

In case anyone else runs into this particular situation, I finally found the key log message that gave the clue, the un-deployment was failing due to code that was not closing a file:

org.apache.catalina.startup.HostConfig.undeploy Undeploying context []
[ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.ExpandWar.deleteDir [C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps\ROOT\WEB-INF\classes\com\...\web\templates] could not be completely deleted. The presence of the remaining files may cause problems

Offending Java code:

InputStream in = Util.class.getClassLoader().getResourceAsStream("/com/.../web/templates/"+templateName)

and the stream was never closed. Putting it in a try() to auto-close solved the problem.