Skip to content

Commit 6a5007f

Browse files
committed
(PA-8247) Add guard against other ruby process when installing
Previously, when installing puppet on Windows, if there is another already running ruby.exe process running during the install, it would fail with an `msiexec 1603` error: Error: Failed previous installation with: ScriptHalted MSI (s) (60:6C) [22:12:51:748]: Product: Puppet Agent (64-bit) -- Error 1306. Another application has exclusive access to the file 'C:\Program Files\Puppet Labs\Puppet\puppet\bin\ruby.exe'. Please shut down all other applications, then click Retry. ... ERROR: msiexec.exe installation failed!!! Return code 1603 This commit updates files/install_puppet.ps1 to guard against other ruby processes by waiting for it to finish before trying to install puppet. It will wait however long `$WaitForPuppetRun` is before erroring.
1 parent 278235a commit 6a5007f

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)