Azure:如何执行延迟的启动任务?

发布于 2024-12-18 04:22:32 字数 1448 浏览 2 评论 0原文

我的 WebRole 中有两个站点,并定义了启动任务。

第一行工作正常,它为我创建了一个新的应用程序池:

%WINDIR%\system32\inetsrv\appcmd.exe add apppool /name:"VCPool" /managedRuntimeVersion:"v4.0" /managedPipelineMode:"Integrated"

现在我想将第二行更改为这个新创建的应用程序池,但随后添加另一行并没有帮助。

%WINDIR%\system32\inetsrv\appcmd.exe set app "WebRole_IN_0_VC/" /applicationPool:"VCPool"

看来第二个网站还没有准备好。

如何将我的任务延迟 30 秒或稍微延迟 appcmd.exe? 除非有办法为此启动任务创建依赖项,否则它只能在第二个站点启动并运行时执行?

任何帮助将不胜感激, 非常感谢,

有没有办法将此执行延迟 30 秒,以确保第二个站点已启动并且可以更改?

更新:

感谢您的提示。我已对此事进行了进一步调查。我找到了 OnStart() 事件。

1) 但由于我使用 silverlight 并简单地将现有 Web 项目包装在 Cloud Roles 项目中,因此我不会有这样的 WebRole.cs。我可以将其添加到我的 Silverlight Web 项目中并在那里使用吗?或者是否建议从头开始创建一个 WebRole 项目并使其完全替换 Silverlight Web 项目?

2)关于服务定义中的标签,我是不是简单的这样添加呢?当网络角色运行提升时,会产生任何安全隐患吗?

<WebRole name="WebRole" enableNativeCodeExecution="true" vmsize="ExtraSmall">
    <Runtime executionContext="elevated"/>
    <Sites>
      <Site name="WebRole" physicalDirectory="./WebRole">
      ...
    </Sites>
</WebRole>

3)最后但并非最不重要的一点是如何运行 cmd 文件或

%WINDIR%\system32\inetsrv\appcmd.exe set site /site.name:"WebRole_IN_0_VC" /[Path='/'].applicationPool:"ASP.NET v4.0" >>Log.txt

OnStart() 方法中的这一行?

I have two Sites within my WebRole and have defined a Startup task.

The first line works fine, it creates a new App pool for me:

%WINDIR%\system32\inetsrv\appcmd.exe add apppool /name:"VCPool" /managedRuntimeVersion:"v4.0" /managedPipelineMode:"Integrated"

Now I would like to change my second to this new created AppPool, but adding another line right after, doesn't help.

%WINDIR%\system32\inetsrv\appcmd.exe set app "WebRole_IN_0_VC/" /applicationPool:"VCPool"

It seems the second site is somehow not yet ready.

How can I delay my task by 30 seconds or delay appcmd.exe slightly?
Unless there is a way to create dependencies for this startup task that it shall only be executed when that second site is up and running?

Any help would be highly appreciated,
Many Thanks,

Is there a way to delay this execution by 30 seconds to make sure the second site is up and can be changed?

Update:

Thanks for the hints. I have made further investigation into this matter. I have found OnStart() event.

1) But since I am using silverlight and simply wrap the existing Web project in the Cloud Roles project, I wouldn't have a WebRole.cs as such. Can I just add it to my Silverlight Web project and use it there? Or is it recommended creating a WebRole project from scratch and make it to replace the Silverlight Web project alltogether?

2) Regarding the <Runtime/> tag in the service definition, do I simply add it like this? Would it have any security implications when the webrole runs elevated?

<WebRole name="WebRole" enableNativeCodeExecution="true" vmsize="ExtraSmall">
    <Runtime executionContext="elevated"/>
    <Sites>
      <Site name="WebRole" physicalDirectory="./WebRole">
      ...
    </Sites>
</WebRole>

3) Last but not least how do I run a cmd file or in fact this line

%WINDIR%\system32\inetsrv\appcmd.exe set site /site.name:"WebRole_IN_0_VC" /[Path='/'].applicationPool:"ASP.NET v4.0" >>Log.txt

in the OnStart() method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

自由如风 2024-12-25 04:22:32

您可以探索使用 PowerShell 脚本来执行这些任务吗? PowerShell 有一种方法可以让线程休眠。 这样的东西

像批处理文件

%WINDIR%\system32\inetsrv\appcmd.exe add apppool /name:"VCPool" /managedRuntimeVersion:"v4.0" /managedPipelineMode:"Integrated"
powershell -command "Set-ExecutionPolicy Unrestricted" 2>> err.out 
powershell .\sleep.ps1 2>> err.out
%WINDIR%\system32\inetsrv\appcmd.exe set app "WebRole_IN_0_VC/" /applicationPool:"VCPool"

我还没有尝试过,但它应该可以工作。请参阅此 post 了解 Powershell 集成。

Can you explore using PowerShell scripts for performing these tasks. PowerShell has a way to sleep thread. Something like

Batch file

%WINDIR%\system32\inetsrv\appcmd.exe add apppool /name:"VCPool" /managedRuntimeVersion:"v4.0" /managedPipelineMode:"Integrated"
powershell -command "Set-ExecutionPolicy Unrestricted" 2>> err.out 
powershell .\sleep.ps1 2>> err.out
%WINDIR%\system32\inetsrv\appcmd.exe set app "WebRole_IN_0_VC/" /applicationPool:"VCPool"

I have not tried but it should work. See this post to know about Powershell integration.

旧人九事 2024-12-25 04:22:32

正如您所发现的,该站点是在“任务”部分运行后创建的。相反,从“OnStart”事件运行代码。到那时该网站就已经创建了。您可能需要更新您的服务定义文件以运行您的角色“提升” 这可以通过添加以下标签来完成:

<Runtime executionContext="elevated"/>

已编辑

要回答您的进一步问题:

1) 无论您有什么项目,您都应该能够添加 RoleEntryPoint 类。您可能需要手动执行此操作。

2) 添加运行时标签不会给您的部署增加任何重大风险。

3) 创建一个 cmd 文件来放入命令(即 OnStart.cmd)并使用如下代码:

System.Diagnostics.Process.Start("OnStart.cmd")

有关启动进程的更多信息,请访问:http://msdn.microsoft.com/en-us/library/53ezey2s.aspx

The site, as you have discovered, is created after the 'Task' section runs. Instead, run your code from the 'OnStart' event. The site will have been created by that point. You may need to update your Service Definition file to run your role 'elevated' This can be done by adding this tag:

<Runtime executionContext="elevated"/>

Edited

To answer your further questions:

1) Whatever project you have, you should just be able to add the RoleEntryPoint class. You may have to do this manually.

2) Adding the runtime tag won't add any significant risk to your deployment.

3) Create a cmd file to put your command in (i.e. OnStart.cmd) and use some code like this:

System.Diagnostics.Process.Start("OnStart.cmd")

More information on starting a process here: http://msdn.microsoft.com/en-us/library/53ezey2s.aspx

素年丶 2024-12-25 04:22:32

对于那些感兴趣的人...我刚刚在博客中介绍了如何在 Windows Azure 配置 IIS 网站上执行 AppCmd 启动任务 - 包括通过 Web 角色名称查找站点,并延迟执行它,以便站点配置已由 Azure 的 IISConfigurator.exe 创建。

更多信息:http://mvolo.com/configure-iis -websites-windows-azure-startup-tasks-appcmd/

谢谢,
麦克风

For those interested ... I just blogged about how to execute AppCmd startup tasks on Windows Azure configure IIS websites - including finding the site by web role name, and executing it delayed so that the site config is already created by Azure's IISConfigurator.exe.

More here: http://mvolo.com/configure-iis-websites-windows-azure-startup-tasks-appcmd/.

Thanks,
Mike

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文