How to automatically restart an app service after certain time?

前端 未结 4 1318
时光说笑
时光说笑 2021-01-19 00:56

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?

4条回答
  •  半阙折子戏
    2021-01-19 01:39

    You can achieve this by creating a web job and placing a PowerShell script to stop and start the web app.

    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"
    

    To Create PowerShell to stop/start App Service

    Create a new folder and place the publish profile downloaded in previous step.

    Create a PowerShell and save as run.ps1

    $ProgressPreference= "SilentlyContinue"
    Select-AzureRmProfile -Path "azureprofile.json"
    Select-AzureRmSubscription -SubscriptionId ''
    Stop-AzureRmWebApp -Name '' -ResourceGroupName ''
    Start-AzureRmWebApp -Name '' -ResourceGroupName ''
    

    Add this in your App service web job section and run based on your requirement by creating a cron expression.

    Reference: Azure App Services: Automate Application restart using Web Job

提交回复
热议问题