0

我目前正在尝试通过将文件从blob存储中拉入角色并通过批处理脚本使用它进行自动化,从而将应用程序部署到Azure Worker角色,该批处理脚本也位于blob存储。我正在使用onStart完成此操作。这里是我的OnStart方法的简化版本:使用LocalResource自动化Azure中的应用程序部署

开始将其拉文件下来:

public override bool OnStart() 
     { 
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); 

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); 

CloudBlobContainer container = blobClient.GetContainerReference("mycontainer"); 

container.CreateIfNotExist(); 

CloudBlob file = container.GetBlobReference("file.bat"); 

实际上得到的文件进入了角色:

LocalResource localResource = RoleEnvironment.GetLocalResource("localStore"); 
      string filePath = System.IO.Path.Combine(localResource.RootPath, "file.bat"); 

using (var fileStream = System.IO.File.OpenWrite(@filePath)) 
      { 
       file.DownloadToStream(fileStream); 
      } 

这是我怎么弄批文件和依赖关系转化为角色。我现在的问题是 - 最初,我建立了批处理文件,假设其他文件将被放置在C:\上。例如 - C:\installer.exeC:\archive.zip等,但现在这些文件在localStorage中。

我在想我可以A)以某种方式通过动态写入脚本onStart来告诉批处理文件localStorage在哪里,或B)将localStorage更改为使用C:\

我不知道该怎么做,或者这里要做的最好的事情是什么。思考?

+0

另一种可能性是通过路径到本地存储为输入到批处理文件。例如如果我有一个名为mycmd.bat的批处理文件,如下所示: ============= ECHO%1 ============= 如果我打电话给mycmd.bat“C:\ Program Files”,它只会在控制台上打印“C:\ Program Files”。 – 2012-08-06 07:53:03

回答

1

我不会改变LocalStorage来使用C​​:(你会怎么做呢?)。看看Steve的博文:Using a Local Storage Resource From a Startup Task。他解释了如何使用powershell获取LocalResource(甚至可以从批处理文件中调用该脚本)。

为什么不使用Windows Azure Bootstrapper?这是一个小工具,可以帮助您配置角色而无需编写任何代码,只需从启动任务调用该工具,并且可以下载文件(也可以像您一样从blob存储中下载),使用本地资源,...

bootstrapper.exe -get http://download.microsoft.com/download/F/3/1/F31EF055-3C46-4E35-AB7B-3261A303A3B6/AspNetMVC3ToolsUpdateSetup.exe -lr $lr(temp) -run $lr(temp)\AspNetMVC3ToolsUpdateSetup.exe -args /q 

注:而不是在批处理文件中使用绝对引用,使之使用使用相对路径%〜DP0

相关问题