Restart Azure Web App Using Azure Logic App in 6 Steps

restart azure web app using azure logic app with azure cloud platform logo
Ajay Thakor
07-Mar-2023
Reading Time: 5 minutes

In this article, we’ll look at how to restart Azure web app using Azure logic App.

There is undoubtedly a lot of discussion in Azure about how to perform specific tasks automatically, such as restarting an application when an error threshold is surpassed. To configure this, there isn’t a lot of easily available information, and even less if you wish to use Managed Identities.

Let’s examine this case and go over how to make an auto-restarting feature for your application. As the trigger might be anything, this will concentrate on the restart process itself. I’ll describe how to queue the trigger, but you’ll have to determine the timing yourself.

There are numerous approaches for restarting a web application on Azure. PowerShell might be used with a Logic App, a custom function hitting a REST endpoint, or an Automation account. We will concentrate on using a Logic App out of simplicity.

What is Logic App?

The Azure Logic Apps is a component of Azure App Service, It aims to use code-free automation to access and use data across clouds. Azure Logic Apps is priced on a per-execution basis. All the Logic App Connectors that are available to support integration and orchestration across products are one of its key selling factors.

Basically, the purpose of Azure Logic Apps is to orchestrate business processes and system integration based on user-defined workflows. We only need an HTTP trigger for this reason, which will call the Web Applications Restart endpoint. That seems simple, and amazingly, it is.

Prerequisites

For creating a Logic App which will restart the Azure function app, you need the following items and access.

  • Azure portal access where Azure web App is deployed.
  • Tenant Id of your azure account
  • Client_id
  • Client_secret
  • Azure Subscription ID
  • Resource Group
  • App name

We will need to follow a few easy steps to restart the function app using the logic app. Let’s break down each step individually.

Restart Azure Web App using Azure Logic App in Step-by-Step Guide

Here are 6 simple steps to set automated logic app for restart web app in azure:

Step #1: Create Logic App:

To create logic app, after login in azure portal, and search the “Logic Apps” in the search box and select the logic app.

Search the Logic Apps in Microsoft Azure and select the logic app.

After navigating on the Logic apps section, add a new logic app. Create the logic app in a similar screen as:

Add and create new logic app

Fill details of a logic app like name, its resource group , location etc. and click on create a button. (select plan according to your needs)

The system will open the logic app designer window on which you will see a list of templates to build workflows quickly or we can create it from a blank.

Select Blank App to start with a new template:

Select blank section in logic app designer

Step #2: Schedule Time:

The first thing that needs to be defined is what will be the trigger to the Logic App or What time will be trigger the logic app. For this search for Recurrence and select request:

Select trigger section and set Recurrence schedule

After selecting recurrence, you can schedule time as per your need, I am selecting every day 5:00 pm, this logic app will be triggered. Set details as below:

Fill Details to set Recurrence

Step #3: Get Access Token (HTTP)

After this select the “+ new step” button as we will want to then call our REST API endpoint to get access token.

We need to add the HTTP action in-order to generate and get the access token. This action is having a post method and requires tenant_id, client_id, client_secret.

This action is having a post method and requires tenant_id, client_id, client_secret.
1."method": "POST"  
2."uri": "https://login.microsoftonline.com/{tenant_id}/oauth2/token"  
3."body": "grant_type=client_credentials&client_id={client_id} &client_secret{client_secret}&resource=https://management.core.windows.net/"  
4."Content-Type": "application/x-www-form-urlencoded"

In http section, fill details like Url, headers, queries and body

After setting all the credentials, Let’s trigger the app. After execution, we will get a JSON result containing an access token value, which is required to restart the app.

A JSON result containing an access token value, which is required to restart the app.

The JSON result looks like as below:

JSON Result Restart Azure Web App Using Azure Logic App in 6 Steps

Step #4: Parse JSON

To generate the schema, parse the JSON and get the body, then define the schema using the sample payload.

Add the JSON body which you have get in above step to generate the schema dynamically, for that click on the “Use sample payload to generate schema”.

Add the JSON body which you have get in above step to generate the schema dynamically

Step #5: Restart App (HTTP)

We require the subscription ID, resource group, and app name of the Azure web app for this HTTP request. The access token from the previous step needs to be passed into the Authorization field.

1."method": "POST"  
2."uri": "https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Web/sites/{webApp_name}/restart?api-version=2016-08-01"  
3."Authorization": "Bearer @{body('Parse_JSON')?['access_token']}",  
"Content-Type": "application/json"
The access token from the previous step needs to be passed into the Authorization field.

Now, our Logic App steps will look like this:

Steps of Logic App

Step #6: Run Logic App

Your logic app is now complete, and you can run it to see the results in history.

Completed steps of Logic App

The Activity Log of Web App

Check the Webapp Activity Log. You might need to wait for 1-2 mins in-order to update this.

webApp activity log updating

The Logic app was properly configured and performed as expected. It is restarting the Azure web app, which we can configure and schedule on demand.

Summary:

In the above article, we saw how to Restart the Azure Web App using the Logic App.

Moreover, if you’re dealing with enterprise cloud software or large-scale cloud applications, you may wish to seek professional assistance. For an expert helping hand, Get in touch with our Microsoft Azure consulting services experts having a minimum of 8+ years of experience working on Azure IoT, Cloud Integration & Migration, DevOps, Analytics and many more Azure services.