Azure Lei Zhang的博客

weibo: LeiZhang的微博/QQ: 185165016/QQ群:319036205/邮箱:leizhang1984@outlook.com/TeL:139-161-22926

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

  《Windows Azure Platform 系列文章目录

 

让我们再回顾一下Windows Azure Startup Task

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="WebRole1">
<Startup>
<Task commandLine="Startup.cmd" executionContext="limited" taskType="simple">
</Task>
</Startup>
</WebRole>
</ServiceDefinition>

  在以上代码中,最核心的就是Startup.cmd,这个cmd可以是PowerShell scripts。在这个cmd文件中你可以执行您自己的逻辑,比如

-  注册一个dll(regsvr32..)

-  注册一个Windows Service (InstallUtil..)

-  其他PowerShell scripts (比如安装其他第三方的组件,如Crystal Report)

  为什么我们需要Startup Task呢?

  我们知道,Windows Azure VM是非持久性的。在某些异常情况下(比如断电,硬件故障等),某个正常工作的Azure VM会宕机而无法正常使用。后台的Windows Azure Fabric Controller会自动把该VM上的Azure Apps迁移到同一数据中心的另外一台正常的计算节点之上,保证服务的持久性和健壮性。

  如果没有StartUp Task,那在Fabric Controller迁移之后,Azure Apps管理员不得不远程登录到新的VM上,然后手工执行regsvr32命令。否则Azure Apps无法正常运行(的确,因为在新的Azure VM上没有注册COM组件)。但这样岂不是非常麻烦:迁移之后还需要人工来注册,不能实现自动化。

  有了Startup Task功能会在系统迁移、故障恢复的时候自动执行命令,因此每次修改都是持久性的,不需要人为干预操作。

  如果大家对Startup Lifecycle (Startup 生命周期)感兴趣的,可以参考这篇文章 《Real World : Startup Lifecycle of a Windows Azure Role》http://msdn.microsoft.com/en-us/library/windowsazure/hh127476.aspx

posted on 2012-04-02 12:05  Lei Zhang的博客  阅读(1507)  评论(0编辑  收藏  举报