[英]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.