Skip to content

Commit 14513ea

Browse files
authored
Merge pull request #823 from puppetlabs/PA-8247/guard-against-ruby-process-windows-install
(PA-8247) Add guard against other ruby process when installing
2 parents 278235a + 6a5007f commit 14513ea

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

files/install_puppet.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,30 @@ try {
320320
$msi_arguments += " PUPPET_AGENT_STARTUP_MODE=`"$PuppetStartType`""
321321
}
322322
$msi_arguments += " $InstallArgs"
323+
324+
# Check & wait for other ruby process to end
325+
# This ensures no other ruby.exe processes are running before installing
326+
if ($InstallDir) {
327+
$escapedInstallDir = $InstallDir -replace '\\', '\\'
328+
}
329+
if (Test-Path "$escapedInstallDir\puppet\bin\ruby.exe") { # The first time an upgrade is run with InstallDir, ruby.exe will not yet exist there yet
330+
$other_ruby_process_id = Get-CimInstance Win32_Process -Filter "Name='ruby.exe' AND ExecutablePath LIKE '$escapedInstallDir\\puppet\\bin\\ruby.exe'" | Select-Object -First 1 -ExpandProperty ProcessID
331+
} else {
332+
$other_ruby_process_id = Get-CimInstance Win32_Process -Filter "Name='ruby.exe' AND ExecutablePath LIKE 'C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\ruby.exe%'" | Select-Object -First 1 -ExpandProperty ProcessID
333+
}
334+
if ($other_ruby_process_id) {
335+
Write-Log "Waiting for other ruby process to stop, PID: $other_ruby_process_id" $Logfile
336+
$ruby_process = Get-Process -ID $other_ruby_process_id -ErrorAction SilentlyContinue
337+
if ($ruby_process) {
338+
if (!$ruby_process.WaitForExit($WaitForPuppetRun)){
339+
Write-Log "ERROR: Timed out waiting for ruby!" $Logfile
340+
throw
341+
}
342+
} else {
343+
Write-Log "Ruby already finished" $Logfile
344+
}
345+
}
346+
323347
Write-Log "Beginning MSI installation with Arguments: $msi_arguments" $Logfile
324348
Write-Log "****************************** Begin msiexec.exe output ******************************" $Logfile
325349
$startInfo = New-Object System.Diagnostics.ProcessStartInfo('msiexec.exe', $msi_arguments)

0 commit comments

Comments
 (0)