我为 Azure 网站创建了一个启动任务,该任务执行以下操作:
- 创建应用程序池
- 将虚拟目录转换为虚拟应用程序
我创建了一个执行这些任务的 powershell 脚本。
我已经在服务定义中设置了启动元素
<Startup>
<Task commandLine="MyStartup.cmd" executionContext="elevated" taskType="simple">
</Task>
</Startup>
到目前为止一切都很好。
但是,I've found out, rather late ,即:
IIS may not be fully configured during the startup task stage in the startup process, so role-specific data may not be available.
我认为这意味着运行 powershell 脚本时该网站可能不存在于 IIS 上。我已经测试了该脚本,果然它失败了,因为它在 IIS 上找不到虚拟目录。
我的问题是:有没有办法确保在 IIS 上创建网站之后运行 powershell 脚本?
请注意,如果可能的话,我真的不想使用Microsoft.WindowsAzure.ServiceRuntime.RoleEntryPoint.OnStart
。
提前致谢。
最佳答案
我按照 @kwill 的建议创建了以下内容:
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>
这有效。
关于iis - 创建网站后运行的 Azure 启动任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22106175/