Startup task on a multiple site Azure web role
<WebRole name="webrole"> <Sites> <Site name="web0" physicalDirectory="../publish/web0"> ... </Site> <Site name="web1" physicalDirectory="../publish/web1"> ... </Site> </Sites> ... <Startup> <Task commandLine="StartupTasks\addScheduledTaskRunner.cmd" executionContext="elevated" taskType="background" /> </Startup> ... </WebRole>
In Windows Azure definition file (csdef), Startup Task configuration hangs off the web role as opposed to a site (see above). The interesting part is startup task files are added as a part of the site's project file. Now what happens when we have multiple sites? to which site do we put the startup task files on to?
Interestingly enough, after some experimentation I found that Windows Azure creates the following folder structure on the F drive of the VM of the Web Role:
Also the following structure in IIS of the Web Role:
Let me highlight a few things:
- multiple sites are deployed to IIS as separate websites
- each sites are pointing to the approot\_WASR_\0 and 1. I imagine if you have more sites, the number just keeps incrementing
- The sequence of the numbering matches with the sequence of the sites in Csdef
The most important part is the following:
Remember that the approot\bin path is where our startup tasks will be executed and also accessible from powershell/batch file by using %~dp0? Well, the content of approot\bin folder are *All* the binaries of the FIRST site listed in Csdef.
None of of the libraries from 2nd, 3rd site will go into that approot\bin.
So, if you have a multi site web role, you will need to put your startup task in the first site. You would probably want to treat this site as a Bootstrapper and not use it for anything to avoid confusion in the future.