3

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"}
    }
}
Arluin
  • 594
  • 1
  • 8
  • 21
  • The `Package` resource is supposed to work with .exe installers, but from what I understand it can be problematic. You might have better luck with [the `xPackage` community resource from Microsoft](https://github.com/PowerShell/xPSDesiredStateConfiguration) though. – briantist Dec 02 '15 at 18:59
  • Also, check to see if the exe is just unpacking MSI(s) that are being installed. I'm not familiar with that specific install so I don't know if it just wraps an MSI or not. If it does, then you could possibly just install those with a /qn switch. – EBGreen Dec 02 '15 at 19:33
  • There's four parts to the Apache install. I have File resource that pulls the httpd-2.4.17-win64-VC14.zip file on to the target server. Then there is an Archive resource that unzips the file. Then another File resource moves the Apache24 subdirectory of the httpd-2.4.17-win64-VC14 folder up to the d:\ level, and then finally the Script resource that runs the httpd.exe -k install. – Arluin Dec 02 '15 at 22:10
  • Since this is just a powershell script you can pipe your command to out-null to prevent apache installers from returning those unwanted strings. IE: d:\Apache24\bin\httpd.exe -k install | Out-Null – Randy Rakestraw Apr 12 '17 at 18:46

0 Answers0