Tuesday, January 07, 2020

Restarting a web-app using Logic Apps

Unfortunately its not straight forward and the help wasnt very helpful. So here are the steps and the pages I had to look up for getting the data.
  1. Create a logic app and add whatever trigger you need. (I used a recurrence based trigger, but you could use a HTTP request, etc).
  2.  Add a new step and then look for Azure Resource Manager. Once you click on it, search for "Invoke" and pick the "Invoke Resource Operation" action.
  3. You will need to fill in the following parameters and here is how to find them:
  4. Subscription: This should be available in the drop-down. Else, its your subscription Id.
  5. Resource Group: The resource group in which your web-app resides
  6. Resource Provider: Microsoft.Web
    This I figured out from this page: Resource providers for Azure services
    Microsoft.Web because I needed to manage an App Service.
  7. Short Resource Id: this I figured out by going to the "Properties" section of my App Service and its the in the "ResourceId".

    The value will end up being something like "sites/xxxxxxx"
  8. Action Name: Lets look at this param before the ClientAPIVersion.
    The function we want to invoke is "Restart" which I found via the REST API documentation pages: https://docs.microsoft.com/en-us/rest/api/appservice/webapps
    Restart: https://docs.microsoft.com/en-us/rest/api/appservice/webapps/restart
    You can check out all the other parameters that one could provide. In this case, we dont need any additional parameters.
  9. Client Api Version: This is date value and you can get it from the Restart API documenation page. Its called "API Version" and can be found at the top of the page. In my case, as of writing of this post the value was "2019-08-01".
  10. Final result will look like this:
  11. Test it out by clicking run.

    1. If it ran successfully, you should see a screen that looks like this
    2. You should also check the activity log of the web-app to see if it did restart.

Restarting a redis cache

To restart a redis cache, here are the parameters you need for the Invoke operation:

Subscription: subscription in which the resource resides
Resource Group: resource group in which the resource resides.
Resource Provider: Microsoft.Cache
Short Resource Id: Redis/NameOfCacheInstance (can be found under properties of your cache instance)
Client API Version: 2016-04-01 (as of the writing of this post)
Action Name: forceReboot
Request Body: {"rebootType":"AllNodes"}

4 comments:

  1. Hi Raj,

    Thank you for the post. I found it very helpful. I have a WCF webapp hosted on Azure that hangs once in a while. I seem to need to restart about once every 3 to 6 weeks. For now I am just going to reset it at 2:30 am everyday. Eventually I will figure out what is causing the WCF to hang and stop accepting requests. But for now this is a perfect work around!

    ReplyDelete
  2. This was an awesome article. We setup an alert action group that ran a logic app that did this - which based on a 5xx from the website, would restart the app service. EXCELLENT. And thanks.

    ReplyDelete

Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.