2017-08-09 55 views

回答

0

您可以通過創建Web作業並放置PowerShell腳本來停止和啓動Web應用程序來實現此目的。

要執行Azure App Service的啓動/停止操作,Web作業應該可以訪問您的訂閱。它還需要您的Azure配置文件。

Login-AzureRmAccount 
Save-AzureRmProfile -Path "E:\azureprofile.json" 

創建PowerShell來停止/啓動應用程序服務

創建一個新的文件夾,將在 上一步中下載的發佈配置文件。

創建PowerShell和保存爲run.ps1

$ProgressPreference= "SilentlyContinue" 
Select-AzureRmProfile -Path "azureprofile.json" 
Select-AzureRmSubscription -SubscriptionId '<subscriptionId>' 
Stop-AzureRmWebApp -Name '<AppService-Name>' -ResourceGroupName '<Resource-Group-Name>' 
Start-AzureRmWebApp -Name '<AppService-Name>' -ResourceGroupName '<Resource-Group-Name>' 

在App Web Service的工作部分添加這一點,並運行基於通過創建一個cron表達您的要求。

參考:Azure App Services: Automate Application restart using Web Job

+0

命令Save-AzureRmProfile -Path「E:\ azureprofile.json」返回一個錯誤,指出「Save-AzureRmProfile」未被識別爲cmdlet,函數,腳本文件或可操作程序的名稱。 – Apurva

+0

Select-AzureRmSubscription現在發生錯誤。 – Apurva

+0

您正在使用哪個版本的Powershell? Save-AzureRmProfile適用於3.7版本。您可以使用以下cmdlet來檢查Azure PowerShell版本。 Get-Module -ListAvailable -Name Azure -Refresh 如果您使用的是最新版本,那麼您可以使用Save-AzureRmContext -Path「E:\ azureprofile.json」。 參考:https://github.com/Azure/azure-powershell/blob/preview/documentation/release-notes/migration-guide.4.0.0.md – Ashok

0

保存-AzureRmProfile -Path 「E:\ azureprofile.json」 返回錯誤但命令保存-AzureRmContext路徑 「C:\ script.json」 給出的輸出爲相同的Save-AzureRmProfile -Path「E:\ azureprofile.json」。

+0

請在發佈答案的原始問題實例中包含更新這會讓社區感到困惑。 –

0

我們也可以用Azure Rest API來做到這一點。關於如何獲取訪問令牌請參考azure document

POST /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/restart?api-version=2016-08-01&softRestart&synchronous={softRestart&synchronous} 

下列文件類型均被WebJob接受:

.CMD,.BAT,.EXE(使用在cmd視窗)

的.ps1(使用的powershell)。 sh(使用bash)

.php(使用php)

的.py(使用python)

的.js(使用節點)

的.jar(用java)

如果C#是可能的,有一個example使用NET庫。

相關問題