Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) convert install_puppet.bat to CRLF #183

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 49 additions & 49 deletions templates/install_puppet.bat.erb
Original file line number Diff line number Diff line change
@@ -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