Jeremy Davis
Jeremy Davis
Sitecore, C# and web development
Article printed from: https://blog.jermdavis.dev/posts/2015/improving-the-automated-package-installs

Improving the automated package installs

Published 06 July 2015
Updated 25 August 2016

Last week I looked at some simple PowerShell script to automate installing packages into Sitecore instances. Having spent a bit of time testing this process, I found a couple of useful tips for speeding it up:

Start Sitecore before you try to install packages

The first request to a Sitecore site (after it's been installed) usually takes a while as everything has to be started up and loaded into memory. Hence it's possible that the time for this to happen, plus install a package might cause a timeout.

So it makes sense to fire of some simple requests to the Sitecore site before you try to install packages:

function Start-Sitecore(){
    $siteName = Get-ConfigParam "InstanceName"
    $url = "http://$siteName/"

    Write-Host "Starting Sitecore..."

    $result = Invoke-WebRequest -Uri $url -TimeoutSec 0

    if($result.StatusCode -ne 200){
        throw "Sitecore failed to start at url $url"
    } else { 
        Write-Host "Public site started..."
    }

    $url = $url + "sitecore/"

    $result = Invoke-WebRequest -Uri $url -TimeoutSec 0

    if($result.StatusCode -ne 200){
        throw "Sitecore UI failed to start at url $url"
    } else { 
        Write-Host "Admin site started..."
    }
}

					

This bit of code makes a request to the instance name (to load the public site) and then to the /sitecore folder to initialise the admin interface.

Disable search indexing while installing packages

Another trick which can be helpful when installing large packages is to turn off Sitecore's automatic indexing of new items while the package installs. There's a helpful write up of how you can do this, and make use of it in the Sitecore UI here, but we just need the underlying configuration setting for a patch:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
      <settings>
        <setting name="Indexing.UpdateInterval">
          <patch:attribute name="value">00:00:00</patch:attribute>
        </setting>
      </settings>
  </sitecore>
</configuration>

					

We can add a reference to a file containing this patch to the config for the install:

<config>
  <params>

    <param name="IndexPatchFile">.\files\StopLucene.config</param>

  </params>
</config>

					

And then disabling indexing is as simple as copying that patch file to the right folder:

function Disable-Indexing(){
    Write-Host "Disabling indexing..."

    $siteName = Get-ConfigParam "InstanceName"
    $sitecorePatchFolder = "C:\Inetpub\wwwroot\$($siteName)\Website\App_Config\Include"

    $patchFilePath = Get-ConfigParam "IndexPatchFile"

    Copy-Item $patchFilePath $sitecorePatchFolder
}

					

This function can be run immediately before starting Sitecore and then installing the package files. And once the packages are installed, the automatic indexing can be re-enabled by simply deleting the patch file again:

function Enable-Indexing(){
    Write-Host "Re-enabling indexing..."
    
    $siteName = Get-ConfigParam "InstanceName"
    $sitecorePatchFolder = "C:\Inetpub\wwwroot\$($siteName)\Website\App_Config\Include"

    $patchFilePath = Get-ConfigParam "IndexPatchFile"
    $patchFile = (Split-Path -Path $patchFilePath -Leaf)

    $file = Join-Path $sitecorePatchFolder $patchFile

    Remove-Item $file
}

					
↑ Back to top