2015-09-29 38 views
0

我有一個天藍色的雲服務,我希望它在作業完成後暫停自己。我有一個可以暫停控制檯應用程序的雲服務的方法(如下所示),但是當我從放置的雲服務中放置方法並調用它時,它不會自行暫停。如何讓Azure Cloud Service使用PowerShell來暫停自己

public void StopService(string serviceName, string email, string password) 
    { 
     using (PowerShell script = PowerShell.Create()) 
     { 
      script.AddScript(string.Format("$password = ConvertTo-SecureString \"{0}\" -AsPlainText -Force", password)); 
      script.AddScript(string.Format("$userName = \"{0}\"", email)); 
      script.AddScript(string.Format("$creds = New-Object System.Management.Automation.PSCredential ($userName, $passwprd)")); 

      /*Code to sign in to azure subscription 
      * ... 
      * ... 
      */ 

      script.AddScript(string.Format("$Status = (Get-AzureDeployment -ServiceName \"{0}\").Status", serviceName)); 
      script.AddScript(string.Format("if($Status -eq \"Running\") {1} Get-AzureService -ServiceName \"{0}\" | Stop-AzureService {2}", serviceName, _bracketOpen, _bracketClose)); 
      script.AddScript(string.Format("(Get-AzureDeployment -ServiceName \"{0}\").Status", serviceName)); 

      Collection<PSObject> result = script.Invoke(); 
     } 
    } 

Azure雲服務可以暫停自己,還是需要暫停外部服務?

+0

任何具體理由要它暫停,不會被刪除? –

+0

我有另一個PowerShell腳本等待它從運行轉換爲掛起,然後它啓動其他邏輯 – Paul

+0

您可以在問題中詳細介紹其他邏輯的高級設計概述嗎?它不尋常的工人角色定期啓動和停止... –

回答

0

您必須改用Set-AzureDeployment cmdlet。以下是一個基本示例:

Set-AzureDeployment -Status -ServiceName "MySvc1" -Slot "Production" -NewStatus "Suspended" 

請注意,暫停Cloud Service並不意味着您不會爲此付費。這與關閉虛擬機而不取消分配類似。停止使用資源的唯一方法是刪除部署。

更多信息:

https://msdn.microsoft.com/en-us/library/azure/dn495140.aspx

相關問題