Automating Deployment of Tomcat
Installation of Tomcat out of the box on linux, or using apt
or your package manager of choice is easy; but as you noted it's difficult to know where everything is and what's configured.
I've found the MOST configurable way to automate Tomcat installation on Linux is by using Chef. The ChefDK can be installed, and then using the Tomcat Cookbook for Chef you can configure and deploy chef again and again!
The advantage of installing Tomcat with Chef is a consistent installation of Tomcat in a manner that is standard, supportable, and in-line with the Tomcat documentation for installation on Linux.
Java pre-requisite
The Tomcat cookbook doesn't install Java, so generally I combine the Java Cookbook to automate the installation of your JRE with Tomcat.
Chef Role to install Tomcat
Below is an example Chef Role I have used to deploy JRE and then Tomcat to a linux box.
- The main two steps that install JRE then Tomcat are in the
run_list
section of the JSON file
- The
override_attributes
section of the Chef role sets the attributes for the Java and Tomcat recipes.
{
"name": "java-appserver-small",
"default_attributes": {},
"override_attributes": {
"java": {
"jdk_version": "7"
},
"oracle": {
"accept_oracle_download_terms": true
},
"tomcat": {
"java_options": "${JAVA_OPTS} -Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx3g -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=512m -XX:+DisableExplicitGC -XX:+CMSClassUnloadingEnabled"
}
},
"json_class": "Chef::Role",
"description": "Role for Java Apps Servers using OpenJDK7 - 15GB Memory",
"chef_type": "role",
"run_list": [
"recipe[java]",
"recipe[tomcat]"
]
}
It's a little bit of a learning curve, but once you know how to automate anything on linux with chef - it's a great start to rapid re-deployment and automation of anything you can imagine.
Automating deployment of an Application (WAR)
You can add a third recipe to your Chef role that will deploy an application on Tomcat. Generally Tomcat can be configured
to auto-unpack and deploy a WAR file.
Modify the run_list
in the role to include another recipe:
"run_list": [
"recipe[java]",
"recipe[tomcat]",
"recipe[app-deploy]"
]
Deploy WAR from local file on linux instance
The recipe chef will use app-deploy
is a set of instructions to copy a pre-defined WAR file to the Tomcat webapps directory. In the below recipe example, the WAR file path is defined in a from a separate attribute file, but you could hard code the location to copy from as well.
#
# Cookbook Name:: myChefCookbook
# Recipe:: app-deploy
#
# This recipe only installs the application.
# Base app server is setup via the java app server role.
#
# Copy WAR to webapps for auto-deployment
execute "cp #{node['myappfile']} /var/lib/tomcat/webapps/" do
action :run
not_if { File.exist?("/var/lib/tomcat/webapps/#{server_file(node['myappfile'])}") }
end
The recipe copies the WAR file, Tomcat deploys it.
Deploy WAR from AWS S3 bucket to AWS linux instance
The final recipe example below copies (using AWS tools) the WAR file from an Amazon S3 bucket onto the linux instance running Tomcat, deployed by chef, in the Amazon Web Services cloud provider.
# Copy WAR to webapps for auto-deployment - Requires that the instance have role with access to bucket
execute "aws s3 cp #{node['urls']['myappurl']} /var/lib/tomcat/webapps/" do
action :run
not_if { File.exist?("/var/lib/tomcat/webapps/#{server_file(node['urls']['myappurl'])}") }
end
ps -efww | grep tomcat
in the linux server and paste the output ?apt
basically automates the steps you mentioned. Go tohttp://localhost:8080
, that should load the default Tomcat page with some links. But if you really wanted to know the "manual" way that is similar to what you did on Windows, take a look at the answer here. It's on Ubuntu, so the commands should be similar on your Debian.