4
votes

We have an Azure app service (website) which has an additional deployment slot called offline that we want to use when we have taken the main website offline for maintenance.

I am trying to write a PowerShell script that will switch between this offline slot and the production slot, or vice versa, depending on parameters passed to the script. However, the script must also perform additional actions when the switchover happens, hence it is important to know which slot is currently "active".

The problem is that I can't find a way of determining this. I'm using the Resource Manager cmdlets (*-AzureRm*), and although I can call:

Get-AzureRmWebAppSlot -ResourceGroupName xxx -Name websitename -Slot offline

the object that this returns has nothing in it that can help me, as far as I can tell. It's the same story for the object returned by Get-AzureRmWebApp.

As there doesn't seem to be a Resource Manager cmdlet for this, are there any other techniques I can use? All I can think of at the moment is to have a particular web page that only exists on the offline site, and check for the existence of that page by querying the live website: this should tell me which slot is currently live. This seems kind of hacky though.

1
Either I'm not totally clear about this or possibly way out of line but isnt websitename-production (having -procuction as suffix) always the "active" one?JFM
If the web app was called foo and there was a single slot called offline then there would be two domains: foo.azurewebsites.net and foo-offline.azurewebsites.net. When the two slots are swapped, the domains remain the same but their content is switched around, ie. accessing foo.azurewebsites.net would show the content that was previously in foo-offline.azurewebsites.net, and vice versa. AFAIK there is no such thing as foo-production.azurewebsites.net (indeed, that will give a 404 Host Not Found error).Steven Rands
What I'm trying to get at is that, yes, foo.azurewebsites.net is always the "active" site in the sense that it is the domain that you advertise to your users (although you'd probably use a custom domain for public sites). That site is always there, and always available via the same URL. However, I need to be able to determine programmatically (via PowerShell) what content is currently deployed to that domain. In other words, if I went to foo.azurewebsites.net right now, would I get the live site content, or the offline site content.Steven Rands

1 Answers

2
votes

You could setup a non-slot-specific app setting that identifies the app. That would be swapped along with the app when doing the swap.

E.g. set an app setting with key AppVersion and value Production on the production slot, and an app setting with the same key and value Offline on the offline slot.

You can get access to app settings with PowerShell like this:

(Get-AzureRmWebApp -ResourceGroupName your-resource-group -Name your-webapp).SiteConfig.AppSettings