I'm trying deploy a War file on my Tomcat 7 installed by a cookbook on CHEF. But, I can't find a single answer for my question at any forums. I don't have any idea how to do this! I'm using a Ubuntu server 12.10. The recipe that I'm using is https://github.com/solarvm/tomcat7-cookbook
The simple way to do is is to use the service
resource to stop Tomcat, use the bash
resource or a file resource to copy the WAR file, and then use the service
resource to start Tomcat again.
That cookbook you are trying to use doesn't do WAR file deployment. But I found this one - https://github.com/poise/application_java - that may do the job.
And for what it is worth, I think you could find a better Tomcat installation cookbook too. For a start, there is a "tomcat" recipe on the Opscode Community Cookbooks site that can handle Tomcat 7.
(Hint: don't just use the first cookbook you find with Google. Do a Github search, and try to assess the cookbooks functionality and quality)
Have you already found $tomcat/webapps/ folder?
Steps doing a manual hotdeployment and update. Avoiding possible conflict you should do a temporary mywebapp.war.zip filename trick. Trick I have used in linux and windows for years.
- copy myapp.war to $tomcat/webapps/myapp.war.zip filename. Tomcat ignores it.
- rename myapp.war.zip to myapp.war filename. Tomcat finds a new web application.
- wait few seconds, you should find $tomcat/webapps/myapp/ extract folder made by tomcat. war file was autoextracted and now available.
- browse to
http://localhost:8080/myapp/
URL address
Update existing web application using overwrite trick.
- copy myapp.war to $tomcat/webapps/myapp.war.zip filename
- rename myapp.war.zip to myapp.war filename, force overwrite existing one.
- wait few seconds, you should see $tomcat/webapps/myapp/ folder timestamp be updated
- browse to
http://localhost:8080/myapp/
URL address
Or update existing web application using delete-copy trick.
- copy myapp.war to $tomcat/webapps/myapp.war.zip filename
- delete existing myapp.war filename
- wait few seconds, you should see $tomcat/webapps/myapp/ folder being removed
- rename myapp.war.zip to myapp.war filename
- wait few seconds, you should find $tomcat/webapps/myapp/ extract folder made by tomcat. war file was autoextracted and now available.
- browse to
http://localhost:8080/myapp/
URL address
Reason for a temporary war.zip filename is ensure file is fully copied to a destination folder before Tomcat touches it. Copying large files directly to .war filename may trigger Tomcat reading halfsized file content.
A very important part to remember while doing this in chef is to use a guard conditions to not let chef keep deploying the file on every run. As the steps explained above are fine but when you code in chef, it will keep copying the file in each run and deploying unless you have a guard condition.
Take for example below case, chef will execute this in each run.
# Extract
execute "tar" do
user "#{tc7user}"
group "#{tc7group}"
installation_dir = "#{tc7target}"
cwd installation_dir
command "tar zxf /tmp/#{tc7tarball}"
action :run
end
To prevent chef from executing the on each run use the creates
property with parameter of the full path of the file being created. The next chef run will see that file was already created and will skip it.
来源:https://stackoverflow.com/questions/21094477/how-to-upload-a-war-file-on-tomcat-7-cookbook-by-chef