<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RuslanY Blog</title>
	<atom:link href="https://ruslany.net/feed/" rel="self" type="application/rss+xml" />
	<link>https://ruslany.net/</link>
	<description>Azure App Service Features and Best Practices</description>
	<lastBuildDate>Fri, 31 Jan 2020 19:31:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.9</generator>

<image>
	<url>https://ruslany.net/wp-content/uploads/2019/05/cropped-web-32x32.png</url>
	<title>RuslanY Blog</title>
	<link>https://ruslany.net/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to monitor Azure App Service content changes and publishing activity</title>
		<link>https://ruslany.net/2020/01/how-to-monitor-azure-app-service-content-changes-and-publishing-activity/</link>
					<comments>https://ruslany.net/2020/01/how-to-monitor-azure-app-service-content-changes-and-publishing-activity/#respond</comments>
		
		<dc:creator><![CDATA[Ruslan]]></dc:creator>
		<pubDate>Mon, 13 Jan 2020 23:08:58 +0000</pubDate>
				<category><![CDATA[Azure App Service]]></category>
		<category><![CDATA[App Service]]></category>
		<category><![CDATA[Azure Monitor]]></category>
		<category><![CDATA[Azure Websites]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<guid isPermaLink="false">https://ruslany.net/?p=424476</guid>

					<description><![CDATA[<p>There are various ways to deploy an Azure App Service content: FTP, GitHub actions, deploy from Zip and many others. With Azure Role-Based Access Control it is possible to have many different users with contributor access who can deploy new content or modify existing files. In those situations it may be important to track who &#8230; <a href="https://ruslany.net/2020/01/how-to-monitor-azure-app-service-content-changes-and-publishing-activity/" class="more-link">Continue reading<span class="screen-reader-text"> "How to monitor Azure App Service content changes and publishing activity"</span></a></p>
<p>The post <a href="https://ruslany.net/2020/01/how-to-monitor-azure-app-service-content-changes-and-publishing-activity/">How to monitor Azure App Service content changes and publishing activity</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>There are various ways to deploy an Azure App Service content: FTP, GitHub actions, deploy from Zip and <a rel="noreferrer noopener" aria-label="many others (opens in a new tab)" href="https://docs.microsoft.com/en-us/azure/app-service/deploy-zip" target="_blank">many others</a>. With Azure Role-Based Access Control it is possible to have many different users with contributor access who can deploy new content or modify existing files. In those situations it may be important to track who made the content changes and when. Some companies or businesses may need this capability for various compliance requirements. This blog post explains how to enable the monitoring of app service content publishing activity and content file changes.</p>



<p>Azure App Service is integrated with <a rel="noreferrer noopener" aria-label="Azure Monitor (opens in a new tab)" href="https://azure.github.io/AppService/2019/11/01/App-Service-Integration-with-Azure-Monitor.html" target="_blank">Azure Monitor</a> which makes many app service logs available in Azure Monitor and <a rel="noreferrer noopener" aria-label="Azure Log Analytics (opens in a new tab)" href="https://docs.microsoft.com/en-us/azure/azure-monitor/log-query/get-started-portal" target="_blank">Azure Log Analytics</a>. The publishing activity and file change logs are also pushed to Azure Monitor and can be exported to third party services or can be used to create rule-based alerts.</p>



<p>Here are the configuration steps necessary to enable publishing activity and file change logging.</p>



<span id="more-424476"></span>



<h3 class="wp-block-heading">Create a new Log Analytics workspace</h3>



<blockquote class="wp-block-quote"><p>Note that this step can be omitted if you do not plan to use Log Analytics to query the logs and instead just want to make the logs available to third party log processing services.</p></blockquote>



<p>Make sure that the workspace is created in the same region where you app service is located.</p>



<figure class="wp-block-image size-large"><img decoding="async" width="403" height="457" src="https://ruslany.net/wp-content/uploads/2020/01/2020-01-13_12h48_05.png" alt="" class="wp-image-424480" srcset="https://ruslany.net/wp-content/uploads/2020/01/2020-01-13_12h48_05.png 403w, https://ruslany.net/wp-content/uploads/2020/01/2020-01-13_12h48_05-265x300.png 265w" sizes="(max-width: 403px) 85vw, 403px" /><figcaption>Create new Log Analytics workspace</figcaption></figure>



<h3 class="wp-block-heading">Configure Azure Monitor diagnostic settings</h3>



<p>In the Azure Portal select the App Service and then select the diagnostic settings:</p>



<figure class="wp-block-image size-large"><img decoding="async" loading="lazy" width="232" height="225" src="https://ruslany.net/wp-content/uploads/2020/01/DiagnosticSettings.png" alt="" class="wp-image-424484"/><figcaption>App Service diagnostic settings</figcaption></figure>



<p>Select +Add diagnostic setting:</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" loading="lazy" src="https://ruslany.net/wp-content/uploads/2020/01/AddDiagnosticSettings.png" alt="" class="wp-image-424485" width="449" height="238" srcset="https://ruslany.net/wp-content/uploads/2020/01/AddDiagnosticSettings.png 599w, https://ruslany.net/wp-content/uploads/2020/01/AddDiagnosticSettings-300x159.png 300w" sizes="(max-width: 449px) 85vw, 449px" /><figcaption>Add diagnostic setting</figcaption></figure>



<p>On next page you can specify what logs you need and where you need those logs to be sent to. Select the following logs:</p>



<ul><li><strong>AppServiceFileAuditLogs </strong>&#8211; this will generate logs for app service content files changes;</li><li><strong>AppServiceAuditLogs </strong>&#8211; this will generate logs for publishing access, for example when somebody logs on via FTP.</li></ul>



<p>Then select where you need those logs to be sent to. For example you can send them to a storage account of your choice and to a Log Analytics workspace that you created in a previous step. Note that the storage account has to be in the same region as the app service.</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" loading="lazy" src="https://ruslany.net/wp-content/uploads/2020/01/ConfigureDiagnosticsSetting.png" alt="" class="wp-image-424487" width="486" height="600" srcset="https://ruslany.net/wp-content/uploads/2020/01/ConfigureDiagnosticsSetting.png 648w, https://ruslany.net/wp-content/uploads/2020/01/ConfigureDiagnosticsSetting-243x300.png 243w" sizes="(max-width: 486px) 85vw, 486px" /><figcaption>Configure logs for Azure Monitor</figcaption></figure>



<h3 class="wp-block-heading">Scale the App Service Plan to PremiumV2 or Premium</h3>



<p>The file change audit logs (<strong>AppServiceFileAuditLogs</strong>) are only available for app services in Premium, PremiumV2 and Isolated App Service Plans. You will need to scale up the app service plan in order to get those logs.</p>



<p>The publishing audit logs (<strong>AppServiceAuditLogs</strong>) are available for all App Service Plan pricing tiers.</p>



<h3 class="wp-block-heading">Enable File Change Audit for the App Service</h3>



<p>The last step is to switch on the File Change Audit configuration setting for the web app. At the time of writing this article there is no Portal support or client libraries for this setting yet so the easiest way to do this is via <a href="https://resources.azure.com/" target="_blank" rel="noreferrer noopener" aria-label="Azure Resource Explorer (opens in a new tab)">Azure Resource Explorer</a>:</p>



<figure class="wp-block-image size-large is-resized"><a href="https://ruslany.net/wp-content/uploads/2020/01/FileChangeAuditEnabled.png"><img decoding="async" loading="lazy" src="https://ruslany.net/wp-content/uploads/2020/01/FileChangeAuditEnabled.png" alt="" class="wp-image-424493" width="443" height="213" srcset="https://ruslany.net/wp-content/uploads/2020/01/FileChangeAuditEnabled.png 886w, https://ruslany.net/wp-content/uploads/2020/01/FileChangeAuditEnabled-300x144.png 300w, https://ruslany.net/wp-content/uploads/2020/01/FileChangeAuditEnabled-768x368.png 768w" sizes="(max-width: 443px) 85vw, 443px" /></a><figcaption>Enable file change audit in Azure Resource Explorer</figcaption></figure>



<h3 class="wp-block-heading">How to access the logs</h3>



<p>If you enabled sending of the logs to a storage account then you should see the <em>insights-logs-appserviceauditlogs </em>and <em>insights-logs-appservicefileauditlogs</em> containers in that storage account:</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" loading="lazy" src="https://ruslany.net/wp-content/uploads/2020/01/AzMonStorage.png" alt="" class="wp-image-424498" width="524" height="206" srcset="https://ruslany.net/wp-content/uploads/2020/01/AzMonStorage.png 698w, https://ruslany.net/wp-content/uploads/2020/01/AzMonStorage-300x118.png 300w" sizes="(max-width: 524px) 85vw, 524px" /><figcaption>Log containers in the storage account</figcaption></figure>



<p>If you enabled sending of the logs to the Log Analytics workspace then open that workspace and go to the Logs page. That will open the query window where you can write the queries against the AppServiceFileChangeAuditLogs:</p>



<figure class="wp-block-image size-large is-resized"><a href="https://ruslany.net/wp-content/uploads/2020/01/LogAnalyticsExample.png" target="_blank" rel="noreferrer noopener"><img decoding="async" loading="lazy" src="https://ruslany.net/wp-content/uploads/2020/01/LogAnalyticsExample-1024x401.png" alt="" class="wp-image-424500" width="512" height="201"/></a><figcaption>Querying file changes in the past 7 days</figcaption></figure>



<p>and AppServiceAuditLogs:</p>



<figure class="wp-block-image size-large is-resized"><a href="https://ruslany.net/wp-content/uploads/2020/01/LogAnalyticsExample2_masked-e1579377862568.png" target="_blank" rel="noreferrer noopener"><img decoding="async" loading="lazy" src="https://ruslany.net/wp-content/uploads/2020/01/LogAnalyticsExample2_masked-1024x465.png" alt="" class="wp-image-424514" width="512" height="233"/></a><figcaption> <em>Querying the publishing access in the past 7 days</em> </figcaption></figure>



<p>The log analytics allows you to create complex queries against these logs and also use those queries to create rule-based alerts. For example you can create an alert that will send you an email whenever a files with extension .config and *.dll are modified.</p>



<h3 class="wp-block-heading">How to exclude specific files or directories from audit</h3>



<p>If an application generates many temporary files or if it constantly writes something to a log file then this may result in very noisy audit log. To prevent this from happening you can exclude certain directories from auditing by using the audit log filter file.</p>



<p>Create a file named _auditLog.filter at the root directory of your site content (D:\Home) and add the directory and file paths to be excluded there:</p>



<pre class="wp-block-code"><code># this is an example of an audit filter file
# it can contain file and directory paths
# it can have comments
# it can have up to 50 exclude paths
# each path can be up to 256 chars long
/LogFiles
/site/locks
/site/deployments
/site/wwwroot/applogs/phperrors.log</code></pre>



<h3 class="wp-block-heading">Known issues</h3>



<ul><li>The file change audit and publishing access audit are currently in a public preview. The functionality may have some bugs and the logs schema may change</li><li>The file change audit is only available for app services that run on Windows App Service plans. The Linux App Service Plans are not supported at the time of writing this article.</li></ul>
<p>The post <a href="https://ruslany.net/2020/01/how-to-monitor-azure-app-service-content-changes-and-publishing-activity/">How to monitor Azure App Service content changes and publishing activity</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ruslany.net/2020/01/how-to-monitor-azure-app-service-content-changes-and-publishing-activity/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Using ARM template to swap App Service deployment slots</title>
		<link>https://ruslany.net/2019/10/using-arm-template-to-swap-app-service-deployment-slots/</link>
					<comments>https://ruslany.net/2019/10/using-arm-template-to-swap-app-service-deployment-slots/#respond</comments>
		
		<dc:creator><![CDATA[Ruslan]]></dc:creator>
		<pubDate>Tue, 01 Oct 2019 18:43:06 +0000</pubDate>
				<category><![CDATA[Azure App Service]]></category>
		<category><![CDATA[Deployment Slots]]></category>
		<category><![CDATA[App Service]]></category>
		<category><![CDATA[Azure Websites]]></category>
		<guid isPermaLink="false">https://ruslany.net/?p=424454</guid>

					<description><![CDATA[<p>Azure Resource Manager (ARM) templates are used to automate deployment and configuration of Azure resources. With the templates you can define the infrastructure to be deployed via a JSON file and then use that file to repeatedly deploy new resources or update existing ones. ARM templates are widely used to release new versions of the &#8230; <a href="https://ruslany.net/2019/10/using-arm-template-to-swap-app-service-deployment-slots/" class="more-link">Continue reading<span class="screen-reader-text"> "Using ARM template to swap App Service deployment slots"</span></a></p>
<p>The post <a href="https://ruslany.net/2019/10/using-arm-template-to-swap-app-service-deployment-slots/">Using ARM template to swap App Service deployment slots</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p><a rel="noreferrer noopener" aria-label="Azure Resource Manager (ARM) templates (opens in a new tab)" href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/template-deployment-overview" target="_blank">Azure Resource Manager (ARM) templates</a> are used to automate deployment and configuration of Azure resources. With the templates you can define the infrastructure to be deployed via a JSON file and then use that file to repeatedly deploy new resources or update existing ones. ARM templates are widely used to release new versions of the Azure web apps and function apps. During a release the new version of an app is deployed to a staging slot and then it is swapped into production. This blog post explains how to automate the <a rel="noreferrer noopener" aria-label="App Service deployment slot swap (opens in a new tab)" href="https://review.docs.microsoft.com/en-us/azure/app-service/deploy-staging-slots" target="_blank">App Service deployment slot swap</a> operation with an ARM template.</p>



<span id="more-424454"></span>



<p>Let&#8217;s assume you have a web app with production and staging deployment slots. When you release a new version of that web app you first would deploy it to the staging slot and then swap it into production slot. To define the swap operation via ARM template you&#8217;ll need to use two properties on the &#8220;Microsoft.Web/sites&#8221; and &#8220;Microsoft.Web/sites/slots&#8221; resources:</p>



<ul><li><strong>buildVersion </strong>&#8211; this is a string property which can be set to any arbitrary value that would represent the current version of the app deployed in the slot. For example: &#8220;<em>v1</em>&#8220;, &#8220;<em>1.0.0.1</em>&#8220;, &#8220;<em>2019-09-20T11:53:25.2887393-07:00</em>&#8220;.</li><li><strong>targetBuildVersion </strong>&#8211; this is a string property that is used to specify what version of the app the current slot should have. If the targetBuildVersion is different from the buildVersion then this will trigger the swap operation by finding a slot that has the expected build version and then swapping the site from that slot into the current slot. </li></ul>



<p>With that the process of deploying a new version of an app can be done as follows:</p>



<ol><li>Deploy a new version of an app into a staging slot</li><li>Execute ARM template to update the buildVersion of the app in staging slot</li><li>Execute ARM template to set the targetBuildVersion on the production slot</li></ol>



<p>Here is an example ARM template that demonstrates how to perform steps #2 and #3:</p>



<pre class="wp-block-code"><code>{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "sites_SwapAPIDemo_name": {
            "defaultValue": "SwapAPIDemo",
            "type": "String"
        },
        "sites_buildVersion": {
            "defaultValue": "v1",
            "type": "String"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Web/sites/slots",
            "apiVersion": "2018-02-01",
            "name": "[concat(parameters('sites_SwapAPIDemo_name'), '/staging')]",
            "location": "East US",
            "kind": "app",
            "properties": {
                "buildVersion": "[parameters('sites_buildVersion')]"
            }
        },
        {
            "type": "Microsoft.Web/sites",
            "apiVersion": "2018-02-01",
            "name": "[parameters('sites_SwapAPIDemo_name')]",
            "location": "East US",
            "kind": "app",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites/slots', parameters('sites_SwapAPIDemo_name'), 'staging')]"
            ],
            "properties": {
                "targetBuildVersion": "[parameters('sites_buildVersion')]"
            }
        }        
    ]
}</code></pre>



<p>This ARM template is idempotent, meaning that it can be executed repeatedly and produce the same state of the slots. In other words if you re-run the same template with the same parameters after the swap has been performed and <strong>targetBuildVersion </strong>on production slot matches the <strong>buildVersion </strong>then it will not trigger another swap.</p>
<p>The post <a href="https://ruslany.net/2019/10/using-arm-template-to-swap-app-service-deployment-slots/">Using ARM template to swap App Service deployment slots</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ruslany.net/2019/10/using-arm-template-to-swap-app-service-deployment-slots/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to restore a deleted Azure Web App</title>
		<link>https://ruslany.net/2019/06/how-to-restore-a-deleted-azure-web-app/</link>
					<comments>https://ruslany.net/2019/06/how-to-restore-a-deleted-azure-web-app/#comments</comments>
		
		<dc:creator><![CDATA[Ruslan]]></dc:creator>
		<pubDate>Wed, 05 Jun 2019 18:51:51 +0000</pubDate>
				<category><![CDATA[Azure App Service]]></category>
		<category><![CDATA[App Service]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<guid isPermaLink="false">https://ruslany.net/?p=424425</guid>

					<description><![CDATA[<p>If you happened to accidentally delete your web app in Azure App Service then up until recently you had to open a support case in order to get it restored. But now you can restore it yourself by using the commands from the Az PowerShell module. This blog post explains how to do that. Assume &#8230; <a href="https://ruslany.net/2019/06/how-to-restore-a-deleted-azure-web-app/" class="more-link">Continue reading<span class="screen-reader-text"> "How to restore a deleted Azure Web App"</span></a></p>
<p>The post <a href="https://ruslany.net/2019/06/how-to-restore-a-deleted-azure-web-app/">How to restore a deleted Azure Web App</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you happened to accidentally delete your web app in Azure App Service then up until recently you had to open a support case in order to get it restored. But now you can restore it yourself by using the commands from the <a href="https://docs.microsoft.com/en-us/powershell/azure/overview?view=azps-2.2.0">Az PowerShell</a> module. This blog post explains how to do that.</p>



<p>Assume you used to have a site named &#8220;<strong>undeletesiteexample</strong>&#8221; and you have deleted it accidentally. The first step to recover it is to get the details of the deleted app:</p>



<span id="more-424425"></span>



<pre class="wp-block-code"><code>Get-AzDeletedWebApp -Name undeletesiteexample</code></pre>



<figure class="wp-block-image is-resized"><a href="https://ruslany.net/wp-content/uploads/2019/06/UndeleteSite1.png"><img decoding="async" loading="lazy" src="https://ruslany.net/wp-content/uploads/2019/06/UndeleteSite1.png" alt="" class="wp-image-424431" width="579" height="314" srcset="https://ruslany.net/wp-content/uploads/2019/06/UndeleteSite1.png 579w, https://ruslany.net/wp-content/uploads/2019/06/UndeleteSite1-300x163.png 300w" sizes="(max-width: 579px) 85vw, 579px" /></a><figcaption>Get-AzDeletedWebApp output</figcaption></figure>



<p>This command will return the information about the deleted app such as when it was deleted and what is its DeletedSiteId. The DeletedSiteId is used to uniquely identify the deleted app in case there have been several apps with the same name deleted.</p>



<p>The next step is to restore the deleted app by using <code>Restore-AzDeletedWebApp</code> command:</p>



<pre class="wp-block-code"><code>Restore-AzDeletedWebApp -ResourceGroupName SwapTestRG -Name undeletesiteexample -TargetAppServicePlanName SwapTestASP</code></pre>



<figure class="wp-block-image"><img decoding="async" loading="lazy" width="579" height="538" src="https://ruslany.net/wp-content/uploads/2019/06/UndeleteSite2.png" alt="" class="wp-image-424433" srcset="https://ruslany.net/wp-content/uploads/2019/06/UndeleteSite2.png 579w, https://ruslany.net/wp-content/uploads/2019/06/UndeleteSite2-300x279.png 300w" sizes="(max-width: 579px) 85vw, 579px" /><figcaption>Restore-AzDeletedWebApp output</figcaption></figure>



<p>Or alternatively you can pipe the output of the <code>Get-AzDeletedWebApp</code> command:</p>



<pre class="wp-block-code"><code>$deletedSiteInfo = Get-AzDeletedWebApp -Name undeletesiteexample
$deletedSiteInfo | Restore-AzDeletedWebApp -ResourceGroupName SwapTestRG -Name undeletesiteexample -TargetAppServicePlanName SwapTestASP</code></pre>



<p>The <code>Restore-AzDeletedWebApp</code> can be used to restore a site using the same or different name. Also you can chose where to restore it to, e.g. which resource group, app service plan or deployment slot. In addition you can also chose to restore just the content (<code>[-RestoreContentOnly]</code>) or the content and the site&#8217;s configuration settings.</p>



<p>Note that if the app was hosted on and then deleted from an App Service Environment then it can be restored only if the corresponding App Service Environment still exist.</p>
<p>The post <a href="https://ruslany.net/2019/06/how-to-restore-a-deleted-azure-web-app/">How to restore a deleted Azure Web App</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ruslany.net/2019/06/how-to-restore-a-deleted-azure-web-app/feed/</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>Azure App Service Deployment Slots Tips and Tricks</title>
		<link>https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/</link>
					<comments>https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/#comments</comments>
		
		<dc:creator><![CDATA[Ruslan]]></dc:creator>
		<pubDate>Tue, 04 Jun 2019 19:21:32 +0000</pubDate>
				<category><![CDATA[Azure App Service]]></category>
		<category><![CDATA[Deployment Slots]]></category>
		<category><![CDATA[App Service]]></category>
		<category><![CDATA[Azure Websites]]></category>
		<guid isPermaLink="false">https://ruslany.net/?p=424386</guid>

					<description><![CDATA[<p>This post explains some of the not so well-known features and configurations settings of the Azure App Service deployment slots. These can be used to modify the swap logic as well as to improve the application availability during and after the swap. Here is what you can do with them: Swap slots only if the &#8230; <a href="https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/" class="more-link">Continue reading<span class="screen-reader-text"> "Azure App Service Deployment Slots Tips and Tricks"</span></a></p>
<p>The post <a href="https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/">Azure App Service Deployment Slots Tips and Tricks</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This post explains some of the not so well-known features and configurations settings of the <a href="https://docs.microsoft.com/en-us/azure/app-service/deploy-staging-slots">Azure App Service deployment slots</a>. These can be used to modify the swap logic as well as to improve the application availability during and after the swap. Here is what you can do with them:</p>



<ul><li><a href="https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/#status-code">Swap slots only if the warm up request gets an expected status code</a></li><li><a href="https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/#prevent-cold-start">Minimize the random cold starts in the production slot</a></li><li><a href="https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/#slot-sticky-config">Configure the behavior of the slot settings</a></li><li><a href="https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/#swap-detector">Use swap detector to troubleshoot swap errors</a></li></ul>



<span id="more-424386"></span>



<h4 class="wp-block-heading" id="status-code">Swap based on the status code</h4>



<p>During the swap operation the site in the staging slot is warmed up by making an HTTP request to its root directory. More detailed explanation of that process is available at <a href="https://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/">How to warm up Azure Web App during deployment slots swap</a>. By default the swap will proceed as long as the site responds with <strong>any</strong> status code. However, if you prefer the swap to not proceed if the application fails to warm up then you can configure it by using these app settings:</p>



<ul><li><code>WEBSITE_SWAP_WARMUP_PING_PATH</code>: The path to make the warm up request to. Set this to a URL path that begins with a slash as the value. For example, &#8220;/warmup.php&#8221;. The default value is /.</li><li><code>WEBSITE_SWAP_WARMUP_PING_STATUSES</code>:Expected HTTP response codes for the warm-up operation. Set this to a comma-separated list of HTTP status codes. For example: &#8220;200,202&#8221; . If the returned status code is not in the list, the swap operation will not complete. By default, all response codes are valid.</li></ul>



<p>You can mark those two app setting as &#8220;Slot Settings&#8221; which would make them remain with the slot during the swap. Or you can have them as &#8220;non-sticky&#8221; settings meaning that they would move with the site as it gets swapped between slots.</p>



<h4 class="wp-block-heading" id="prevent-cold-start">Minimize random cold starts</h4>



<p>In some cases after the swap the web app in the production slot may restart later without any action taken by the app owner. This usually happens when the underlying storage infrastructure of Azure App Service undergoes some changes. When that happens the application will restart on all VMs at the same time which may result in a cold start and a high latency of the HTTP requests. While you cannot control the underlying storage events you can minimize the effect they have on your app in the production slot. Set this app setting on <strong>every</strong> slot of the app:</p>



<ul><li><code>WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG</code>: setting this to &#8220;1&#8221; will prevent web app&#8217;s worker process and app domain from recycling when the App Service&#8217;s storage infrastructure gets reconfigured. </li></ul>



<p>The only side effect this setting has is that it may cause problems when used with some Windows Communication Foundation (WCF) application. If you app does not use WCF then there is no downside of using this setting.</p>



<h4 class="wp-block-heading" id="slot-sticky-config">Control SLOT-sticky configuration</h4>



<p>Originally when deployment slots functionality was released it did not properly handle some of the common site configuration settings during swap. For example if you configured IP restrictions on the production slot but did not configure that on the staging slot and then performed the swap you would have had the production slot without any IP restrictions configuration, while the staging slot had the IP restrictions enabled. That did not make much sense so the product team has fixed that. Now the following settings always remain with the slot:</p>



<ul><li>IP Restrictions</li><li>Always On</li><li>Protocol settings (Https Only, TLS version, client certificates)</li><li>Diagnostic Log settings</li><li>CORS </li></ul>



<p>If however for any reason you need to revert to the old behavior of swapping these settings then you can add the app setting <code>WEBSITE_OVERRIDE_PRESERVE_DEFAULT_STICKY_SLOT_SETTINGS</code> to <strong>every </strong>slot of the app and set its value to &#8220;0&#8221; or &#8220;false&#8221;.</p>



<h4 class="wp-block-heading" id="swap-detector">swap Diagnostics detector</h4>



<p>If a swap operation did not complete successfully for any reason you can use the diagnostics detector to see what has happened during the swap operation and what caused it to fail. To get to it use the &#8220;Diagnose and solve problems&#8221; link in the portal:</p>



<figure class="wp-block-image is-resized"><a href="https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks1.png"><img decoding="async" loading="lazy" src="https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks1.png" alt="" class="wp-image-424414" width="488" height="416" srcset="https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks1.png 976w, https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks1-300x255.png 300w, https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks1-768x654.png 768w" sizes="(max-width: 488px) 85vw, 488px" /></a><figcaption>How to find the Swap Diagnostics detector</figcaption></figure>



<p>From there click on &#8220;Check Swap Operations&#8221; which will open a page showing all the swaps performed on the webapp and their results. It will include possible root causes for the failures and recommendations on how to fix them.</p>



<figure class="wp-block-image is-resized"><a href="https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks2.png"><img decoding="async" loading="lazy" src="https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks2-1024x661.png" alt="" class="wp-image-424416" width="512" height="331" srcset="https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks2-1024x661.png 1024w, https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks2-300x194.png 300w, https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks2-768x495.png 768w, https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks2-1200x774.png 1200w, https://ruslany.net/wp-content/uploads/2019/06/SlotsTipsTricks2.png 1389w" sizes="(max-width: 512px) 85vw, 512px" /></a><figcaption>Check Swap Operations page</figcaption></figure>
<p>The post <a href="https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/">Azure App Service Deployment Slots Tips and Tricks</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/feed/</wfw:commentRss>
			<slash:comments>30</slash:comments>
		
		
			</item>
		<item>
		<title>Using Azure Activity Log to check the progress of deployment slots swap operation</title>
		<link>https://ruslany.net/2018/03/using-azure-activity-log-to-check-the-progress-of-deployment-slots-swap-operation/</link>
					<comments>https://ruslany.net/2018/03/using-azure-activity-log-to-check-the-progress-of-deployment-slots-swap-operation/#comments</comments>
		
		<dc:creator><![CDATA[Ruslan]]></dc:creator>
		<pubDate>Thu, 08 Mar 2018 18:10:38 +0000</pubDate>
				<category><![CDATA[Azure App Service]]></category>
		<category><![CDATA[Deployment Slots]]></category>
		<category><![CDATA[Azure Websites]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<guid isPermaLink="false">http://ruslany.net/?p=424244</guid>

					<description><![CDATA[<p>If you use Azure Web App Deployment Slots then you may have noticed that sometimes the swap action may take a while to complete. This may happen when an application that is being swapped into production has a long warmup/initialization phase. It has to be warmed up on every VM in an App Service Plan &#8230; <a href="https://ruslany.net/2018/03/using-azure-activity-log-to-check-the-progress-of-deployment-slots-swap-operation/" class="more-link">Continue reading<span class="screen-reader-text"> "Using Azure Activity Log to check the progress of deployment slots swap operation"</span></a></p>
<p>The post <a href="https://ruslany.net/2018/03/using-azure-activity-log-to-check-the-progress-of-deployment-slots-swap-operation/">Using Azure Activity Log to check the progress of deployment slots swap operation</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you use <a href="https://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/">Azure Web App Deployment Slots</a> then you may have noticed that sometimes the swap action may take a while to complete. This may happen when an application that is being swapped into production has a long warmup/initialization phase. It has to be warmed up on every VM in an App Service Plan and that sometimes takes minutes (more detailed description of what happens during the swap can be found in&nbsp;<a href="http://ruslany.net/2017/11/most-common-deployment-slot-swap-failures-and-how-to-fix-them/">Most common deployment slot swap failures and how to fix them</a>).&nbsp;This blog post explains how to see the progress and the result of the swap operation in the Azure Activity Log.</p>



<span id="more-424244"></span>



<p>To see the swap operation events use the Activity log view in the Azure Portal:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2018/03/2018-03-07_15h29_31.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2018/03/2018-03-07_15h29_31.png" alt="Activity Log" class="wp-image-424254"/></a></figure>



<p>Here is an example of how the swap events look like:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2018/03/2018-03-07_16h40_49.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2018/03/2018-03-07_16h40_49-500x479.png" alt="Swap events example" class="wp-image-424264"/></a></figure>



<ol><li><strong>ApplySlotConfig</strong> &#8211;&nbsp;this is logged when slot settings from production slot have been applied to a webapp in the staging slot</li><li><strong>StartSlotWarmup</strong> &#8211; this is logged when starting to initialize the webapp in the staging slot</li><li><strong>EndSlotWarmup</strong> &#8211; this indicates that the webapp initialization has completed</li><li><strong>SlotSwap</strong> &#8211; this is logged when the webapp from the staging slot has been swapped into production slot.</li></ol>



<p>If there was a failure while swapping the slots then the events will look like below. The event description will have explanation of why the failure occurred.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2018/03/2018-03-07_16h44_34.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2018/03/2018-03-07_16h44_34-500x325.png" alt="Failed swap event in activity log" class="wp-image-424274"/></a></figure>



<p>If you use PowerShell then you can get the swap related events by using this command:</p>



<pre class="wp-block-code"><code>Get-AzureRmLog -ResourceGroup slotswaptest -StartTime 2018-03-07 -Caller SlotSwapJobProcessor</code></pre>



<p>This will produce an output as below:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2018/03/2018-03-07_16h15_51.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2018/03/2018-03-07_16h15_51-500x427.png" alt="Activity Log in PowerShell" class="wp-image-424284"/></a></figure>



<p>(For more information on how to get Activity Log events via Powershell refer to&nbsp;<a href="https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-audit">View activity logs to audit actions on resources</a>)</p>



<p>If you prefer to call the Azure API&#8217;s directly (or by using ARMClient tool) then you make a request like below:</p>



<pre class="wp-block-code"><code>ArmClient.exe GET "//providers/microsoft.insights/eventtypes/management/values?api-version=2015-04-01&amp;$filter=eventTimestamp ge '2018-03-07T00:00:00Z' and eventTimestamp le '2018-03-08T23:00:00Z' and resourceGroupName eq 'slotswaptest'"</code></pre>



<p>In the response look for events that have <strong>Caller</strong> property set to &#8220;<strong>SlotSwapJobProcessor</strong>&#8220;.</p>
<p>The post <a href="https://ruslany.net/2018/03/using-azure-activity-log-to-check-the-progress-of-deployment-slots-swap-operation/">Using Azure Activity Log to check the progress of deployment slots swap operation</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ruslany.net/2018/03/using-azure-activity-log-to-check-the-progress-of-deployment-slots-swap-operation/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>Most common deployment slot swap failures and how to fix them</title>
		<link>https://ruslany.net/2017/11/most-common-deployment-slot-swap-failures-and-how-to-fix-them/</link>
					<comments>https://ruslany.net/2017/11/most-common-deployment-slot-swap-failures-and-how-to-fix-them/#comments</comments>
		
		<dc:creator><![CDATA[Ruslan]]></dc:creator>
		<pubDate>Thu, 02 Nov 2017 21:30:01 +0000</pubDate>
				<category><![CDATA[Azure App Service]]></category>
		<category><![CDATA[Deployment Slots]]></category>
		<category><![CDATA[App Service]]></category>
		<category><![CDATA[Azure Websites]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<guid isPermaLink="false">http://ruslany.net/?p=419544</guid>

					<description><![CDATA[<p>Azure Web App Deployment Slots are used to deploy new versions of an application code into production with no interruption to the production traffic. In order to achieve this the swap process involves multiple steps that are performed to prepare the new version of the code to successfully handle the load once it is in &#8230; <a href="https://ruslany.net/2017/11/most-common-deployment-slot-swap-failures-and-how-to-fix-them/" class="more-link">Continue reading<span class="screen-reader-text"> "Most common deployment slot swap failures and how to fix them"</span></a></p>
<p>The post <a href="https://ruslany.net/2017/11/most-common-deployment-slot-swap-failures-and-how-to-fix-them/">Most common deployment slot swap failures and how to fix them</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p><a href="https://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/">Azure Web App Deployment Slots</a> are used to deploy new versions of an application code into production with no interruption to the production traffic. In order to achieve this the swap process involves multiple steps that are performed to prepare the new version of the code to successfully handle the load once it is in production slot. Some of these steps may go wrong, especially when the new version of the code does not cooperate well. This in turn either causes the swap to fail or it results in swapping new code in production while it is still not ready to handle the production load. This post describes the most common reasons why this may happen and how to correct them.</p>



<span id="more-419544"></span>



<p>In order to better understand the reasons for the swap failures it is first necessary to explain how the application code in the staging slot is initialized / warmed up prior to the swap to production. Failures during these steps are the most common reasons for the overall failure of the swap operation.</p>



<p>The swap operation is done by an internal process that runs within a scale unit where web app is hosted. Here are the steps that it performs to ensure the application is initialized prior to the swap. Note that the same sequence of actions happens during <strong>Auto-Swap</strong> and <a href="http://ruslany.net/2015/10/azure-web-app-deployment-slot-swap-with-preview/">Swap with Preview</a>.</p>



<ul><li>Apply the production configuration settings to all web app&#8217;s instances in the staging slot. This happens when web app has appsettings or connection strings marked as &#8220;<a href="https://docs.microsoft.com/en-us/azure/app-service/web-sites-staged-publishing">Slot settings</a>&#8221; or if <a href="http://ruslany.net/2014/03/azure-web-sites-continuous-deployment-with-staged-publishing/">Continuous Deployment</a> is enabled for the site or if Site Authentication is enabled. This will trigger all instances in the staging slot to restart. (For <strong>Swap with Preview</strong> this the first phase of the swap after which the swap process is paused and you can validate that the application works correctly with production settings)</li><li>Wait for every instance to complete its restart. If some instance failed to restart then the swap process will revert any configuration changes to the app in staging slot and will not proceed further. If that happens the first place to look into is the <strong>D:\home\LogFiles\eventlog.xml</strong> file of the application specific error log (such as <strong>php_errors.log</strong> for PHP apps) where you may find more clues what prevents application from starting.</li><li>If Local Cache is enabled then swap process will trigger Local Cache initialization by making an HTTP request to the root directory URL path (&#8220;/&#8221;) of the web app on every web worker. Local Cache Initialization consists of copying the site&#8217;s content files from network share to the local disk of the worker and then re-pointing the web app to use local disk for its content. This causes another restart of the web app. The swap process will wait until the Local Cache is completely initialized and restarted on every instance before proceeding further. A common reason why Local Cache Initialization may fail is when site content size exceeds the local disk quota specified for the Local Cache. If that is the case the the quota can be increased by following instructions from <a href="https://docs.microsoft.com/en-us/azure/app-service/app-service-local-cache-overview">Local Cache Documentation</a>.</li><li>If <a href="https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-8/iis-80-application-initialization">Application Initialization</a> (AppInit) is enabled then swap process will make another HTTP request to the root URL path on every web worker. The AppInit is a module that runs within the web app request processing pipeline and it gets executed when web app starts. The only thing the swap process does with its first HTTP request to the web app is it triggers the AppInit module to do its work. After that it just waits until AppInit reports that it has completed the warmup. AppInit module uses the list of URL paths specified inside web.config file and makes internal HTTP requests to each of those. All these requests are within the web app process. It does not call any external URL&#8217;s and its requests are not going through the scale unit&#8217;s front ends. Also, neither the initial HTTP request nor AppInit internal requests follow HTTP redirects. That causes the most common problem that users run into with this module. If web app has such rewrite rules as &#8220;<a href="http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/#canonical">Enforce Domain</a>&#8221; or &#8220;<a href="http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/#redirect-https">Enforce HTTPs</a>&#8221; then none of the warmup requests will actually reach the application code. All the requests will be shortcut by the rewrite rules. In order to prevent that the rewrite rules need to be modified like below:</li></ul>



<pre class="wp-block-code"><code>&lt;rule name="Canonical Host Name" stopProcessing="true">
  &lt;match url="(.*)" />
  &lt;conditions>
    &lt;add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
    &lt;add input="{REMOTE_ADDR}" pattern="^100?\." negate="true" />
    &lt;add input="{HTTP_HOST}" negate="true" pattern="^ruslany\.net$" />
  &lt;/conditions>
  &lt;action type="Redirect" url="http://ruslany.net/{R:1}" redirectType="Permanent" />
&lt;/rule></code></pre>



<pre class="wp-block-code"><code>&lt;rule name="Redirect to HTTPS" stopProcessing="true">
  &lt;match url="(.*)" />
  &lt;conditions>
    &lt;add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
    &lt;add input="{REMOTE_ADDR}" pattern="^100?\." negate="true" />
    &lt;add input="{HTTPS}" pattern="^OFF$" />
  &lt;/conditions>
  &lt;action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
&lt;/rule></code></pre>



<p>The <strong>{WARMUP_REQUEST}</strong> is a server variable that is set by AppInit module for each of its internal requests. That is a reliable way to distinguish whether the request is external or is made by AppInit module. The <strong>{REMOTE_ADDR}</strong> is a server variable that contains the IP address of HTTP client. The IP address ranges starting with &#8220;<strong>10.</strong>&#8221; or &#8220;<strong>100.</strong>&#8221; are internal to the scale unit and no outside HTTP client can use them.
</p>



<ul><li>If AppInit is not enabled then swap process just makes an HTTP request to the root path of the webapp on each web worker and as long as it receives some HTTP response it considers the warmup complete. Again the rewrite rules in the web app can cause the site to return HTTP redirect response and the actual application code will not be executed at all. Since the AppInit is not involved here the only way to prevent the rewrite rules is to use the <strong>{REMOTE_ADDR}</strong> server variable in the rule&#8217;s conditions as shown below.</li></ul>



<pre class="wp-block-code"><code>&lt;conditions>
  &lt;add input="{REMOTE_ADDR}" pattern="^100?\." negate="true" />
&lt;/conditions></code></pre>



<ul><li> After all the above steps are completed successfully the actual swap is performed by switching the routing rules on the scale unit&#8217;s front ends. More details on what happens during the swap can be found in other blog post &#8220;<a href="http://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/">How to warm up Azure Web App during deployment slots swap</a>&#8221; </li></ul>



<p>Some other common problems that cause the swap to fail:</p>



<ul><li>An HTTP request to the root URL path times out. The swap process waits for 90 seconds for the request to return. In case of timeout the request will be retried for up to 5 times. If after that the request still times out then the swap operation will be aborted. If that happens then check the eventlog.xml or application specific error log to see if there are any indications of what causes the timeout.</li><li>An HTTP request to the root URL path is aborted. This may happen if web app has a rewrite rule to abort some requests. If that is the case then the rule can be modified by adding the {REMOTE_ADDR} check as shown in previous examples.</li><li>Web App has <a href="https://azure.microsoft.com/en-us/blog/ip-and-domain-restrictions-for-windows-azure-web-sites/?v=17.42n">IP restriction rules</a> that prevent the swap process from connecting to it. In that case you&#8217;ll need to allow the internal IP address range used by the swap process:<figure><a href="http://ruslany.net/wp-content/uploads/2017/11/BlogPost1.png"><img decoding="async" loading="lazy" title="IP Restriction Rules" width="500" height="257" class="alignnone size-medium wp-image-419654 screenshot" src="https://ruslany.net/wp-content/uploads/2017/11/BlogPost1-500x257.png" alt=""></a></figure></li></ul>
<p>The post <a href="https://ruslany.net/2017/11/most-common-deployment-slot-swap-failures-and-how-to-fix-them/">Most common deployment slot swap failures and how to fix them</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ruslany.net/2017/11/most-common-deployment-slot-swap-failures-and-how-to-fix-them/feed/</wfw:commentRss>
			<slash:comments>15</slash:comments>
		
		
			</item>
		<item>
		<title>Using Powershell to manage Azure Web App Deployment Slots</title>
		<link>https://ruslany.net/2016/10/using-powershell-to-manage-azure-web-app-deployment-slots/</link>
					<comments>https://ruslany.net/2016/10/using-powershell-to-manage-azure-web-app-deployment-slots/#comments</comments>
		
		<dc:creator><![CDATA[Ruslan]]></dc:creator>
		<pubDate>Fri, 28 Oct 2016 00:41:20 +0000</pubDate>
				<category><![CDATA[Azure App Service]]></category>
		<category><![CDATA[Deployment Slots]]></category>
		<category><![CDATA[App Service]]></category>
		<category><![CDATA[Azure Websites]]></category>
		<category><![CDATA[PowerShell]]></category>
		<guid isPermaLink="false">http://ruslany.net/?p=402841</guid>

					<description><![CDATA[<p>This blog post has been updated from its original version in order to use the correct names of the PowerShell cmdlets. This blog post explains how to perform common management tasks for Azure Web App deployment slots by using Powershell cmdlets. To learn more about deployment slots refer to the Azure documentation and my previous &#8230; <a href="https://ruslany.net/2016/10/using-powershell-to-manage-azure-web-app-deployment-slots/" class="more-link">Continue reading<span class="screen-reader-text"> "Using Powershell to manage Azure Web App Deployment Slots"</span></a></p>
<p>The post <a href="https://ruslany.net/2016/10/using-powershell-to-manage-azure-web-app-deployment-slots/">Using Powershell to manage Azure Web App Deployment Slots</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<blockquote class="wp-block-quote"><p>This blog post has been updated from its original version in order to use the correct names of the PowerShell cmdlets.</p></blockquote>



<p>This blog post explains how to perform common management tasks for Azure Web App deployment slots by using Powershell cmdlets. To learn more about deployment slots refer to the <a href="https://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/">Azure documentation</a> and my previous blog posts: <a href="http://ruslany.net/2015/10/azure-web-app-deployment-slot-swap-with-preview/">Azure Web App Deployment Slot Swap with Preview</a>&nbsp;and <a href="http://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/">How to warm up Azure Web App during deployment slots swap</a>.</p>



<span id="more-402841"></span>



<h4 class="wp-block-heading">Create a new deployment slot for an existing web app</h4>



<pre class="wp-block-code"><code>$rg = "SomeResourceGroupName"
$site = "SomeSiteName"
New-AzWebAppSlot -ResourceGroupName $rg -name $site -slot staging</code></pre>



<h4 class="wp-block-heading">List deployment slots for a web app</h4>



<pre class="wp-block-code"><code>Get-AzWebAppSlot -ResourceGroupName $rg -name $site</code></pre>



<h4 class="wp-block-heading">Delete a deployment slot</h4>



<pre class="wp-block-code"><code>Remove-AzWebAppSlot -ResourceGroupName $rg -name $site -Slot staging</code></pre>



<h4 class="wp-block-heading">Specify slot app settings and connection strings</h4>



<pre class="wp-block-code"><code>Set-AzWebAppSlotConfigName -ResourceGroupName $rg -name $site -AppSettingNames "SlotName","Environment" -ConnectionStringNames "PrimaryDB","SecondaryDB"</code></pre>



<p>This cmdlet specifies the names of app settings and connection strings that will be treated as slot settings, meaning that they will remain with the slot during swap.</p>



<h4 class="wp-block-heading">Set the app setting values on web app and on its slots</h4>



<pre class="wp-block-code"><code>Set-AzWebApp -ResourceGroupName $rg -Name $site -AppSettings @{"SlotName" = "Production"; "Environment" = "Production"}
Set-AzWebAppSlot -ResourceGroupName $rg -Name $site -Slot staging -AppSettings @{"SlotName" = "Staging"; "Environment" = "Staging"}</code></pre>



<h4 class="wp-block-heading">Perform a regular slot swap</h4>



<pre class="wp-block-code"><code>Switch-AzWebAppSlot -ResourceGroupName $rg -Name $site -SourceSlotName staging -DestinationSlotName production</code></pre>



<h4 class="wp-block-heading">Perform swap with preview</h4>



<p>First check that the staging slot&#8217;s app setting have staging values:</p>



<pre class="wp-block-code"><code>$stagingSite = Get-AzWebAppSlot -ResourceGroupName $rg -Name $site -Slot staging
$stagingSite.SiteConfig.AppSettings

Name Value
---- -----
SlotName Staging
Environment Staging</code></pre>



<p>Next perform the first step of the swap, which is to apply target slot&#8217;s setting values to the current staging slot:</p>



<pre class="wp-block-code"><code>Switch-AzWebAppSlot -ResourceGroupName $rg -Name $site -SourceSlotName staging -DestinationSlotName production -SwapWithPreviewAction ApplySlotConfig</code></pre>



<p>Now confirm that the app setting values have changed:</p>



<pre class="wp-block-code"><code>$stagingSite = Get-AzWebAppSlot -ResourceGroupName $rg -Name $site -Slot staging
$stagingSite.SiteConfig.AppSettings

Name Value
---- -----
SlotName Production
Environment Production</code></pre>



<p>At this point you would want to verify that the web app in the staging slot works as expected. You can make multiple requests to it to warm it up and fill up its caches, etc.</p>



<p>Once you are sure the app works as expected call this cmdlet to finish the swap:</p>



<pre class="wp-block-code"><code>Switch-AzWebAppSlot -ResourceGroupName $rg -Name $site -SourceSlotName staging -DestinationSlotName production -SwapWithPreviewAction CompleteSlotSwap</code></pre>



<p>If for any reason you do not want to proceed with the swap you can reset the configuration on the staging slot back to its original state:</p>



<pre class="wp-block-code"><code>Switch-AzWebAppSlot -ResourceGroupName $rg -Name $site -SourceSlotName staging -DestinationSlotName production -SwapWithPreviewAction ResetSlotSwap</code></pre>
<p>The post <a href="https://ruslany.net/2016/10/using-powershell-to-manage-azure-web-app-deployment-slots/">Using Powershell to manage Azure Web App Deployment Slots</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ruslany.net/2016/10/using-powershell-to-manage-azure-web-app-deployment-slots/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
		<item>
		<title>How to buy a certificate for an Azure Web App</title>
		<link>https://ruslany.net/2016/04/how-to-buy-a-certificate-for-an-azure-web-app/</link>
					<comments>https://ruslany.net/2016/04/how-to-buy-a-certificate-for-an-azure-web-app/#comments</comments>
		
		<dc:creator><![CDATA[Ruslan]]></dc:creator>
		<pubDate>Tue, 05 Apr 2016 18:55:25 +0000</pubDate>
				<category><![CDATA[Azure App Service]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[App Service]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">http://ruslany.net/?p=397342</guid>

					<description><![CDATA[<p>If you have tried to enable SSL for your Azure Web App you know that the steps to do that are: Purchase certificate and export it into a PFX file Upload PFX file to a resource group that contains your web app Bind the web app&#8217;s hostnames to the certificate Out of those steps the &#8230; <a href="https://ruslany.net/2016/04/how-to-buy-a-certificate-for-an-azure-web-app/" class="more-link">Continue reading<span class="screen-reader-text"> "How to buy a certificate for an Azure Web App"</span></a></p>
<p>The post <a href="https://ruslany.net/2016/04/how-to-buy-a-certificate-for-an-azure-web-app/">How to buy a certificate for an Azure Web App</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>If you have tried to enable SSL for your Azure Web App you know that the steps to do that are:</p>



<ol><li>Purchase certificate and export it into a PFX file</li><li>Upload PFX file to a resource group that contains your web app</li><li>Bind the web app&#8217;s hostnames to the certificate</li></ol>



<p>Out of those steps the step #1 is the most non-obvious. Just by looking through the <a href="https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure-ssl-certificate/">instructions in this article</a> you can see that the process is complex and error prone.</p>



<p>Recently the Azure team has released an improved support for buying certificates for Azure Web Apps. Now it is possible to purchase a certificate without ever leaving the Azure Portal UI experience. In this blog post I&#8217;ll show how easy it is to buy a certificate and enable SSL for a Web App. As an example I will walk through the process of buying a certificate and enabling SSL for my web site <a href="http://ruslany.net/">http://ruslany.net/</a></p>



<span id="more-397342"></span>



<p>To start the process of buying a cert in <a href="https://portal.azure.com">Azure Portal</a> click on <strong>Browse &gt;</strong> and select &#8220;<strong>App Service Certificates</strong>&#8220;.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2016/04/Screenshot1.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2016/04/Screenshot1-472x500.png" alt="" class="wp-image-397352"/></a></figure>



<p>Then click <strong>Add</strong> and specify the certificate properties, most importantly the Naked Domain Host Name (e.g. ruslany.net in my case):</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2016/04/Screenshot2.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2016/04/Screenshot2-500x279.png" alt="" class="wp-image-397362"/></a></figure>



<p>The certificate purchase process starts and at some point you will be asked to configure a Key Vault service which will store the purchased cert.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2016/04/Screenshot3_blur.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2016/04/Screenshot3_blur-500x387.png" alt="" class="wp-image-397562"/></a></figure>



<p>If you do not have a Key Vault configured then add a new Key Vault Repository and once it is provisioned click on the &#8220;<strong>Store</strong>&#8221; button:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2016/04/Screenshot500.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2016/04/Screenshot500-500x500.png" alt="" class="wp-image-397502"/></a></figure>



<p>After the Key Vault has been linked to your certificate then next step is to verify the domain ownership. Azure Portal makes this verification very simple. If you already have a Web App that uses the same domain name as in the certificate then you can chose &#8220;App Service Verification&#8221; method and the corresponding App will be listed below.&nbsp;Just click on &#8220;Verify&#8221; button and give it 5 to 10 minutes for verification process to complete.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2016/04/Screenshot6.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2016/04/Screenshot6-500x445.png" alt="" class="wp-image-397392"/></a></figure>



<p>Assuming the verification was successful the certificate will be issued and will be stored in the Key Vault repository from where it can be used by other App Services within your subscription:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2016/04/Screenshot8.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2016/04/Screenshot8-500x345.png" alt="" class="wp-image-397402"/></a></figure>



<p>To use the certificate in the Web App, select the Web App in the portal, then select &#8220;Custom domains and SSL&#8221; and then click on &#8220;Import Certificate&#8221;</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2016/04/Screenshot9.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2016/04/Screenshot9-500x393.png" alt="" class="wp-image-397412"/></a></figure>



<p>This will ask you to pick the certificate from the Key Vault repository:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2016/04/Screenshot10.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2016/04/Screenshot10-500x174.png" alt="" class="wp-image-397422"/></a></figure>



<p>After that the certificate information should show up in the &#8220;Custom Domains and SSL&#8221; page where you can configure SSL bindings to use that certificate:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2016/04/Screenshot11.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2016/04/Screenshot11-363x500.png" alt="" class="wp-image-397432"/></a></figure>



<h4 class="wp-block-heading">How to rekey a certificate</h4>



<p>One nice feature that is included in the certificate management functionality is the ability to rekey a certificate. If for any reason you believe your certificate got compromised or if you need to rotate the certificate for security compliance reasons you can easily rekey it. This will result in a new certificate with a different thumbprint issued for your domain.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2016/04/Screenshot132.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2016/04/Screenshot132-500x322.png" alt="" class="wp-image-397442"/></a></figure>



<p>In addition, once the rekey&#8217;ed certificate has been issued you can click on &#8220;Sync&#8221; button and all the web apps that use the old certificate will be updated to use the rekey&#8217;ed certificate. Note that you can rekey these certificates as many times as you need as long as they are not expired.</p>
<p>The post <a href="https://ruslany.net/2016/04/how-to-buy-a-certificate-for-an-azure-web-app/">How to buy a certificate for an Azure Web App</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ruslany.net/2016/04/how-to-buy-a-certificate-for-an-azure-web-app/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Azure Web App Deployment Slot Swap with Preview</title>
		<link>https://ruslany.net/2015/10/azure-web-app-deployment-slot-swap-with-preview/</link>
					<comments>https://ruslany.net/2015/10/azure-web-app-deployment-slot-swap-with-preview/#comments</comments>
		
		<dc:creator><![CDATA[Ruslan]]></dc:creator>
		<pubDate>Fri, 30 Oct 2015 16:56:12 +0000</pubDate>
				<category><![CDATA[Azure App Service]]></category>
		<category><![CDATA[Deployment Slots]]></category>
		<category><![CDATA[App Service]]></category>
		<category><![CDATA[ASPNET]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<guid isPermaLink="false">http://ruslany.net/?p=392581</guid>

					<description><![CDATA[<p>Some time ago I had a blog post describing how to warm up an Azure Web App during deployment slots swap. In that post I explained the sequence of actions that happens during the swap. One important point in that explanation is that if a site has any app settings or connection strings that are &#8230; <a href="https://ruslany.net/2015/10/azure-web-app-deployment-slot-swap-with-preview/" class="more-link">Continue reading<span class="screen-reader-text"> "Azure Web App Deployment Slot Swap with Preview"</span></a></p>
<p>The post <a href="https://ruslany.net/2015/10/azure-web-app-deployment-slot-swap-with-preview/">Azure Web App Deployment Slot Swap with Preview</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Some time ago I had a blog post describing how to <a href="http://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/">warm up an Azure Web App during deployment slots swap</a>. In that post I explained the sequence of actions that happens during the swap. One important point in that explanation is that if a site has any app settings or connection strings that are marked as &#8220;Slot&#8221; then during slot swap those settings are read from target (e.g. Production) slot and applied to the site in the staging slot. That causes the restart of the site&#8217;s worker process so that those changes take effect and become visible as process environment variable.</p>



<p>The restart of the worker process is OK for the majority of the swaps. But sometimes it would be useful to pause right after the production settings were applied on the staging slot and before the actual swap of host names happens. Recently Azure Web Apps team has released a &#8220;Swap with Preview&#8221; feature that supports that use case. That feature will give you a chance to verify that the web site in the staging slot works fine with production settings. Also this will allow you to warm up/initialize the site in any way you want. For example you can generate some load on that site so that its cache is completely pre-populated. After you are satisfied with how the site works in staging slot you can complete the swap so that the site is moved to production slot and starts taking on production traffic. The site&#8217;s worker process <strong>will not be restarted</strong> during that step, which means that the worker process in production slot is exactly what you have tested in staging slot.</p>



<p>To demonstrate how Swap with Preview works I&#8217;ve created a site and added a &#8220;Slot&#8221; setting to it with name &#8220;<strong>SlotName</strong>&#8221; and value &#8220;<strong>Production</strong>&#8220;. Also I added a &#8220;Slot&#8221; connection string with value &#8220;<strong>ProductionConnectionString</strong>&#8220;.</p>



<span id="more-392581"></span>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview1.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview1-500x206.png" alt="" class="wp-image-392591"/></a></figure>



<p>Then I&#8217;ve created a staging deployment slot for this site and added a &#8220;Slot&#8221; setting to it with name &#8220;<strong>SlotName</strong>&#8221; and value &#8220;<strong>Staging</strong>&#8220;. Also I added a &#8220;Slot&#8221; connection string with value &#8220;<strong>StagingConnectionString</strong>&#8220;.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview2.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview2-500x196.png" alt="" class="wp-image-392621"/></a></figure>



<p>Then I have deployed the following ASP.NET code to both sites in production and staging slots. The code reads the environment variables where the app setting values are stored. Also it reads the current process id which changes every time the site gets restarted.</p>



<pre class="wp-block-code"><code>&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8">
&lt;title>Swap with Preview test&lt;/title>
&lt;h1>Swap with Preview Test Page&lt;/h1>
&lt;table>
&lt;tbody>
&lt;tr>
&lt;th>Server Variable&lt;/th>
&lt;th>Value&lt;/th>
&lt;/tr>
&lt;tr>
&lt;td>Process ID:&lt;/td>
&lt;td>&lt;%= System.Diagnostics.Process.GetCurrentProcess().Id %>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>SlotName:&lt;/td>
&lt;td>&lt;%= Environment.GetEnvironmentVariable("SlotName") %>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ConnectionString:&lt;/td>
&lt;td>&lt;%= Environment.GetEnvironmentVariable("SQLAZURECONNSTR_ConnectionString") %>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table></code></pre>



<p>If I browse to the production and staging slots I can see the process ID, app settings and connection strings:</p>



<p>Production slot:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview3.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview3-500x287.png" alt="" class="wp-image-392651"/></a></figure>



<p>Staging slot:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview5.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview5-500x287.png" alt="" class="wp-image-392671"/></a></figure>



<p>Now let&#8217;s assume that I have deployed a new version of an app into a staging slot and want to swap it into production. I use the &#8220;Swap&#8221; action which gives me a choice of doing a normal Swap or &#8220;Swap with Preview&#8221;. I chose &#8220;Swap with Preview&#8221; and click OK.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview6.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview6-500x225.png" alt="" class="wp-image-392681"/></a></figure>



<p>After the operation completes let&#8217;s browse to the staging slot:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview7.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview7-500x287.png" alt="" class="wp-image-392701"/></a></figure>



<p>Notice that the Process ID has changed, meaning that the worker process has restarted. Also the SlotName and ConnectionString now contain the values from the production slot. Basically the site now has all the settings that it would have in production slot except that it is still in the staging slot and does not receive any production traffic. This gives me an opportunity to verify how the new version of my app behaves with production settings. Also it lets me hit all the important URL paths on my app to make sure they are properly warmed up.</p>



<blockquote class="wp-block-quote"><p><strong>IMPORTANT</strong>: While the site is in this &#8220;swap pending&#8221; state it is not possible to make any changes to connection strings and app settings of both slots involved in the swap.</p></blockquote>



<p>From here I have two options. If I am happy with how my new app version works with production settings I can complete the swap by using &#8220;Complete Swap&#8221; action and then choosing &#8220;Complete Swap&#8221; from the drop down list:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview8.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview8-500x277.png" alt="" class="wp-image-392711"/></a></figure>



<p>if I browse to the production slot after the swap completes&nbsp;I can see that it now has the new version of my app and the Process ID is the same, meaning that the worker process has not restarted.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview9.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/10/SwapWithPreview9-500x287.png" alt="" class="wp-image-392721"/></a></figure>



<p>If however I find that the new version of my app in staging slot does not work very well with production settings I can chose &#8220;Cancel Swap&#8221; action, which will reset the settings on my staging slot.</p>



<p>This example demonstrates how to perform deployment slot swap while pausing after target slot settings have been applied to the current slot and before the swap completes. During that paused state you can prepare application for taking on production traffic so that when you complete the swap you have exact same application in production slot without any restarts.</p>



<p>With the addition of the &#8220;Swap with preview&#8221; capability there are now three options for how to perform deployment slot swaps. They range from fully manual to fully automated and you can choose any of them depending on how confident you feel about new bits you deploy:</p>



<ol><li><strong>Swap with preview</strong> &#8211; this is the option which gives you most control over the swap process. It allows you to fully verify the new version of your app before it is swapped into production and it helps to avoid restarts during the swap.</li><li><strong>Regular swap</strong> &#8211; this is the most common swap option, where the application get automatically warmed up prior to the swap. Application in the staging slot may get restarted prior to the swap.</li><li><strong>Auto-swap</strong> &#8211; this is the fully automated option where swap operation is triggered as soon as the new content is deployed to a staging slot.</li></ol>
<p>The post <a href="https://ruslany.net/2015/10/azure-web-app-deployment-slot-swap-with-preview/">Azure Web App Deployment Slot Swap with Preview</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ruslany.net/2015/10/azure-web-app-deployment-slot-swap-with-preview/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>How to warm up Azure Web App during deployment slots swap</title>
		<link>https://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/</link>
					<comments>https://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/#comments</comments>
		
		<dc:creator><![CDATA[Ruslan]]></dc:creator>
		<pubDate>Wed, 30 Sep 2015 16:23:04 +0000</pubDate>
				<category><![CDATA[Azure App Service]]></category>
		<category><![CDATA[Deployment Slots]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[App Service]]></category>
		<category><![CDATA[Tracing]]></category>
		<category><![CDATA[Windows Azure]]></category>
		<guid isPermaLink="false">https://ruslanynet.azurewebsites.net/2015/09/30/how-to-warm-up-azure-web-app-during-deployment-slots-swap/</guid>

					<description><![CDATA[<p>Azure Web App deployment slots are used to help roll out new versions of an app without downtime or cold start activation. New version is typically deployed to a staging slot, then after testing and final verification it gets swapped into a production slot. During the swap operation the Web App&#8217;s worker process may get &#8230; <a href="https://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/" class="more-link">Continue reading<span class="screen-reader-text"> "How to warm up Azure Web App during deployment slots swap"</span></a></p>
<p>The post <a href="https://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/">How to warm up Azure Web App during deployment slots swap</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p><a href="https://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/">Azure Web App deployment slots</a> are used to help roll out new versions of an app without downtime or cold start activation. New version is typically deployed to a staging slot, then after testing and final verification it gets swapped into a production slot. During the swap operation the Web App&#8217;s worker process may get restarted in order for some settings to take effect. Even though the swap does not proceed until the restarted worker process comes back online on every VM instance, it may still not be enough for application to be completely ready to take on production traffic. This post explains how you can use the recently enabled <a href="http://www.iis.net/downloads/microsoft/application-initialization">Application Initialization Module</a> to completely warm up your application prior to swapping it into production.</p>



<span id="more-388262"></span>



<p>First of all it is necessary to explain the sequence of actions that happens when a staging slot is swapped into production. When the Swap button is clicked in Azure Portal or a corresponding management API is called:</p>



<ol><li>The App Settings and Connection Strings that are marked as &#8220;Slot&#8221; are read from the Production slot and applied to the site in the Staging slot. That causes the site&#8217;s worker process to be restarted for those changes to take effect and become visible as process environment variables;</li><li>Then the site in the staging slot gets warmed up. To warm up the site an HTTP request is made to the root directory of the site to every VM instance where site is supposed to run. The warm up request has a User-Agent header set to &#8220;SiteWarmup&#8221;;</li><li>After warm up has completed the host names for the sites in production and staging slots get swapped. Now the site that has been warmed up in the staging slot starts getting production traffic and the site that used to be in the production slot is now in the staging slot</li><li>The site that is now in the staging slot gets updated with the App Settings and Connection Strings associated with the staging slot. That causes restart of that site, but it is not in production slot any more so restart is harmless.</li></ol>



<p>Sometimes hitting the site&#8217;s root URL is not enough to completely warm up the application. For example it maybe necessary to hit all important routes in an ASP.NET MVC app or to pre-populate the in-memory cache. That is where the Application Initialization Module can help.</p>



<p>Let&#8217;s use a simple example to demonstrate how a Web App can be warmed up in the deployment slot during the swap operation. First let&#8217;s create a site and a staging deployment slot:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/09/CreateSlot.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/09/CreateSlot-500x159.png" alt="" class="wp-image-388291"/></a></figure>



<p>Next let&#8217;s set some slot settings on the App and its staging slot. These slot settings will cause the App&#8217;s worker process to restart during swap.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/09/SlotSettingProd.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/09/SlotSettingProd-500x149.png" alt="" class="wp-image-388301"/></a></figure>



<p>For the actual app code I used two simple PHP files: <strong>index.php</strong> and <strong>warmup-cache.php</strong>. The <strong>index.php</strong> is served when site&#8217;s root URL is requested. The <strong>warmup-cache.php</strong> is my &#8220;cache warmup&#8221; code that takes long time to run (emulated by sleep() command). In real application that can be the script that makes database queries to fill up the cache.</p>



<p>Finally I also have a web.config file which configures AppInit module:</p>



<pre class="wp-block-code"><code>&lt;system.webServer>
  &lt;applicationInitialization >
    &lt;add initializationPage="/warmup-cache.php" hostName="appinit-warmup.azurewebsites.net"/>
  &lt;/applicationInitialization>
&lt;system.webServer></code></pre>



<p>In the <strong>applicationInitialization</strong> section I can specify multiple URL paths that need to be requested in order to warm up my application. In my case I only need to hit one URL. Also notice that I can specify the host name to use for the warm up requests (this is optional and if not specified the &#8220;localhost&#8221; will be used as a host name).</p>



<blockquote class="wp-block-quote"><p>The following steps are just for verification/debugging purposes. There is no need to perform them when using AppInit module. In fact enabling them for your production site may considerably slow it down.</p></blockquote>



<p>To confirm that the <strong>warmup-cache.php</strong> is actually requested during the swap I will use Failed Request Tracing. It can be enabled from Azure Portal:</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/09/EnableFreb.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/09/EnableFreb-245x500.png" alt="" class="wp-image-388341"/></a></figure>



<p>However, that will trace only failed requests. I need it to trace all requests. For that I add the following section to the web.config file:</p>



<pre class="wp-block-code"><code>&lt;tracing>
  &lt;traceFailedRequests>
    &lt;clear/>
    &lt;add path="*">
      &lt;traceAreas>
      &lt;add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,Rewrite,iisnode" verbosity="Verbose" />
      &lt;/traceAreas>
      &lt;failureDefinitions statusCodes="200-600" />
    &lt;/add>
  &lt;/traceFailedRequests>
&lt;/tracing></code></pre>



<p>The important attribute here is <strong>statusCodes</strong> which specifies that requests with status codes between 200 and 600 should be logged.</p>



<p>Now let&#8217;s run the swap command.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/09/SwapCommand.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/09/SwapCommand-500x271.png" alt="" class="wp-image-388381"/></a></figure>



<p>During the swap operation the application is restarted and the first warm up request is made to the root directory of the web app. That starts the AppInit module which makes a request to <strong>warmup-cache.php</strong> URL and waits until it completes. Only after that request competes the swap operation proceeds to the next step and swaps the host names so that the warmed up site starts getting production traffic. Because of that the swap operation takes longer time to complete.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/09/Swapping.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/09/Swapping.png" alt="" class="wp-image-388391"/></a></figure>



<p>After the swap completed we can analyze the Request Tracing logs to confirm that the <strong>warmup-cache.php</strong> URL has been hit prior to the swap. Note that we need to get those log files from the site in the production slot now.</p>



<figure class="wp-block-image"><a href="http://ruslany.net/wp-content/uploads/2015/09/FrebLogs.png"><img decoding="async" src="https://ruslany.net/wp-content/uploads/2015/09/FrebLogs-500x222.png" alt="" class="wp-image-388401"/></a></figure>



<p>Looking through the logs we can see the following:</p>



<ul><li>The first warm up request is made to the web site. Notice the user agent value set to &#8220;SiteWarmup&#8221;:<br><figure><a href="http://ruslany.net/wp-content/uploads/2015/09/warmuprequest.png"><img decoding="async" loading="lazy" class="alignnone size-medium wp-image-388421 screenshot" title="warmuprequest" src="https://ruslany.net/wp-content/uploads/2015/09/warmuprequest-500x127.png" alt="" width="500" height="127"></a></figure></li><li>Another log file shows that the appInit module has started and made an HTTP request to the <strong>warmup-cache.php</strong> around the same time. That request has the host name I specified in the <strong>web.config</strong> file. Also the user-agent is different.<br><figure><a href="http://ruslany.net/wp-content/uploads/2015/09/AppInitRequest.png"><img decoding="async" loading="lazy" class="alignnone size-medium wp-image-388431 screenshot" title="AppInitRequest" src="https://ruslany.net/wp-content/uploads/2015/09/AppInitRequest-500x68.png" alt="" width="500" height="68"></a></figure><br>As expected that request took around 30 seconds.<br><figure><a href="http://ruslany.net/wp-content/uploads/2015/09/TimeTaken.png"><img decoding="async" loading="lazy" class="alignnone size-medium wp-image-388441 screenshot" title="TimeTaken" src="https://ruslany.net/wp-content/uploads/2015/09/TimeTaken-500x315.png" alt="" width="500" height="315"></a></figure></li></ul>



<p>That simple example demonstrates how to use IIS Application Initialization Module with Azure Web App deployment slots to ensure that the application in the slot is completely warmed up.</p>
<p>The post <a href="https://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/">How to warm up Azure Web App during deployment slots swap</a> appeared first on <a href="https://ruslany.net">RuslanY Blog</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/feed/</wfw:commentRss>
			<slash:comments>42</slash:comments>
		
		
			</item>
	</channel>
</rss>
