Client Pay Portal
 azure

Using Azure Startup Commands to configure your Azure Instances

Windows Azure provides a great platform for deploying web applications into a scalable, flexible environment. With that scalability, several "presets" have been made within the Windows installations that may not align with your application and how it functions. Luckily, Azure has Startup Tasks that you can use to configure the role the way you need to.

Every time an Azure instance starts it will use the uploaded application image to create the new role. Startup tasks are executed when an instance comes online so the goal is to configure the server as required every time it starts. As roles recycle, the Startup tasks ensure they are configured correctly and the application performs as expected.


Configuring Startup Tasks

Startup tasks usually consist of a command file (.cmd). In the .cmd file you script out he command(s) you want to execute when the role starts. This file is then included within your Azure project. The Startup tasks are defined in the ServiuceDefinition.csdef file.

    <Startup>
      <Task commandLine="settimezone.cmd" executionContext="elevated" taskType="simple">
      </Task>
      <Task commandLine="disabletimeout.cmd" executionContext="elevated" taskType="simple">
      </Task>
    </Startup>


NOTE

When defining a task, be sure to set the properties of the task appropriately.
Commandline: .cmd file to execute

executionContext: Determines the permission the task will run under.
     Elevated = Administrator
    Limited = Same permissions the role runs as

taskType: Type of task to execute
    Simple: Task completes before role starts
    Background: Executes on start, but role does not wait for completion to start
    Foreground: Executes on start and role cannot restart until startup tasks finishes.

Here are a few Startup tasks I recommend to help your application run smoothly:


Disable AppPool Timeouts

By default, IIS configures app pools to timeout after 20 minutes.  If you application requires a good bit of compilation to run properly this could become an issue for your users and the site performance.  Adding the following Startup task will disable the app pool, ensuring your application stays as responsive as possible.

Command File Text:

%windir%\system32\inetsrv\appcmd set config -section:applicationPools -applicationPoolDefaults.processModel.idleTimeout:00:00:00


Setting the time zone

Azure instances are set to UTC time. This can be an issue if your application depends on reporting server time to users or for data retention. Using the following Startup task you can set the time zone to your preferred setting:

Command File Text:

tzutil /s "Eastern Standard Time"


Installing Software

Some companies have non-.NET applications they would like to host in Azure. Adding these to Azure is fairly simple process that involves using the WebpiCmdLine.exe utility and installing the protocol on the server.

Command File Text:

WebPICmdLine.exe /Products: PHP

For detailed information on using the WebPICmd tool, click here.


Writing to the Event Log

Some applications need access to write to the Windows Event Log and performance counter. The following Startup task will allow the application to writer to the Event Log.

Command File Text:

powershell Set-ExecutionPolicy RemoteSigned -Force
powershell -ExecutionPolicy Unrestricted .\CreateEventLog.ps1

This sample uses a PowerShell script to set up the log.

new-eventlog -logname 'SAMPLEEventLogs' -source 'app'

Using Startup tasks can really open a lot of possibilities for developers. Be sure to configure them correctly and you will be able to easily configure your applications for optimal performance and functionality.

 

Author

Wiz E. Wig, Mascot & Director of Magic
Wiz E. Wig

Director of Magic