简体   繁体   English

如何从启动任务访问 Azure 本地存储?

[英]How to access Azure local storage from a startup task?

In my Azure role startup task I need to deploy my native C++ application.在我的 Azure 角色启动任务中,我需要部署我的原生 C++ 应用程序。 I do that by running a set of actions from a.cmd file.我通过从 a.cmd 文件运行一组操作来做到这一点。

The problem is that the E:\ drive where the role contents is located and from where the startup task is run only has about 1 gigabyte of free space and that's not enough for deploying that application.问题是角色内容所在的E:\驱动器以及运行启动任务的位置只有大约 1 GB 的可用空间,这不足以部署该应用程序。

I can of course ask for local storage in the service definition, but I can't find how to get the actual path of where the local storage will be located from the startup task - there's RoleEnvironment.GetLocalResource() for that but it seems to only be available from the role code and I need to do the same from inside the startup task.我当然可以在服务定义中要求本地存储,但我无法找到如何从启动任务中获取本地存储所在位置的实际路径 - 有RoleEnvironment.GetLocalResource()但它似乎只能从角色代码中获得,我需要在启动任务中做同样的事情。

How do I detect the path to my local storage from a startup task?如何从启动任务中检测到本地存储的路径?

You can write C# or PowerShell to do it.您可以编写 C# 或 PowerShell 来执行此操作。 These days, my preferred method is the following PowerShell script:这些天来,我首选的方法是以下 PowerShell 脚本:

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

which I then call from a batch file as needed:然后我根据需要从批处理文件中调用:

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

EDIT: See also http://blog.smarx.com/posts/using-a-local-storage-resource-from-a-startup-task , the same answer but on my blog.编辑:另见http://blog.smarx.com/posts/using-a-local-storage-resource-from-a-startup-task ,相同的答案,但在我的博客上。

If I recall correctly, we are using Azure Bootstrapper .如果我没记错的话,我们使用的是Azure Bootstrapper It's convenient, and you don't have to deal with the complications of PowerShell if you aren't familiar with it.它很方便,如果您不熟悉它,您不必处理 PowerShell 的复杂性。

I'm not 100% sure at this moment, but I remember it has local resource access as well, so you may be able to use it.目前我不是 100% 确定,但我记得它也具有本地资源访问权限,因此您也许可以使用它。

How do I detect the path to my local storage from a startup task?如何从启动任务中检测到本地存储的路径?

Use Local Storage to Store Files During Startup在启动期间使用本地存储来存储文件

<!-- 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>

And you can access with local evironment variable PathToStartupStorage , %PathToStartupStorage% from your startup script您可以使用本地环境变量PathToStartupStorage%PathToStartupStorage%从您的启动脚本中访问

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法从本地Azure存储模拟器,VisualStudio或Azure存储资源管理器访问队列 - I can't access a queue from local Azure Storage Emulator nor from VisualStudio, nor from Azure Storage Explorer Windows Azure启动任务未触发 - Windows Azure Startup task not firing Azure教程 - 如何使用本地blob存储 - Azure tutorial - How to use local blob storage 如何将多个 Azure VM 中的文件自动复制到 Azure 存储并随后访问 - How to copy files from multiple Azure VM to Azure Storage automatically and access then 具有启动任务的Windows Azure虚拟机 - Windows Azure Virtual Machine with Startup Task 为什么要从Azure启动任务内部调用32位regsvr32? - Why is 32-bit regsvr32 invoked from inside Azure startup task? Windows Azure中的本地存储错误 - Local Storage Error in Windows Azure 如何连接Azure存储以从blob存储中读取.txt文件 - How to connect Azure Storage to read .txt files from blob storage 如何从ml64.exe(MSVC 64位X64汇编程序)访问线程本地存储? - How Do I Access Thread Local Storage From ml64.exe (MSVC 64-bit X64 Assembler)? Windows Azure存储中的容器访问重置为私有 - Container Access in Windows Azure Storage Resets to Private
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM