Tuesday, May 28, 2013

Automating Tomcat 7 Installation on EC2

Extending work performed in the earlier post Running Tomcat 7 on EC2, I began the process to automate the creation of a Tomcat 7 application server.  The magic is performed on the "Advanced Instance Options" page (which also has an equivalent in the EC2 API world):


The "User Data" area allows for the creation of a "one time script" which will be run immediately after the server is provisioned and started for the first time.  For this case, the following was dumped into a text file and included on the configuration wizard page:

 #!/bin/bash
export DEBIAN_FRONTEND=noninteractive
sudo apt-get update -q -y
sudo apt-get install tomcat7 -q -y
sudo apt-get install tomcat7-docs -q -y
sudo apt-get install tomcat7-examples -q -y

Note that the "as file" option was used as opposed to "as text".  There really is no technical reason for doing things this way;  However, this implementation does provide for a script file which could be placed under configuration management control (svn/git/etc) outside of this process.

After completing the instance wizard and waiting for provisioning, an Ubuntu 12 server was successfully created with Tomcat 7 and associated docs and examples already installed.  All that remained was the port configuration steps and service startup:

sudo nano /etc/tomcat7/server.xml
change instances of 8080 to 80, and save file
sudo nano /etc/default/tomcat7
change #AUTHBIND no to AUTHBIND yes, and save file
sudo service tomcat7 stop
sudo service tomcat7 start


In a future post, I'll attempt to integrate these remaining items into the user data script.

No comments:

Post a Comment