How to programmatically restart an instance of an App Service in Azure

Chakaravarthi Rangarajan Bhargavi 1,115 Reputation points MVP
2023-09-14T01:43:58.3033333+00:00

Is there a way to restart an instance of an Azure App Service programmatically? Additionally, how does Azure handle unresponsive instances within a scaled-out App Service with 10 instances? Is there a feature or mechanism, such as a Health Check, that allows for automatic identification and recovery of unresponsive instances, including notification to administrators about the affected instance? If Azure replaces the unresponsive instance, how does this process work?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,971 questions
{count} votes

Accepted answer
  1. AirGordon 7,150 Reputation points
    2023-09-14T07:14:26.6366667+00:00

    You can leverage the Azure CLI to restart the web app : https://learn.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest#az-webapp-restart

    az webapp restart --name MyWebapp --resource-group MyResourceGroup

    Health Check is a feature;

    The Health Check feature allows you to specify a path on your application for App Service to ping. If an instance fails to respond to the ping, the system determines it is unhealthy and removes it from the load balancer rotation. This increases your application’s average availability and resiliency.

    ref: https://azure.github.io/AppService/2020/08/24/healthcheck-on-app-service.html

    I'd suggest that you wouldn't want to alert administrators when an instance is replaced, as a PaaS - I would focus on the availability of your endpoint rather than the instances that comprise the service. However, as part of troubleshooting if you do experience degraded performance with the web app then i would leverage the Metrics and Logs which would allow you to view instance specific issues.


1 additional answer

Sort by: Most helpful
  1. Janarthanan S 700 Reputation points
    2023-09-15T07:20:36.2166667+00:00

    Hi @Chakaravarthi Rangarajan Bhargavi ,

    In order to enable the health check of an app service instances from the Azure Portal.

    Please find steps below,

    App Service -> Monitoring -> Health Service and you have to provide a health probe path URL. This url has to specify to which endpoint you are trying to ping.

    Then it will ping to that specific endpoint at regular intervals.

    If the URL returns an error HTTP status code or fails to respond, the instance is identified as unhealthy and removed from the Load Balancer rotation.

    If you are looking for detailed explanation please follow the blog given below.

    https://dotnetthoughts.net/azure-app-service-enable-health-check/

    If an instance remains unhealthy for one hour, it will be replaced with a new instance.

    Enable Health Check in Azure App Service

    You can also verify health check by going to Metrics page from the health check blade. This will redirect to the health status page and provide the ability to add a new alert rule too.

    Azure Alert configuration

    If you have deployed the web app from local to Azure App service then easiest way to check the health check path URL is to visit the Resource Explorer (azure.com) link. This article provides detailed steps for accessing the web app config file.

    enter image description here

    Hope the answer is useful to you and thanks for the great question.

    Regards,

    Janarthanan S

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.