我们正在运行一个包含3个实例的WebApp。我们想在晚上单独重启这些实例。我试图找到一个Powershell或REST API解决方案与cron作业一起工作,但我只是提出了重启整个WebApp的解决方案。
我们知道重启它们的手动过程(下面的屏幕截图链接),但我们希望自动化该过程。
答案 0 :(得分:2)
是的,您可以使用Azure Power Shell执行此操作,请检查此answer。
根据您的说明,我建议您首先使用Get-AzureRmResource
命令在您的网络应用中查找每个实例的流程。然后,您可以使用Remove-AzureRmResource
来停止这些过程。然后,当您访问azure Web应用程序时,azure将自动创建新实例的进程以运行您的应用程序。
更多细节,您可以参考下面的powershell代码:
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId '{your subscriptionid}'
$siteName = "{sitename}"
$rgGroup = "{groupname}"
$webSiteInstances = @()
#This gives you list of instances
$webSiteInstances = Get-AzureRmResource -ResourceGroupName $rgGroup -ResourceType Microsoft.Web/sites/instances -ResourceName $siteName -ApiVersion 2015-11-01
$sub = (Get-AzureRmContext).Subscription.SubscriptionId
foreach ($instance in $webSiteInstances)
{
$instanceId = $instance.Name
"Going to enumerate all processes on {0} instance" -f $instanceId
# This gives you list of processes running
# on a particular instance
$processList = Get-AzureRmResource `
-ResourceId /subscriptions/$sub/resourceGroups/$rgGroup/providers/Microsoft.Web/sites/$sitename/instances/$instanceId/processes `
-ApiVersion 2015-08-01
foreach ($process in $processList)
{
if ($process.Properties.Name -eq "w3wp")
{
$resourceId = "/subscriptions/$sub/resourceGroups/$rgGroup/providers/Microsoft.Web/sites/$sitename/instances/$instanceId/processes/" + $process.Properties.Id
$processInfoJson = Get-AzureRmResource -ResourceId $resourceId -ApiVersion 2015-08-01
# is_scm_site is a property which is set
# on the worker process for the KUDU
$computerName = $processInfoJson.Properties.Environment_variables.COMPUTERNAME
if ($processInfoJson.Properties.is_scm_site -ne $true)
{
$computerName = $processInfoJson.Properties.Environment_variables.COMPUTERNAME
"Instance ID" + $instanceId + "is for " + $computerName
"Going to stop this process " + $processInfoJson.Name + " with PID " + $processInfoJson.Properties.Id
# Remove-AzureRMResource finally STOPS the worker process
$result = Remove-AzureRmResource -ResourceId $resourceId -ApiVersion 2015-08-01 -Force
if ($result -eq $true)
{
"Process {0} stopped " -f $processInfoJson.Properties.Id
}
}
}
}
}
答案 1 :(得分:1)
如果您正在查看Windows Azure PowerShell Cmdlet,您要使用的命令是Reset-AzureRoleInstance(http://msdn.microsoft.com/en-us/library/jj152835.aspx)