Avkash Chauhan's Blog

Windows Azure, Windows 8, Cloud Computing, Big Data and Hadoop: All together at one place.. One problem, One solution at One time...

Full Startup task based Tomcat/Java Worker Role Application for Windows Azure

Full Startup task based Tomcat/Java Worker Role Application for Windows Azure

Rate This
  • Comments 3

This Windows Azure Tomcat Solution is designed in a way that you can update your Tomcat project outside VS2010 project. The VS2010 application will be deployed once however whenever you would need to update, Tomcat, Java Run time or your own Tomcat based solution, you can update without updating your Windows Azure application. This project is based on Startup task in which Tomcat, Java and your project is downloaded from Azure Storage and then installed in Azure VM. Full source code is available for startup task and solution. 

Download Source code : http://tomcatazure.codeplex.com/

Step 1: Preparation for the files to be download from Azure Storage:

Java Run Time: 

- Download Java Run Time from Java web site and the zip the runtime from the installed location.  

- The JRE zip file should have a root folder as "jre7"

Tomcat Installation Package:

- Please download desired Tomcat installation zip file from http://tomcat.apache.org/download-70.cgi

- Please unzip the ZIP file to a location in your machine and edit \conf\server.xml as below: (MUST)

       <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />

Your Tomcat application project

- In most of the cases your Tomcat application will be inside "webapp"s folder in a folder itself. Please package your whole application into a ZIP file.

The above 3 zip files should have the root folder as below:

 

Step 2: Uploading all the files to Windows Azure Storage

Once you upload all 3 files (or more) to Windows Azure Storage your Windows Azure Storage container will look like as below:

 

Step 3: Opening Windows Azure Tomcat Solution in VS2010.

After you open Windows Azure Solution in Visual Studio 2010, the solution will look like as below:

 

Edit startup\startup.bat to have correct Windows Azure Storage credentials:

 

@REM Setting up Azure Stroage Credentials
set azurestoragename=*********azure_storage_name**************** set azurestoragekey=**********azure_storage_key***************** set storagecontainername=*****azure_storage_container_name******

@REM Download Tomcat ZIP
set filename=apache-tomcat-7.0.19-windows-x64.zip
startup\packagedownloader.exe "%azurestoragename%" "%azurestoragekey%" "%storagecontainername%" "%filename%"

@REM Download JRE Runtime ZIP
set filename=jre7.zip
startup\packagedownloader.exe "%azurestoragename%" "%azurestoragekey%" "%storagecontainername%" "%filename%"

@REM Download Tomcat/Java Applicaiton ZIP
set filename=myproject.zip
startup\packagedownloader.exe "%azurestoragename%" "%azurestoragekey%" "%storagecontainername%" "%filename%"

@REM unzip Tomcat
cscript //B //Nologo startup\unzip.vbs apache-tomcat-7.0.19-windows-x64.zip "%ROLEROOT%\approot"

@REM unzip JRE
cscript //B //Nologo startup\unzip.vbs jre7.zip "%ROLEROOT%\approot\apache-tomcat-7.0.19"

@REM unzip project files to tomcatServer\webapps folder
md "%ROLEROOT%\approot\apache-tomcat-7.0.19\webapps"
cscript //B //Nologo startup\unzip.vbs myproject.zip "%ROLEROOT%\approot\apache-tomcat-7.0.19\webapps"

set JRE_HOME=%ROLEROOT%\approot\apache-tomcat-7.0.19\jre7
set CATALINA_HOME=%ROLEROOT%\approot\apache-tomcat-7.0.19

@REM Edit Server.xml
@REM cd "%ROLEROOT%\approot\apache-tomcat-7.0.19\conf"
@REM copy server.xml server.orig.xml
@REM cscript //nologo startup\editserverxml.vbs server.xml 80

@REM start the server
cd "%ROLEROOT%\approot\apache-tomcat-7.0.19\bin"
copy startup.bat startup.back
set > %RoleRoot%\approot\env.txt
startup.bat > %RoleRoot%\approot\tomcat.txt
exit /b 0

The provided solution already have port 80 based TCP endpoint defined. IF you would need to add HTTPS endpont please look the "Adding SSL to Tomcat Solution" documentation section. 

 

Step 4: Adding RDP access to application and packaging for deployment

It is good to add RDP access to your application when you are ready to publish the application, add RDP access as well. If you dont know how to do, please follow link below:

http://blogs.msdn.com/b/avkashchauhan/archive/2011/04/03/setting-rdp-access-in-windows-azure-application-with-windows-azure-sdk-1-3-1-4.aspx

Now just deploy your application to Windows Azure. 

 

Step 5:  Verifying that Zip files are downloaded from Windows Azure Blob storage

After your VM will start and download your zip file the download completion log will be available on Azure Storage as below

 

Step 6: Running Tomcat Application

After some time your worker role will be ready as below:

Download Source code : http://tomcatazure.codeplex.com/

Leave a Comment
  • Please add 4 and 6 and type the answer here:
  • Post
Page 1 of 1 (3 items)