Thursday, 3 November 2016

How to configure the app pool recycle time from batch file


Stick the following in a configure_app_pool.bat batch file and run...


cls
@echo off

set last_five_chars_of_computername=%COMPUTERNAME:~-5%
echo.Running on %last_five_chars_of_computername%

SET recyle_time=01:55:00
IF "%last_five_chars_of_computername%" EQU "BAP01" SET recyle_time=01:55:00
IF "%last_five_chars_of_computername%" EQU "BAP02" SET recyle_time=01:56:00
IF "%last_five_chars_of_computername%" EQU "BAP03" SET recyle_time=01:57:00

REM CHOICE /C 123 /N /M "Enter 1 for bap01, 2 for bap02 or 3 for bap03, or press Ctrl+C to cancel"

REM SET answer=%ERRORLEVEL%
REM IF %answer% EQU 1 SET recyle_time=01:55:00
REM IF %answer% EQU 2 SET recyle_time=01:56:00
REM IF %answer% EQU 3 SET recyle_time=01:57:00

echo setting apppool recycle time to %recyle_time%

set recycle_period=1.05:00:00
echo setting apppool recycle period to %recycle_period%

setlocal


set servers=Beacon@RRA
set servers=%servers:@=,%

for %%a in (%servers%) do (
  FOR /F "delims=," %%i in ('%systemroot%\system32\inetsrv\appcmd list apppool /name:"$=*%%a*" /text:name') do (
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo         Setting up app pool: "%%i"                       
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
call:setFunc "%%i"
)
)

goto :eos

:eos
endlocal
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo         Please verify above configuration changes      
echo         Then press any key to exit      
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
pause
@echo on
goto:eof

::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
:setFunc
echo.
echo ***** BEFORE ******
%systemroot%\system32\inetsrv\APPCMD list apppool /apppool.name:"%~1" /config
%systemroot%\system32\inetsrv\APPCMD set apppool /apppool.name:"%~1" /recycling.periodicRestart.time:%recycle_period%
%systemroot%\system32\inetsrv\APPCMD set apppool /apppool.name:"%~1" /+recycling.periodicRestart.schedule.[value='%recyle_time%']
%systemroot%\system32\inetsrv\APPCMD set config /section:applicationPools /[name='"%~1"'].recycling.logEventOnRecycle:Time,Schedule,Memory,IsapiUnhealthy,OnDemand,ConfigChange,PrivateMemory -commit:apphost
echo.
echo ***** AFTER ******
%systemroot%\system32\inetsrv\APPCMD list apppool /apppool.name:"%~1" /config

No comments:

Post a Comment

Android mediaserver process killing battery life

If this happens to you, then do the following Force stop on Settings, Applications, All, Media Storage. Clear Cache and Clear Data, fo...