In the previous post “Windows Azure Startup Tasks Part 1” we learned about the basics of start-up tasks and how they can enable you to realize solutions that may otherwise have been outside of the scope of PaaS. This powerful feature offers some additional functionality that we will cover in this post.
Towards the end of this post we will discuss some of the lessons I have learned when working with Start-up tasks easing your adoption of them.
Environment VariablesWhile the start-up tasks are executing they have access to environment variables that define various characteristics of the instance. The predefined variables are:
In some cases you may have a need to set an environment variable to be used in your start-up tasks. This can be done by adding a bit more XML. To add a new environment variable for the startup.cmd script to use named TaskName I simply add it to the service definition file as you see below.
In order to get access to more specific instance and environment details you can leverage XPATH queries against Worker Role Schema (http://msdn.microsoft.com/en-us/library/windowsazure/gg557552.aspx) or the Web Role Schema (http://msdn.microsoft.com/en-us/library/windowsazure/gg557553.aspx). In the following example an XPATH is used to determine if the task is running in the emulator.
XPATH based environment variables that are typically of interest include
This was not a complete list of environment variables. To find out more you can review the links above where you will see other exposed data such as the Virtual Machine size or web site names.
Lessons LearnedThe following few points summarize lessons I have learned over time.
Helpful Things to KnowSo that pretty much covers the basics. I am hoping everyone is comfortable with the information we have covered to this point because we are not going to dive into some more detailed scenarios and samples.
For this next section I will point out some things you can do in batch and PowerShell scripts that you may find useful.
Hopefully the lessons learned above will help guide you through the successful creation of start-up tasks. Watch for the next post “Widnows Azure Startup-up Tasks Part3” where I will show some common tasks that I perform in my scripts that may help you in the future.