开发者

How to access Azure local storage from a startup task?

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 pro开发者_JS百科blem 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?


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜