SALES: 1-800-867-1380

Define Startup Tasks for a Role

Updated: November 13, 2013

You can define a startup task for a role by adding the Startup element to the definition of the role in the service definition file. For more information about these elements, see the Windows Azure Service Definition Schema (.csdef File).

You can edit the ServiceDefinition.csdef file by using your favorite text editor, or you can define the tasks for the role by using Visual Studio.

To edit the definition file

  1. Open the ServiceDefinition.csdef file for your service in the text editor.

  2. Add the Startup element to the WebRole or WorkerRole; startup tasks are not applicable to the VMRole. The following code example shows how to add a startup task to a web role that runs a command script:

    
    <ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
       <WebRole name="WebRole1">
          <Startup>
             <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple">
             </Task>
          </Startup>
       </WebRole>
    </ServiceDefinition>
    
    noteNote
    The commandLine task is relative to the AppRoot\Bin folder for the deployment. Environment variables are not expanded in the commandLine value. If environment expansion is required, you can create a small .cmd script that calls your startup task as cmd.exe, which expands the environment variables.

  3. Set the commandLine value to the name of the program or script file that you want to run.

  4. Set the executionContext to the level of permissions that you want for your startup task.

  5. Set the taskType to simple, foreground, or background depending on how you want the task to run. For more information on taskType, see WorkerRole Schema.

  6. Save the file.

See Also

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft