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.