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

发布于 2024-11-24 06:12:18 字数 304 浏览 2 评论 0原文

在我的 Azure 角色启动任务中,我需要部署本机 C++ 应用程序。我通过从 .cmd 文件运行一组操作来做到这一点。

问题是角色内容所在的 E:\ 驱动器以及运行启动任务的驱动器只有大约 1 GB 的可用空间,这不足以部署该应用程序。

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

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

In my Azure role startup task I need to deploy my native C++ application. I do that by running a set of actions from a .cmd file.

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.

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.

How do I detect the path to my local storage from a startup task?

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

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

发布评论

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

评论(3

著墨染雨君画夕 2024-12-01 06:12:48

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

在启动期间使用本地存储来存储文件

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

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

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

方圜几里 2024-12-01 06:12:46

如果我没记错的话,我们正在使用 Azure Bootstrapper。它很方便,如果您不熟悉 PowerShell,也不必处理它的复杂性。

目前我还不能 100% 确定,但我记得它也具有本地资源访问权限,因此您也许可以使用它。

If I recall correctly, we are using Azure Bootstrapper. It's convenient, and you don't have to deal with the complications of PowerShell if you aren't familiar with it.

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.

腻橙味 2024-12-01 06:12:43

您可以编写 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,相同答案但在我的博客上。

You can write C# or PowerShell to do it. These days, my preferred method is the following PowerShell script:

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.

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