Update SEQ with Powershell DSC

We user Powershell Desired State Configuration (DSC) to install everything. A new installation could be done to a clean machine or by removing existing software prior to installing it. Below is part of the script we use.

configuration DscWebServer {    
   
 Import-DscResource -ModuleName PSDesiredStateConfiguration  
    
 Node $AllNodes.NodeName {

  Script seq {
   GetScript  = { return @{} }
   TestScript = {
    # test for existing service seq
    $service = Get-Service -Name seq -ErrorAction SilentlyContinue
    if($service) { return $true }
    else { return $false }
   }
   SetScript  = {   
    $arguments = '/i ' + $using:Node.DeployLocation + '\Seq-4.2.1113.msi /qn /norestart /log ' + $using:Node.DeployLocation + '\seq.install.log'
    # msi install with logging to seq.install.log file
    Start-Process msiexec -ArgumentList $arguments -Wait
    # post install configuration to run as a windows service ...
   }
  }

 }
}

Now we want to upgrade an existing installation to preserve the data it contains.
Note: this means the installation files must support updating of existing versions. The application SEQ in this example handles updates by replacing the application and converting the data.

With the script below we can upgrade Seq version 4 to version 5.
For this we edited the installation (Script seq) to use the new msi; if the software doesn’t exist then install the newest version right away.
We also added an UpgradeSeq that depends on seq being present; there we check the version and upgrade if needed.

configuration DscWebServer {    
   
 Import-DscResource -ModuleName PSDesiredStateConfiguration  
    
 Node $AllNodes.NodeName {

  Script seq {
   GetScript  = { return @{} }
   TestScript = {
    # test for existing service seq
    $service = Get-Service -Name seq -ErrorAction SilentlyContinue
    if($service) { return $true }
    else { return $false }
   }
   SetScript  = {   
    $arguments = '/i ' + $using:Node.DeployLocation + '\Seq-5.1.3364.msi /qn /norestart /log ' + $using:Node.DeployLocation + '\seq.install.log'
    # msi install with logging to seq.install.log file
    Start-Process msiexec -ArgumentList $arguments -Wait
    # post install configuration to run as a windows service ...
   }
  }

  Script UpgradeSeq {
   DependsOn  = "[Script]seq"
   GetScript  = { return @{} }
   TestScript = {
    push-location 'c:\program files\seq'
    $version = seq.exe version
    if($version -eq '5.1.3364') { return $true }
    else { return $false }
   }
   SetScript  = {   
    # inplace upgrade
    $arguments = '/i ' + $using:Node.DeployLocation + '\Seq-5.1.3364.msi /qn /norestart /log ' + $using:Node.DeployLocation + '\seq.install.log'
    # msi install with logging to seq.install.log file
    Start-Process msiexec -ArgumentList $arguments -Wait
    # restart service to complete upgrade
    Get-Service -Name seq | Restart-Service
   }
  }

 }
}

The next version of Seq will be simple, just edit the versions in the msi and upgradeseq test in the script above. (find-and-replace 5.1.3364)

We are confident this way of working can be applied to all our upgrades, like the dotnetcore framework.

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Development, Tooling and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.