3
votes

I have a set of Azure App Services which occasionally have single instances that become unhealthy. We've identified that restarting that specific instance via Advanced Diagnostics brings the instance back up.

We'd like to build some automation such that once this unhealthy instance is detected, we will automatically go and restart that instance. Note that we only want to restart the unhealthy instance, not the entire App Service.

We have found the following method:

public static Task RestartAsync(
  this IWebAppsOperations operations, 
  string resourceGroupName, 
  string name, 
  bool? softRestart = null, 
  bool? synchronous = null, 
  CancellationToken cancellationToken = default
);

Under the Microsoft.Azure.Management.AppService.Fluent namespaces WebAppsOperationsExtensions class, and similar methods in the non-Fluent ARM library. However, these only allow us to restart the entire App Service. We want to minimise disruption and only target a specific instance with the restart.

Is there a mechanism through either a .NET library, or a REST API (where we would build the request ourselves) which will allow us to restart a single App Service instance?

1
"We've identified that restarting that specific instance via Advanced Diagnostics brings the instance back up." Can you clarify what "Advanced Diagnostics" refers to?nlawalker
@nlawalker: Azure portal > open app service resource > Diagnose and solve problems > Advanced Application Restart is the page we used to restart the single instanceElFik
Got it. The implementation of that in the portal is in fact using using the strategy that Tamas Huj lays out in his answer. It uses a couple REST calls to enumerate the instances and find the w3wp processes on each instance, then shows them in the UI. Requesting a restart on one of them uses a DELETE to kill the process.nlawalker

1 Answers

1
votes

In an MSDN blog post, it says:

The Azure PowerShell cmdlets for WebApp allow you to restart a WebApp or a WebApp slot. They do not however allow to restart an instance within the WebApp

There is a PowerShell script in it, though, which restarts all instances with some delay.

Also, if you check the Azure REST API, there are two methods to kill a process on an instance. I think it should be good enough for you to just kill the w3wp.exe process on that specific intance:

Like this:

DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/slots/{slot}/instances/{instanceId}/processes/{processId}?api-version=2016-08-01