Add a retry for SplunkForwarder stoppage

Attempt at fixing https://github.com/clong/DetectionLab/issues/243
This commit is contained in:
Chris Long
2019-04-26 01:14:22 -07:00
committed by GitHub
parent abda46222a
commit 4accd72069

View File

@@ -8,24 +8,30 @@ $targetContent = get-content c:\vagrant\resources\splunk_forwarder\inputs.conf
if ($currentContent -ne $targetContent) if ($currentContent -ne $targetContent)
{ {
Write-Host "Stopping the Splunk forwarder" Write-Host "Stopping the Splunk forwarder"
Stop-Service splunkforwarder try {
Stop-Service splunkforwarder -ErrorAction Stop
} catch {
Write-Host "Failed to stop SplunkForwarder. Trying again..."
Set-Location "C:\Program Files\SplunkUniversalForwarder\bin"
& ".\splunk.exe" "stop"
}
Write-Host "Deleting the default configuration" Write-Host "Deleting the default configuration"
Remove-Item $inputsPath Remove-Item $inputsPath
Write-Host "Copying over the custom configuration" Write-Host "Copying over the custom configuration"
Copy-Item c:\vagrant\resources\splunk_forwarder\inputs.conf $inputsPath Copy-Item c:\vagrant\resources\splunk_forwarder\inputs.conf $inputsPath
Write-Host "Starting the Splunk forwarder" Write-Host "Starting the Splunk forwarder"
Start-Service splunkforwarder Start-Service splunkforwarder
} }
else else
{ {
Write-Host "Splunk forwarder already configured. Moving on." Write-Host "Splunk forwarder already configured. Moving on."
} }
If ((Get-Service -name splunkforwarder).Status -ne "Running") If ((Get-Service -name splunkforwarder).Status -ne "Running")
{ {
throw "splunkforwarder service was not running." throw "splunkforwarder service was not running."
} }
Write-Host "Splunk forwarder installation complete!" Write-Host "Splunk forwarder installation complete!"