Recently I had an issue with one of the web sites I was supporting and it seemed to be falling over each night and it was difficult to work out what was wrong. Whilst I was working it out I need a mechanism to restart the website over night so that I could then take the time to figure out exactly what was wrong. There were a number of ways to achieve this but the simplest one for me was to use an Azure DevOps Release pipeline triggered on a schedule. The Azure DevOps “Azure App Service Manage” task allows me to achieve this.
To get started create a new release pipeline with an Empty job
Click on the “1 job, 0 task” link and then click on the “+” in Agent Job.
Enter “App service” in the search box and select “Azure App Service Manage” from the list of tasks that appear and click “Add”.
The task will default to Swap Slots but you can change this. Select your Azure Subscription and click “Authorize” if you haven’t already authorised your Azure Subscription.
Clicking “Authorize” will take you through the sign in process where you will need to enter your username and password for the Azure subscription that contains your app service. Once authorised select the Action you want to perform. Currently the list contains:
Select “Restart App Service” then pick your app service from the “App Service name” list, Also change the display name as it defaults to “Swap Slots:”
Your pipeline is now configured to restart your app service.
You now need to trigger this. Click on the pipeline tab
Then click on the Schedule button
Enable the trigger and select your desired schedule, edit the release pipelines title and click save. Your web site will now restart based upon the schedule you picked.
You can restart multiple web apps with a single release pipeline
You are able to chain each website or do it in parallel by changing the pre-deployment conditions:
To chain them select “after stage” and in parallel select “after release” for each stage.
When the schedule is run a new release is created and the web apps will restart and you will be able to see the status of each attempt in the same way you do with your standard releases.
It’s been a while since I’ve talked about web jobs, but they are still around.I needed to modify one of mine recently and configure it as a scheduled web job.
You can deploy your web job from the Azure Portal. Web jobs are part of App Services and are deployed by selecting your app service you want and clicking the web jobs service.
Click the Add button.
Enter a name for your web job, Browse a zip or exe containing your web job
Select Triggered from the Type drop down. This change the UI to allow you to select Scheduled
The Schedule is triggered using a CRON expression.
Alternatively, configure the web job as a manual trigger, then use the Azure Scheduler to trigger the web job.. When you have configured your web job, click on its properties in the Azure Portal and you should see a web hook url.
Now create a new scheduler Job
Select the method as Post and paste in the webhook url.Once you've completed this configuration you can then configure the schedule
Using the scheduler allows you to configure retry policies and also error actions