forked from aws-samples/aws-codedeploy-sample-tomcat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import sample application to GitHub.
- Loading branch information
Showing
19 changed files
with
667 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
version: 0.0 | ||
os: linux | ||
files: | ||
- source: /target/SampleMavenTomcatApp.war | ||
destination: /tmp/codedeploy-deployment-staging-area/ | ||
- source: /scripts/configure_http_port.xsl | ||
destination: /tmp/codedeploy-deployment-staging-area/ | ||
hooks: | ||
ApplicationStop: | ||
- location: scripts/stop_application | ||
timeout: 300 | ||
BeforeInstall: | ||
- location: scripts/install_dependencies | ||
timeout: 300 | ||
ApplicationStart: | ||
- location: scripts/write_codedeploy_config.sh | ||
- location: scripts/start_application | ||
timeout: 300 | ||
ValidateService: | ||
- location: scripts/basic_health_check.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.amazonaws.labs</groupId> | ||
<artifactId>SampleMavenTomcatApp</artifactId> | ||
<packaging>war</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>SampleMavenTomcatApp Maven Webapp</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<spring.version>4.1.1.RELEASE</spring.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-java-sdk-bom</artifactId> | ||
<version>1.10.10</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.webjars</groupId> | ||
<artifactId>bootstrap</artifactId> | ||
<version>3.2.0</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.webjars</groupId> | ||
<artifactId>jquery</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.webjars</groupId> | ||
<artifactId>jquery</artifactId> | ||
<version>2.1.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<version>${spring.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webmvc</artifactId> | ||
<version>${spring.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-java-sdk-autoscaling</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-java-sdk-ec2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-java-sdk-codedeploy</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<finalName>SampleMavenTomcatApp</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-eclipse-plugin</artifactId> | ||
<version>2.9</version> | ||
<configuration> | ||
<downloadSources>true</downloadSources> | ||
<downloadJavadocs>false</downloadJavadocs> | ||
<wtpversion>2.0</wtpversion> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.tomcat.maven</groupId> | ||
<artifactId>tomcat7-maven-plugin</artifactId> | ||
<version>2.2</version> | ||
<configuration> | ||
<path>/</path> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
for i in `seq 1 10`; | ||
do | ||
HTTP_CODE=`curl --write-out '%{http_code}' -o /dev/null -m 10 -q -s http://localhost:4080` | ||
if [ "$HTTP_CODE" == "200" ]; then | ||
echo "Successfully pulled root page." | ||
exit 0; | ||
fi | ||
echo "Attempt to curl endpoint returned HTTP Code $HTTP_CODE. Backing off and retrying." | ||
sleep 10 | ||
done | ||
echo "Server did not come up after expected time. Failing." | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | ||
|
||
<xsl:template match="@*|node()"> | ||
<xsl:copy> | ||
<xsl:apply-templates select="@*|node()"/> | ||
</xsl:copy> | ||
</xsl:template> | ||
|
||
<xsl:template match="//Service/Connector[@protocol = 'HTTP/1.1']/@port"> | ||
<xsl:attribute name="port"> | ||
<xsl:value-of select="'4080'" /> | ||
</xsl:attribute> | ||
</xsl:template> | ||
|
||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
CATALINA_HOME=/usr/share/tomcat7-codedeploy | ||
|
||
# Tar file name | ||
TOMCAT7_CORE_TAR_FILENAME='apache-tomcat-7.0.68.tar.gz' | ||
# Download URL for Tomcat7 core | ||
TOMCAT7_CORE_DOWNLOAD_URL="http://mirror.olnevhost.net/pub/apache/tomcat/tomcat-7/v7.0.68/bin/$TOMCAT7_CORE_TAR_FILENAME" | ||
# The top-level directory after unpacking the tar file | ||
TOMCAT7_CORE_UNPACKED_DIRNAME='apache-tomcat-7.0.68' | ||
|
||
|
||
# Check whether there exists a valid instance | ||
# of Tomcat7 installed at the specified directory | ||
[[ -d $CATALINA_HOME ]] && { service tomcat7 status; } && { | ||
echo "Tomcat7 is already installed at $CATALINA_HOME. Skip reinstalling it." | ||
exit 0 | ||
} | ||
|
||
# Clear install directory | ||
if [ -d $CATALINA_HOME ]; then | ||
rm -rf $CATALINA_HOME | ||
fi | ||
mkdir -p $CATALINA_HOME | ||
|
||
# Download the latest Tomcat7 version | ||
cd /tmp | ||
{ which wget; } || { yum install wget; } | ||
wget $TOMCAT7_CORE_DOWNLOAD_URL | ||
if [[ -d /tmp/$TOMCAT7_CORE_UNPACKED_DIRNAME ]]; then | ||
rm -rf /tmp/$TOMCAT7_CORE_UNPACKED_DIRNAME | ||
fi | ||
tar xzf $TOMCAT7_CORE_TAR_FILENAME | ||
|
||
# Copy over to the CATALINA_HOME | ||
cp -r /tmp/$TOMCAT7_CORE_UNPACKED_DIRNAME/* $CATALINA_HOME | ||
|
||
# Install Java if not yet installed | ||
{ which java; } || { yum install java; } | ||
|
||
# Create the service init.d script | ||
cat > /etc/init.d/tomcat7 <<'EOF' | ||
#!/bin/bash | ||
# description: Tomcat7 Start Stop Restart | ||
# processname: tomcat7 | ||
PATH=$JAVA_HOME/bin:$PATH | ||
export PATH | ||
CATALINA_HOME='/usr/share/tomcat7-codedeploy' | ||
case $1 in | ||
start) | ||
sh $CATALINA_HOME/bin/startup.sh | ||
;; | ||
stop) | ||
sh $CATALINA_HOME/bin/shutdown.sh | ||
;; | ||
restart) | ||
sh $CATALINA_HOME/bin/shutdown.sh | ||
sh $CATALINA_HOME/bin/startup.sh | ||
;; | ||
esac | ||
exit 0 | ||
EOF | ||
|
||
# Change permission mode for the service script | ||
chmod 755 /etc/init.d/tomcat7 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
CATALINA_HOME='/usr/share/tomcat7-codedeploy' | ||
DEPLOY_TO_ROOT='true' | ||
#CONTEXT_PATH='##CONTEXT_PATH##' | ||
SERVER_HTTP_PORT='4080' | ||
|
||
TEMP_STAGING_DIR='/tmp/codedeploy-deployment-staging-area' | ||
WAR_STAGED_LOCATION="$TEMP_STAGING_DIR/SampleMavenTomcatApp.war" | ||
HTTP_PORT_CONFIG_XSL_LOCATION="$TEMP_STAGING_DIR/configure_http_port.xsl" | ||
|
||
# In Tomcat, ROOT.war maps to the server root | ||
if [[ "$DEPLOY_TO_ROOT" = 'true' ]]; then | ||
CONTEXT_PATH='ROOT' | ||
fi | ||
|
||
# Remove unpacked application artifacts | ||
if [[ -f $CATALINA_HOME/webapps/$CONTEXT_PATH.war ]]; then | ||
rm $CATALINA_HOME/webapps/$CONTEXT_PATH.war | ||
fi | ||
if [[ -d $CATALINA_HOME/webapps/$CONTEXT_PATH ]]; then | ||
rm -rfv $CATALINA_HOME/webapps/$CONTEXT_PATH | ||
fi | ||
|
||
# Copy the WAR file to the webapps directory | ||
cp $WAR_STAGED_LOCATION $CATALINA_HOME/webapps/$CONTEXT_PATH.war | ||
|
||
# Configure the Tomcat server HTTP connector | ||
{ which xsltproc; } || { yum install xsltproc; } || { apt-get install xsltproc; } | ||
cp $CATALINA_HOME/conf/server.xml $CATALINA_HOME/conf/server.xml.bak | ||
xsltproc $HTTP_PORT_CONFIG_XSL_LOCATION $CATALINA_HOME/conf/server.xml.bak > $CATALINA_HOME/conf/server.xml | ||
|
||
service tomcat7 start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
service tomcat7 stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
mkdir -p /var/codedeploy/tomcat-sample | ||
|
||
cat <<EOF >/var/codedeploy/tomcat-sample/env.properties | ||
APPLICATION_NAME=$APPLICATION_NAME | ||
DEPLOYMENT_GROUP_NAME=$DEPLOYMENT_GROUP_NAME | ||
DEPLOYMENT_ID=$DEPLOYMENT_ID | ||
EOF |
Oops, something went wrong.