我为Azure网站创建了一个启动任务,执行以下操作:
我已经创建了一个执行这些任务的powershell脚本。
我在服务定义
中设置了启动元素<Startup>
<Task commandLine="MyStartup.cmd" executionContext="elevated" taskType="simple">
</Task>
</Startup>
到目前为止一切顺利。
然而,I've found out, rather late,即:
在启动任务阶段,可能无法完全配置IIS 启动过程,因此特定于角色的数据可能不可用。
我认为这意味着运行powershell脚本时,IIS上可能不存在该网站。我已经测试了脚本,确定它失败了,因为它无法在IIS上找到虚拟目录。
我的问题是:有没有办法确保在IIS上创建 网站后运行powershell脚本 ?
请注意,如果可能,我真的不想使用Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint.OnStart
。
提前致谢。
答案 0 :(得分:6)
我接着是@kwill的建议并创建了以下内容:
Powershell的:
while(!($myWeb = Get-Website -name "*MyWeb*")){ Write-Host "Website not installed. Waiting 30 seconds..." Start-Sleep 30 } # Proceed with installation
和配置
<Task commandLine="MyBackground.cmd" executionContext="elevated" taskType="background">
</Task>
这很有效。
答案 1 :(得分:4)
查看http://blogs.msdn.com/b/kwill/archive/2011/05/05/windows-azure-role-architecture.aspx处的角色架构图。您可以看到在IISConfigurator为您的网站创建应用程序池之前执行启动任务。这意味着您可以对Apppool进行修改的唯一位置是OnStart。
我没有尝试过这个,但你可以创建一个后台类型的启动任务,让你的启动任务仍然在运行时继续启动进程的其余部分(即运行IISConfigurator),然后在启动时循环直到检测到虚拟目录。