如何在一定时间后自动重启应用服务? [英] How to automatically restart an app service after certain time?
问题描述
如何在 24 小时后自动重启应用服务?如何通过 web 作业来安排应用服务在特定时间自动重启?
How to automatically restart an app service after 24 hours? How to schedule the app service to restart automatically at a specific time through the use of web jobs?
推荐答案
您可以通过创建 Web 作业并放置 PowerShell 脚本来停止和启动 Web 应用程序来实现此目的.
You can achieve this by creating a web job and placing a PowerShell script to stop and start the web app.
要执行 Azure 应用服务的启动/停止操作,Web 作业应有权访问您的订阅.它还需要您的 Azure 配置文件.
To perform start/stop operation of Azure App Service, the web job should have access to your subscription. It also requires your Azure profile.
Login-AzureRmAccount
Save-AzureRmProfile -Path "E:azureprofile.json"
创建 PowerShell 以停止/启动应用服务
创建一个新文件夹并将下载的发布配置文件放入上一步.
Create a new folder and place the publish profile downloaded in previous step.
创建一个 PowerShell 并保存为 run.ps1
Create a PowerShell and save as run.ps1
$ProgressPreference= "SilentlyContinue"
Select-AzureRmProfile -Path "azureprofile.json"
Select-AzureRmSubscription -SubscriptionId '<subscriptionId>'
Stop-AzureRmWebApp -Name '<AppService-Name>' -ResourceGroupName '<Resource-Group-Name>'
Start-AzureRmWebApp -Name '<AppService-Name>' -ResourceGroupName '<Resource-Group-Name>'
将此添加到您的应用服务 Web 作业部分并通过创建 cron 表达式根据您的要求运行.
Add this in your App service web job section and run based on your requirement by creating a cron expression.
参考:Azure 应用服务:使用 Web 作业自动重启应用程序
这篇关于如何在一定时间后自动重启应用服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!