如何按计划重新启动 Azure Web App

kkm*_*021 6 azure azure-webjobs azure-web-app-service

我想每天 06:00 重新启动我的 Azure Web 应用程序。

\n\n

我从Azure 应用服务中找到了参考:使用 Web 作业自动重新启动应用程序

\n\n

但是,这篇文章有一些错误。

\n\n
    \n
  • 保存-AzureProfile => 保存-AzureRmContext
  • \n
  • 选择-AzureRmProfile => 导入-AzureRmContext
  • \n
\n\n

解决这个问题后,在本地运行就完美了。

\n\n

当我在 Azure Web 应用程序上创建 Web 作业时,出现错误

\n\n

无效操作

\n\n

看起来不支持 Stop-AzureRmWebApp

\n\n

有没有解决办法\xef\xbc\x9f

\n

Amo*_*mor 0

我在我这边测试了一下。blob 提供的 PowerShell 代码在我这边运行良好。这是我所做的详细步骤。

步骤 1. 创建一个名为 TestRestartWebApp 的文件夹。步骤 2. 生成配置文件到该文件夹​​。

Save-AzureRmProfile -Path "D:\TestRestartWebApp\azureprofile.json"
Run Code Online (Sandbox Code Playgroud)

步骤 3. 在该文件夹中创建一个名为 run.ps1 的 PS 文件。

在此输入图像描述

步骤 4. 以下是我放入 run.ps1 中的代码。

$ProgressPreference= "SilentlyContinue"
Select-AzureRmProfile -Path "azureprofile.json"
Select-AzureRmSubscription -SubscriptionId 'my subscription id'
Stop-AzureRmWebApp -Name 'my web app name' -ResourceGroupName 'my resource group name'
Run Code Online (Sandbox Code Playgroud)

步骤 5. 压缩此文件夹并使用压缩文件创建 WebJob。

完成上面的步骤后,我可以在 WebJob 仪表板中看到日志。Web 应用程序已停止。

在此输入图像描述

请仔细检查你的步骤,你的和我的有什么不同吗?您是否在 run.ps1 文件中设置了正确的配置文件路径。