From 4accd72069704878891e13ac16f2c70fcd17abfd Mon Sep 17 00:00:00 2001 From: Chris Long Date: Fri, 26 Apr 2019 01:14:22 -0700 Subject: [PATCH] Add a retry for SplunkForwarder stoppage Attempt at fixing https://github.com/clong/DetectionLab/issues/243 --- Vagrant/scripts/install-inputsconf.ps1 | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Vagrant/scripts/install-inputsconf.ps1 b/Vagrant/scripts/install-inputsconf.ps1 index b0c6969..2dcd282 100755 --- a/Vagrant/scripts/install-inputsconf.ps1 +++ b/Vagrant/scripts/install-inputsconf.ps1 @@ -8,24 +8,30 @@ $targetContent = get-content c:\vagrant\resources\splunk_forwarder\inputs.conf if ($currentContent -ne $targetContent) { - Write-Host "Stopping the Splunk forwarder" - Stop-Service splunkforwarder + Write-Host "Stopping the Splunk forwarder" + 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" - Remove-Item $inputsPath + Write-Host "Deleting the default configuration" + Remove-Item $inputsPath - Write-Host "Copying over the custom configuration" - Copy-Item c:\vagrant\resources\splunk_forwarder\inputs.conf $inputsPath + Write-Host "Copying over the custom configuration" + Copy-Item c:\vagrant\resources\splunk_forwarder\inputs.conf $inputsPath - Write-Host "Starting the Splunk forwarder" - Start-Service splunkforwarder + Write-Host "Starting the Splunk forwarder" + Start-Service splunkforwarder } 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") { - throw "splunkforwarder service was not running." + throw "splunkforwarder service was not running." } Write-Host "Splunk forwarder installation complete!"