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.
- Create a logic app and add whatever trigger you need. (I used a recurrence based trigger, but you could use a HTTP request, etc).
- 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.
- You will need to fill in the following parameters and here is how to find them:
- Subscription: This should be available in the drop-down. Else, its your subscription Id.
- Resource Group: The resource group in which your web-app resides
- 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. - 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" - 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. - 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".
- Final result will look like this:
- Test it out by clicking run.
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"}
Hi Raj,
ReplyDeleteThank 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!
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.
ReplyDeleteYou sir, are a King!
ReplyDeleteThanks for this!
ReplyDelete