Question

I've created a start-up task for an Azure website that does the following:

  • Creates an AppPool
  • Converts a Virtual Directory into a Virtual Application

I've created a powershell script that carries out these tasks.

I've set up the startup element in the Service Definition

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

All good so far.

However, I've found out, rather late, that:

IIS may not be fully configured during the startup task stage in the startup process, so role-specific data may not be available.

I take this to mean that the website may not exist on IIS when the powershell script is run. I've tested the script and sure enough it fails because it can't find the virtual directory on IIS.

My question is: Is there a way to ensure the powershell script is run after the website is created on IIS?

Please note, I don't really want to use Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint.OnStart if possible.

Thanks in advance.

Était-ce utile?

La solution 2

Check out the role architecture diagram at http://blogs.msdn.com/b/kwill/archive/2011/05/05/windows-azure-role-architecture.aspx. You can see that the startup tasks are executed before IISConfigurator creates the application pool for your website. This means that the only place you can make modifications to the apppool is in OnStart.

I haven't tried this, but you could create a background type startup task which will let the rest of the startup process (ie. running IISConfigurator) proceed while your startup task is still running, and then within that startup just loop until the virtual directory is detected.

Autres conseils

I followed on from @kwill's suggestion and created the following:

Powershell:

while(!($myWeb = Get-Website -name "*MyWeb*")){
    Write-Host "Website not installed. Waiting 30 seconds..."
    Start-Sleep 30
}

# Proceed with installation

and configuration

  <Task commandLine="MyBackground.cmd" executionContext="elevated" taskType="background">
  </Task>

This works.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top