Click here to Skip to main content
14,365,629 members

Restart Azure Web App Using Azure Logic App

Rate this:
5.00 (1 vote)
Please Sign up or sign in to vote.
5.00 (1 vote)
23 Oct 2019Public Domain
How to migrate Azure WebJobs from Azure Scheduler to Azure Logic Apps

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 App and how it works, then refer to this link.

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 the Azure logic app will have three simple steps, as shown below:

Three steps to restarting Azure web app

Figure 1

In the following sections, we will discuss in details the steps shown in figure 1.

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 has a post method and requires tenant_id, client_id, client_secret.

"method": "POST"  

"uri": "https://login.microsoftonline.com/{tenant_id}/oauth2/token"  

"body": "grant_type=client_credentials&client_id={client_id} 
     &client_secret{client_secret}&resource=https://management.core.windows.net/"  

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

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 below:

JSON result

Figure 3

Step 2 - Parse JSON

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

Parsing JSON

Figure 4

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?api-version=2016-08-01"  

"Authorization": "Bearer @{body('Parse_JSON')?['access_token']}",  

"Content-Type": "application/json"  

Restarting the application

Figure 5

Run Logic App

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

Three steps

Figure 6

The Activity Log of Web App

Check the webApp activity log. You might need to wait for 1-2 minutes in order to update this.

Activity log

Figure 7

Expected Result

The Logic app has configured properly and worked as 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 events and restart it on receiving an email with a specific subject line. This is as given below.

Automate the Logic App on Receiving an Email

To automate this process, we can configure the above logic app on receiving 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

Figure 8

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.

History

  • 23rd October, 2019: Initial version

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

Share

About the Author

Harsh Deep Gupta
Software Developer (Senior)
India India
7+ years of experience and expertise in the diverse areas of Microsoft Technologies. He is working as a development lead in Vineforce IT Services Pvt. Ltd.

Comments and Discussions

 
-- There are no messages in this forum --
Tip/Trick
Posted 23 Oct 2019

Tagged as

Stats

994 views
6 downloads
1 bookmarked