{{announcement.body}}
{{announcement.title}}

Restart Azure Web App Using Azure Logic App

DZone 's Guide to

Restart Azure Web App Using Azure Logic App

Learn how you easy it can be to trigger the Azure Logic app to restart the Azure web app.

· Cloud Zone ·
Free Resource

restart pillows

Sometimes you have to begin again.

Introduction

In this article, we are going to see how to restart the Azure web app using Azure Logic App. I am assuming that you know about Azure Logic Apps. If you want to read more about Azure Logic Apps, check out this article.

You may also enjoy:  Introducing Azure Logic Apps Integration Service Environment (ISE)

Prerequisites

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

  1. Azure portal access where Azure web App is deployed.
  2. Tenant Id of your azure account
  3. Client_id
  4. Client_secret
  5. Azure Subscription Id
  6. Resource Group
  7. App name

Steps

Restarting of Azure web app using Azure logic app will have three simple steps, as shown below.

Three steps

Three steps to restarting Azure web app

We will discuss, figure 1 steps in detail in the following section.

Start Designing of the Azure Logic App

Step 1 - Get Access Token (HTTP)

Firstly, 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.

"method": "POST"

"uri": "https://login.microsoftonline.com/{tenant_id}/oauth2/token"
"body": "&client_id={client_id} &client_secret{client_secret}&://management.core.windows.net/"

"Content-Type": "application/x-www-form-urlencoded"

Get HTTP Access Token

Get HTTP Access Token


Figure 2

After execution, we will get a JSON result which will have an access_token value which is required to restart the app.

JSON result looks like as below:

JSON result

JSON result

Step 2: Parse JSON

Parse the JSON and get the body and define the schema using the sample payload to generate the schema.

Parsing JSON

Parsing JSON

Step 3 - Restart App (HTTP)

For this HTTP request, we need a subscription ID, resource group, and app name of the Azure web app. We need to pass the access_token  from the previous step in the Authorization field.

"method": "POST"

"uri": "https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Web/sites/{webApp_name}/restart?-08-01"
"Authorization": "Bearer @{body('Parse_JSON')?['access_token']}",

"Content-Type": "application/json"

Restarting application

Restarting the application

Run Logic App

Your Logic app is ready and now run this and see the results in history.

Three steps

Three steps

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.

Activity Log

Activity log

Expected Result

The Logic app is configured properly and worked as per expected. It is restarting the Azure web app, and we can configure this on-demand and schedule it. For on-demand, we can use email receiving event and restart it on receiving an email with a specific subject line. This process is presented below.

Automate the Logic App on Receiving an Email

To automate this process, we can configure the above Logic app to receive an email with some defined text in the subject. Now, whenever you will receive an email with a defined subject then the Logic app will run automatically.

Running app

Summary

In the above article, we saw how to restart the Azure web app using the logic app. We also saw how to use email receiving an event to restart the app. Apart from the restart, we can perform many more operations like stop, start, etc. For more triggered APIs, refer to the below URL and configure those in the above logic app accordingly.

Further Reading

Is Logic Apps or Durable Functions Best for Your Workflow?

Azure Logic Apps (With Demo Using YouTube and Outlook.com Connectors)

Topics:
azure ,azure web sites ,azure logic application ,cloud ,automation

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}