From 84c7fd2564795a279f864379b8b2c018a5c33539 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 24 Oct 2016 15:47:06 -0500 Subject: [PATCH] (maint) convert install_puppet.bat to CRLF Use CRLF instead of just LF for the template. It is not known if using LF will cause issues with Batch files in any versions of Windows. It is thought that running a batch with LF should work, but it is possible that there may be some issues somewhere. It's typically better to be on the safe side and ensure the file is CRLF. Newer versions of Puppet should leave the EOL format the same. --- templates/install_puppet.bat.erb | 98 ++++++++++++++++---------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/templates/install_puppet.bat.erb b/templates/install_puppet.bat.erb index 4b82e376e..62ba4dfd2 100644 --- a/templates/install_puppet.bat.erb +++ b/templates/install_puppet.bat.erb @@ -1,49 +1,49 @@ -SET - -set AGENT_PID=%1 -set windowTitle=Puppet Agent Upgrade -title %windowTitle% - -set pid= -for /f "tokens=2" %%a in ('tasklist /v ^| findstr /c:"%windowTitle%"') do set pid=%%a -set pid_path=%~dp0puppet_agent_upgrade.pid - -set environment= -for /f "delims=" %%i in ('puppet config print --section agent environment') do set environment=%%i - -if exist %pid_path% del %pid_path% -@echo %pid%> %pid_path% - -SET /A pid_checks_performed=0 - -:wait_for_pid -REM Wait 5 seconds -ping 127.0.0.1 -n 6 > NUL -wmic path Win32_Process where handle=%AGENT_PID% get handle /format:textvaluelist | findstr /I "Handle=%AGENT_PID%" - -SET /A pid_checks_performed+=1 -REM Wait for a max of 120 seconds (or 24 iterations) before aborting the upgrade -IF %errorlevel% == 0 IF %pid_checks_performed% == 24 ( - REM Adding CustomSource allows EventCreate to work properly - reg add HKLM\SYSTEM\CurrentControlSet\services\eventlog\Application\Puppet /v CustomSource /t REG_DWORD /d 1 /f - EVENTCREATE /T ERROR /L APPLICATION /SO Puppet /ID 101 /D "Puppet agent upgrade failed while waiting for Puppet process [ID: %AGENT_PID%] to exit." - GOTO End -) - -IF %errorlevel% == 0 ( GOTO wait_for_pid ) - -REM This *must* occur after Puppet Agent has finished applying its -REM prior catalog which manages the pxp-agent service state. If not, -REM the catalog includes the PE module which starts the service and -REM sets its startup type, which prevents installs from proceeding. -REM This may fail on agents without pxp-agent, but since this is not -REM run interactively and the next command sets ERRORLEVEL, it's OK. -net stop pxp-agent - -start /wait msiexec.exe /qn /norestart /i "<%= @_msi_location %>" /l*vx "<%= @_logfile %>" PUPPET_MASTER_SERVER="<%= @_puppet_master %>" PUPPET_AGENT_ENVIRONMENT="%environment%" <% unless @install_dir.to_s.empty? -%>INSTALLDIR="<%= @install_dir %>"<% end -%> - -:End - -if exist %pid_path% del %pid_path% - -ENDLOCAL +SET + +set AGENT_PID=%1 +set windowTitle=Puppet Agent Upgrade +title %windowTitle% + +set pid= +for /f "tokens=2" %%a in ('tasklist /v ^| findstr /c:"%windowTitle%"') do set pid=%%a +set pid_path=%~dp0puppet_agent_upgrade.pid + +set environment= +for /f "delims=" %%i in ('puppet config print --section agent environment') do set environment=%%i + +if exist %pid_path% del %pid_path% +@echo %pid%> %pid_path% + +SET /A pid_checks_performed=0 + +:wait_for_pid +REM Wait 5 seconds +ping 127.0.0.1 -n 6 > NUL +wmic path Win32_Process where handle=%AGENT_PID% get handle /format:textvaluelist | findstr /I "Handle=%AGENT_PID%" + +SET /A pid_checks_performed+=1 +REM Wait for a max of 120 seconds (or 24 iterations) before aborting the upgrade +IF %errorlevel% == 0 IF %pid_checks_performed% == 24 ( + REM Adding CustomSource allows EventCreate to work properly + reg add HKLM\SYSTEM\CurrentControlSet\services\eventlog\Application\Puppet /v CustomSource /t REG_DWORD /d 1 /f + EVENTCREATE /T ERROR /L APPLICATION /SO Puppet /ID 101 /D "Puppet agent upgrade failed while waiting for Puppet process [ID: %AGENT_PID%] to exit." + GOTO End +) + +IF %errorlevel% == 0 ( GOTO wait_for_pid ) + +REM This *must* occur after Puppet Agent has finished applying its +REM prior catalog which manages the pxp-agent service state. If not, +REM the catalog includes the PE module which starts the service and +REM sets its startup type, which prevents installs from proceeding. +REM This may fail on agents without pxp-agent, but since this is not +REM run interactively and the next command sets ERRORLEVEL, it's OK. +net stop pxp-agent + +start /wait msiexec.exe /qn /norestart /i "<%= @_msi_location %>" /l*vx "<%= @_logfile %>" PUPPET_MASTER_SERVER="<%= @_puppet_master %>" PUPPET_AGENT_ENVIRONMENT="%environment%" <% unless @install_dir.to_s.empty? -%>INSTALLDIR="<%= @install_dir %>"<% end -%> + +:End + +if exist %pid_path% del %pid_path% + +ENDLOCAL