Skip to content

Instantly share code, notes, and snippets.

@grenade
Last active December 29, 2015 13:28
Show Gist options
  • Save grenade/7677021 to your computer and use it in GitHub Desktop.
Save grenade/7677021 to your computer and use it in GitHub Desktop.
Install an NServiceBus dependent Windows Service using PowerShell DSC Note that this is an untested work in progress. It wont work out of the box. ...yet.
Configuration NServiceBusServiceDeployConfig {
param (
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string[]] $targetNodes,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceDeployPath,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceArchivePath,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceDisplayName,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceExecutable,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $serviceUserame,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $servicePassword
)
Node $targetNodes {
# This is for when we get better organised with Pull mode
# http://blog.cosmoskey.com/powershell/desired-state-configuration-in-pull-mode-over-smb/
# http://blog.cosmoskey.com/wp-content/uploads/2013/09/Set-DSCServerConfiguration_v1.1_ps1.txt
#LocalConfigurationManager {
# ConfigurationID = (Get-ComputerGuid $nodeName)
# ConfigurationMode="ApplyandAutoCorrect"
# ConfigurationModeFrequencyMins = 45
# RebootNodeIfNeeded = $True
# RefreshFrequencyMins = 30
# RefreshMode = "PULL"
# AllowModuleOverwrite = $True
# DownloadManagerName = "DSCFileDownloadManager"
# DownloadManagerCustomData = (@{SourcePath = $DSCPullShareFullName})
#}
WindowsFeature netFramework45 {
Ensure = "Present"
Name = ".Net-Framework-45-Core"
}
WindowsFeature msmqServer {
Ensure = "Present"
Name = "MSMQ-Server"
DependsOn = "[WindowsFeature]msmqDirectory", "[WindowsFeature]msmqTriggers", "[WindowsFeature]msmqHttpSupport", "[WindowsFeature]msmqMulticasting", "[WindowsFeature]msmqRouting", "[WindowsFeature]msmqDcom"
}
WindowsFeature msmqDirectory {
Ensure = "Absent"
Name = "MSMQ-Directory"
}
WindowsFeature msmqTriggers {
Ensure = "Absent"
Name = "MSMQ-Triggers"
}
WindowsFeature msmqHttpSupport {
Ensure = "Absent"
Name = "MSMQ-HTTP-Support"
}
WindowsFeature msmqMulticasting {
Ensure = "Absent"
Name = "MSMQ-Multicasting"
}
WindowsFeature msmqRouting {
Ensure = "Absent"
Name = "MSMQ-Routing"
}
WindowsFeature msmqDcom {
Ensure = "Absent"
Name = "MSMQ-DCOM"
}
Archive serviceDeployPath {
Ensure = "Present"
Path = $serviceArchivePath
DestinationPath = $serviceDeployPath
}
Service serviceInstall {
Ensure = "Present"
Name = $serviceName
Credential = New-Object System.Management.Automation.PSCredential ($serviceUserame, (ConvertTo-SecureString $servicePassword -AsPlainText -Force))
DependsOn = "[WindowsFeature]netFramework45", "[WindowsFeature]msmqServer", "[Archive]serviceDeployPath", "[Script]installNServiceBusInfrastructure"
Arguments = "-binaryPathName $serviceDeployPath\$serviceExecutable", "-displayName $serviceDisplayName"
StartupType = Automatic
Status = Start
}
Script installNServiceBusInfrastructure {
SetScript = {
Function FileFind {
Param($dir, $file)
return (Get-ChildItem -Recurse -Force $dir -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $file } | Select-Object -First 1 FullName).FullName
}
Set-Location ("{0}\lib" -f $serviceDeployPath)
Import-Module FileFind ("{0}\lib" -f $serviceDeployPath) "NServiceBus.Powershell.dll"
Install-NServiceBusMSMQ
Install-NServiceBusDTC
Install-NServiceBusRavenDB
Install-NServiceBusPerformanceCounters
Install-NServiceBusLicense
#Set-NServiceBusLocalMachineSettings
}
TestScript = {
#todo: move function to higher context
Function FileFind {
Param($dir, $file)
return (Get-ChildItem -Recurse -Force $dir -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $file } | Select-Object -First 1 FullName).FullName
}
Set-Location ("{0}\lib" -f $serviceDeployPath)
Import-Module FileFind ("{0}\lib" -f $serviceDeployPath) "NServiceBus.Powershell.dll"
#todo: fix incorrect syntax below
return Test-NServiceBusMSMQInstallation -and
Test-NServiceBusDTCInstallation -and
Test-NServiceBusRavenDBInstallation -and
Test-NServiceBusPerformanceCountersInstallation
}
GetScript = {
Function FileFind {
Param($dir, $file)
return (Get-ChildItem -Recurse -Force $dir -ErrorAction SilentlyContinue | Where-Object { $_.Name -eq $file } | Select-Object -First 1 FullName).FullName
}
Set-Location ("{0}\lib" -f $serviceDeployPath)
Import-Module FileFind ("{0}\lib" -f $serviceDeployPath) "NServiceBus.Powershell.dll"
return @{
"NServiceBusVersion" = Get-NServiceBusVersion;
"NServiceBusLocalMachineSettings" = Get-NServiceBusLocalMachineSettings;
"NServiceBusMSMQMessage" = Get-NServiceBusMSMQMessage;
}
}
}
}
}
NServiceBusServiceDeployConfig
Start-DscConfiguration -Wait -Verbose -Path .\NServiceBusServiceDeployConfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment