【发布时间】:2020-05-09 03:15:05
【问题描述】:
我正在尝试在 iis 8.5 中将应用程序池设置为一天内多次回收,我尝试使用 powershell 和 app 命令,并且在池中没有站点/应用程序的服务器上进行测试时,它似乎可以工作完美,但是当尝试在应用程序池中有站点的服务器上使用任何一种方法进行设置时,我看到了奇怪的行为,但是如果我查看应用程序池的回收设置,它似乎在 IIS 的 GUI 中有效显示指定的时间之一。 最初尝试使用的 Powershell 脚本是:
function Set-ApplicationPoolRecycleTimes {
param (
[string]$ApplicationPoolName,
[string[]]$RestartTimes
)
Import-Module WebAdministration
Write-Output "Updating recycle times for $ApplicationPoolName"
# Delete all existing recycle times
Clear-ItemProperty IIS:\AppPools\$ApplicationPoolName -Name Recycling.periodicRestart.schedule
Clear-ItemProperty IIS:\AppPools\$ApplicationPoolName -Name Recycling.periodicRestart.time
foreach ($restartTime in $RestartTimes) {
Write-Output "Adding recycle at $restartTime"
# Set the application pool to restart at the time we want
New-ItemProperty -Path "IIS:\AppPools\$ApplicationPoolName" -Name Recycling.periodicRestart.schedule -Value @{value=$restartTime}
Set-ItemProperty -Path "IIS:\AppPools\$ApplicationPoolName" -Name Recycling.periodicRestart.time -Value "00:00:00"
} # End foreach restarttime
} # End function Set-ApplicationPoolRecycleTimes
$apppoolname1 = "app pool's name"
$restartat = @("1:45", "18:45")
Set-ApplicationPoolRecycleTimes -ApplicationPoolName $apppoolname1 -RestartTimes $restartat
除非应用程序池中有站点,否则这似乎工作得很好。当站点存在时,它似乎可以工作,只是 gui 只显示设置的时间之一:
然而查询值显示的两次:
Import-Module WebAdministration
(Get-ItemProperty ('IIS:\AppPools\app pool name') -Name Recycling.periodicRestart.schedule.collection) | select value
value
-----
18:45:00
01:45:00
也尝试使用 appcmd 但发现相同的结果,在应用程序池中没有站点的服务器上完美运行,但是当针对具有站点的服务器运行时,在 gui 中丢失了一次,查询显示了两次。我已打开应用程序池回收的登录,以确认这两次都发生了,但我想知道我是否只是忽略了一些明显的事情。
appcmd 脚本:
CD C:\windows\System32\inetsrv
$V1 = "app pool name"
#clears any existing schedule
cmd.exe /c appcmd.exe set apppool /apppool.name: $V1 /-recycling.periodicRestart.schedule
#setting desired recycles
cmd.exe /c appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='$v1'].recycling.periodicRestart.schedule.[value='01:45:00']" /commit:apphost
cmd.exe /c appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='$v1'].recycling.periodicRestart.schedule.[value='18:45:00']" /commit:apphost
【问题讨论】:
-
对我来说(我在池中有一个站点),它查询并且这家伙显示了两个时间。话虽如此,我使用
-Value $restartTime而不是-Value @{value=$restartTime},因为后者给了我一个错误(无效的演员表)我担心我无法重现你的行为,但我再次只在我的工作站(Windows 10)上进行了测试,这样可能是问题的一部分...
标签: powershell windows-server-2012-r2 application-pool iis-8.5 appcmd