I'm trying to install Apache 2.4 on Windows 2012 using Powershell 4.0/Desired State Configuration. Since Apache apparently does not update the WMI database I don't think I can use the Package Resource because it will never match on Name or Product ID. Instead I wrote a Script resource:
Script InstallApache
{
DependsOn = @("[Environment]Apache","[File]httpdConf")
SetScript = {
$Quiet = Invoke-Expression "d:\Apache24\bin\httpd.exe -k install"
}
TestScript = {
if(Get-Service | Where-Object {$_.Name -eq "Apache2.4"}) {
$true
} else {
$false
}
}
GetScript = {
Get-Service | Where-Object {$_.Name -eq "Apache2.4"}
}
}
Which "works" except that httpd.exe throws some informational messages that DSC is interpreting as errors:
This event indicates that a non-terminating error was thrown when DSCEngine was executing Set-TargetResource on MSFT_ScriptResource DSC resource. FullyQualifiedErrorId is NativeCommandErrorMessage. ErrorMessage is The 'Apache2.4' service is successfully installed.
Can anyone recommend a way to install Apache via DSC? I'm going to attempt to deflect this issue with a try/catch block while waiting for answers.
Here's the code with try/catch. Still the same error:
Script InstallApache
{
DependsOn = @("[Environment]Apache","[File]httpdConf")
SetScript = {
try{
$Quiet = Invoke-Expression "d:\Apache24\bin\httpd.exe -k install"
} catch {
$true
}
}
TestScript = {
if(Get-Service | Where-Object {$_.Name -eq "Apache2.4"}) {
$true
} else {
$false
}
}
GetScript = {
Get-Service | Where-Object {$_.Name -eq "Apache2.4"}
}
}