67 lines
2.8 KiB
PowerShell
67 lines
2.8 KiB
PowerShell
function Get-MicroservicesWithMigrations {
|
|
<#
|
|
.SYNOPSIS
|
|
Finds microservices which have migrations. Can be used during a lane or POD move to identify Microservices which need to be reinstalled
|
|
|
|
.NOTES
|
|
For now, we assume any service running as DBMS Potentially Has Migrations
|
|
#>
|
|
## TODO: Cole refactor with manifest to determine if there's a migration
|
|
[CmdletBinding()]
|
|
[OutputType([System.Object])]
|
|
Param()
|
|
|
|
$logLead = Get-LogLeadName
|
|
Write-Verbose "$logLead : Looking for Services Running as DBMS to Reinstall"
|
|
|
|
# Get all Chocolatey Services
|
|
$chocoServices = Get-ChocolateyServices
|
|
Write-Verbose ("$logLead : Found {0} Chocolatey Services" -f $chocoServices.Count)
|
|
|
|
$chocoServicesToReinstall = @()
|
|
|
|
Write-Verbose "$logLead : Getting Formatted Local Packages"
|
|
$localChocos = Get-ChocoState -l
|
|
Write-Verbose ("$logLead : Found {0} Local Packages" -f $localChocos.Count)
|
|
|
|
$chocoServices | ForEach-Object {
|
|
|
|
$svc = $_
|
|
$serviceUser = Get-WindowsServiceUser $svc.Name
|
|
|
|
# If the service runs as DBMS and is not disabled, continue
|
|
if ($svc.StartType -eq [System.ServiceProcess.ServiceStartMode]::Disabled) {
|
|
Write-Verbose ("$logLead : Skipping Service {0} as it is Disabled" -f $svc.Name)
|
|
} elseif ($serviceUser -notmatch "dbms\$*$") {
|
|
Write-Verbose ("$logLead : Skipping Service {0} as it is Running as {1}" -f $svc.Name, $serviceUser)
|
|
} else {
|
|
Write-Verbose ("$logLead : Getting information on services {0} for reinstall" -f $svc.Name)
|
|
|
|
$localBinPath = Get-WindowsServiceApplicationPath $svc.Name
|
|
Write-Verbose ("$logLead : Read Installation Path as {0}" -f $localBinPath)
|
|
|
|
if ([string]::IsNullOrEmpty($localBinPath)) {
|
|
Write-Warning ("$logLead : Could not read install path for service: " + $svc.Name)
|
|
} else {
|
|
$installPath = (Get-Item $localBinPath).Parent
|
|
}
|
|
|
|
if ([String]::IsNullOrEmpty($installPath)) {
|
|
Write-Warning ("$logLead : Could not read install path for service: " + $svc.Name)
|
|
} else {
|
|
Write-Verbose ("$logLead : Looking for Packages Matching Name {0}" -f $installPath.Name)
|
|
[array]$choco = ($localChocos | Where-Object { $_.Name -match $installPath.Name })
|
|
if ($null -eq $choco -or $choco.Count -ne 1) {
|
|
Write-Warning ("$logLead : Found {0} Packages Matching Name {1}" -f (IsNull $choco.Count 0), $installPath.Name)
|
|
} else {
|
|
Write-Host ("$logLead : Adding Package {0} with version {1}" -f $choco.Name, $choco.Version)
|
|
$chocoServicesToReinstall += @{Name = $choco.Name; Version = $choco.Version; }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $chocoServicesToReinstall
|
|
}
|
|
|