Project Description
This Windows Azure Tomcat Solution is designed in a way that you can update your Tomcat project outside VS2010 project. 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.

Blog: http://blogs.msdn.com/b/avkashchauhan/archive/2011/08/17/full-startup-task-based-tomcat-java-worker-role-application-for-windows-azure.aspx


Here are the highlights about this solution:

  1. You will host your Java Run-Time, Tomcat and your own solution in a ZIP file at Windows Azure Blob Storage
    1. Be sure to modify tomcat\conf\server.xml to user correct HTTP and HTTPS port as well as SSL certificate which you are going to use.
  2. Create a simple Windows Azure Worker Role Project 
  3. Add HTTP and HTTP endpoint along with Certificate which you are going to use for SSL
  4. Create a Startup task in Worker Role 
  5. In the Startup task we will do the following 
    1. Using Azureblobdownloader (http://azureblobdownloader.codeplex.com/) tool we will download Tomcat, Java and your project from Azure Storage to Azure VM
    2. After that we unzip these files 
    3. Then we setup Tomcat and Java environment variables as below
      1. > set JRE_HOME=%ROLEROOT%\approot\apache-tomcat-7.0.19\jre7
      2. > set CATALINA_HOME=%ROLEROOT%\approot\apache-tomcat-7.0.19
    4. After it will launch the Tomcat startup process using:
      1. > tomcat\bin\startup.bat
  6. Finally we edit workerrole.cs OnStart() function to included HTTP and/or HTTPS endpoint as below:

 

        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections 
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            TcpListener TomcatPortListener = new TcpListener(RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["TomcatWeb80"].IPEndpoint);
            Trace.WriteLine(RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["TomcatWeb80"].IPEndpoint.ToString(),"IP Address:Port");
            TomcatPortListener.Start();

            return base.OnStart();
        }


The Startup.bat looks like as below:

 

@REM Setting up Azure Stroage Credentials
set azurestoragename=happybuddha
set azurestoragekey=***********************AZURE-STORAGE-KEY**************==
set storagecontainername=xyz

@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

 

Last edited Aug 17, 2011 at 7:18 PM by Avkash, version 5