【问题标题】:Powershell for an Advanced Application Restart on an Azure Web App用于在 Azure Web 应用程序上重新启动高级应用程序的 Powershell
【发布时间】:2017-05-09 14:03:45
【问题描述】:

可以使用 Restart-​Azure​Rm​Web​App PowerShell 重新启动 Web 应用程序,但这会同时重新启动计划中的所有服务器,从而缩短停机时间。

Azure 门户具有“高级应用程序重启”功能,该功能使用重启各个实例之间的时间延迟。

有没有办法从 PowerShell 调用它?

【问题讨论】:

  • 有什么更新吗?如果您觉得我的回答有用/有帮助。请将其标记为答案,以便其他人可以从中受益。

标签: azure azure-web-app-service


【解决方案1】:

根据您的描述,我建议您可以先使用 Get-AzureRmResource 命令在您的 Web 应用程序中找到每个实例的进程。然后你可以使用 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
                }
            }       
       }

    }
}

结果:

【讨论】:

猜你喜欢
  • 2022-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-13
相关资源
最近更新 更多