@NIKHIL KUMAR The quickest and simplest way to achieve this would be to create a logic app with a recurrence trigger and call the Web Apps - Restart ARM REST API from it using the Invoke Resource Operation action.
Restart function App with automated process
What would be best approach to restart a function App automatically using scheduled process.
5 answers
Sort by: Most helpful
-
-
Dillon Silzer 45,871 Reputation points
2023-09-06T16:21:42.2866667+00:00 Here is a nice guide for using Azure Logic App:
Create Azure Logic App to Restart Azure Function App
https://helicaltech.com/create-azure-logic-app-to-restart-azure-function-app
If this is helpful please accept answer.
-
NIKHIL KUMAR 81 Reputation points
2023-09-11T07:14:35.4566667+00:00 Thank you @Dillon Silzer @Pramod Valavala
I am getting below error, is there any specific access required. There's already Contributor access to logic app assigned for app service plan.
The client 'xxxxxx' with object id 'xxxxx' does not have authorization to perform action 'Microsoft.Web/sites/2022-09-01/action' over scope '/subscriptions/xxxx/resourcegroups/xxxx/providers/Microsoft.Web/sites/xxxxx' or the scope is invalid. If access was recently granted, please refresh your credentials
-
TP 44,776 Reputation points
2023-09-11T07:45:45.99+00:00 Hi Nikhil,
An Azure Automation Runbook will work well for this. It only takes a minute to set up, however, if you've never used it before and are thus unfamiliar, figure more like 10-15 minutes to slowly walk through each step. Basic steps to set it up below.
Create Automation Account (you can skip this if you already have one):
https://portal.azure.com/#create/Microsoft.AutomationAccount
Give it resource group and name and accept defaults for the rest.
Assign Role to Managed Identity
Navigate to your Function App -- Access control (IAM) blade. Click Add role assignment, select Website Contributor, Next, click Select members, type the first several characters of your automation account name until you see it in the list, click on it, click Select button, Next, click Review + assign.
Create Runbook
In your automation account -- Process Automation -- Runbooks blade, click Create a runbook. Give it a Name, Runbook type: PowerShell, Runtime version: 5.1, click Create. In the editor pane on right, paste in code similar to below sample (don't forget to update with your resource group and functionapp names):
Connect-AzAccount -Identity Restart-AzFunctionApp -ResourceGroupName MyResourceGroupName -Name MyFunctionAppName -Force
Click Publish. Alternatively you may click Test pane, run a test, close the test pane, then Publish.
Click Resources -- Schedules blade. Click Add a schedule, Link a schedule to your runbook, Add a schedule. Give it a Name, set the time you want it to run each day, click Recurring, change the dropdown to Day, click Create. If you don't want it to restart once every day then modify to suite your needs.
Please review pricing for Azure Automation. In your case you should fall within the free included units since the restarts shouldn't take up much run time.
Automation pricing
https://azure.microsoft.com/en-us/pricing/details/automation/
Please click Accept Answer if the above was useful. If something is unclear please add a comment below.
Thanks.
-TP
-
NIKHIL KUMAR 81 Reputation points
2023-09-11T09:27:37.9233333+00:00 Thank you @Pramod Valavala @Dillon Silzer
I am getting below error, is there any specific access required. There's already Contributor access to logic app assigned for app service plan.
The client 'xxxxxx' with object id 'xxxxx' does not have authorization to perform action 'Microsoft.Web/sites/2022-09-01/action' over scope '/subscriptions/xxxx/resourcegroups/xxxx/providers/Microsoft.Web/sites/xxxxx' or the scope is invalid. If access was recently granted, please refresh your credentials