Startup Tasks for Windows Azure Roles

Windows Azure supports startup tasks that can be use to perform operations and install components before your Azure Role starts on Virtual Server. You can use to startup tasks to install other software, register COM components, setting registry keys, start another process, etc. This is very useful in many situations where you might want to running an initialization scripts, execute batch files and PowerShell scripts etc before your Role starts. In the past, I had used a startup task to install ASP.NET MVC 3 when ASP.NET MVC 3 web role was not supported. You can add startup tasks by editing the ServiceDefinition.csdef file. The below configuration in the Service Definition  file will add a startup task.

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AzureDemo" xmlns="">
  <WebRole name="WebRole1" vmsize="Small">
     <Task commandLine="install.cmd" executionContext="elevated" />
 <!--Other Configurations below-->

The above configuration added a batch file install.cmd as a startup task. You should add the batch file install.cmd onto your Azure Role project. The executionContex attribute specifies the permission level.This value can be limited or elevated. The elevated execution context enables administrator level permission and limited level permission gives non-admin level permission. Windows Azure will look for the bin folder for the startup tasks. So you should specify the batch file as “Copy to Output Directory” in Visual Studio so that the batch file will be copied to bin folder of your Azure Role. In our example, the batch file install.cmd will be executed before the Azure role  starts.

No Comments