2011-07-13 40 views
1

在我的Azure角色启动任务中,我需要部署我的本地C++应用程序。我通过从.cmd文件运行一组操作来实现这一点。如何从启动任务访问Azure本地存储?

问题是E:\驱动器位于角色内容所在的位置以及运行启动任务的位置仅有约1千兆字节的可用空间,这不足以部署该应用程序。

我当然可以在服务定义中要求本地存储,但我找不到如何从启动任务中获取本地存储位置的实际路径 - 这里有RoleEnvironment.GetLocalResource(),但它似乎只能从角色代码中获得,我需要从启动任务中执行相同的操作。

如何从启动任务检测到本地存储的路径?

回答

3

您可以编写C#或PowerShell来执行此操作。这些天来,我的首选方法是以下PowerShell脚本:

param($name) 
[void]([System.Reflection.Assembly]::LoadWithPartialName("Microsoft.WindowsAzure.ServiceRuntime")) 
write-host ([Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment]::GetLocalResource($name)).RootPath.TrimEnd('\\') 

然后我从一个批处理文件调用需要:

powershell -c "set-executionpolicy unrestricted" 
for /f %%p in ('powershell .\getLocalResource.ps1 MyStorage') do set LOCALPATH=%%p 

编辑:又见http://blog.smarx.com/posts/using-a-local-storage-resource-from-a-startup-task,同样的答案,但在我的博客。

+1

另外值得一读的如何定义启动脚本:http://msdn.microsoft.com/en-us/library/gg456327.aspx –

3

如果我没有记错,我们使用Azure Bootstrapper。这很方便,如果您不熟悉PowerShell,您不必处理PowerShell的复杂问题。

我不能在这个时候100%肯定,但我记得它具有本地资源的访问一样,所以你可以使用它。

0

如何从启动任务检测到本地存储的路径?

使用本地存储来存储文件启动

<!-- Create the Local Storage used by the startup task. --> 
    <LocalResources> 
     <LocalStorage name="StartupLocalStorage" sizeInMB="5"/> 
    </LocalResources> 

    <Startup> 
     <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple"> 
     <Environment> 

      <!-- Create the environment variable that informs the startup task where to find its Local 
       Storage. %PathToStartupStorage% resolves to the fully qualified path to the location 
       of the Local Storage.--> 
      <Variable name="PathToStartupStorage"> 
      <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='StartupLocalStorage']/@path" /> 
      </Variable> 

     </Environment> 
     </Task> 
    </Startup> 

而且你可以与当地的环境现状变量PathToStartupStorage%PathToStartupStorage%从你的启动脚本访问

更多参考:http://msdn.microsoft.com/en-us/library/azure/hh974419.aspx

相关问题