You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: step-templates/iis-apppool-update-recycle-settings.json
+16-5Lines changed: 16 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@
3
3
"Name": "IIS AppPool - Update Recycle Settings",
4
4
"Description": "Update the worker process and app pool timeout/recycle times.",
5
5
"ActionType": "Octopus.Script",
6
-
"Version": 7,
6
+
"Version": 8,
7
7
"Properties": {
8
-
"Octopus.Action.Script.ScriptBody": "Import-Module WebAdministration\n\nfunction Update-IISAppPool-PeriodicRestart($appPool, $periodicRestart) {\n Write-Output \"Setting worker process periodic restart time to $periodicRestart for AppPool $appPoolName.\"\n $appPool.Recycling.PeriodicRestart.Time = [TimeSpan]::FromMinutes($periodicRestart)\n $appPool | Set-Item\n}\n\nfunction Update-IISAppPool-IdleTimeout($appPool, $appPoolName, $idleTimeout) {\n Write-Output \"Setting worker process idle timeout to $idleTimeout for AppPool $appPoolName.\"\n $appPool.ProcessModel.IdleTimeout = [TimeSpan]::FromMinutes($idleTimeout)\n $appPool | Set-Item\n}\n\nfunction Update-IISAppPool-ScheduledTimes($appPool, $appPoolName, $schedule) {\n $minutes = $periodicRecycleTimes.Split(\",\")\n $minuteArrayList = New-Object System.Collections.ArrayList\n\n foreach ($minute in $minutes) {\n $minute = $minute.trim()\n\n if ($minute -eq \"-1\") {\n break\n }\n if ($minute -lt 0) {\n continue\n }\n\n $temp = $minuteArrayList.Add([TimeSpan]::FromMinutes($minute))\n }\n\n Write-Output \"Setting worker process scheduled restart times to $minuteArrayList for AppPool $appPoolName.\"\n\n $settingName = \"recycling.periodicRestart.schedule\"\n Clear-ItemProperty $appPool.PSPath -Name $settingName\n \n $doneOne = $false\n foreach ($minute in $minuteArrayList) {\n if ($doneOne -eq $false) {\n Set-ItemProperty $appPool.PSPath -Name $settingName -Value @{value=$minute}\n $doneOne = $true\n }\n else {\n New-ItemProperty $appPool.PSPath -Name $settingName -Value @{value=$minute}\n }\n }\n}\n\nfunction Update-IISAppPool-RecycleEventsToLog($appPool, $appPoolName, $events) {\n $settingName = \"Recycling.logEventOnRecycle\"\n Write-Output \"Setting $settingName for AppPool $appPoolName to $events.\"\n\n Clear-ItemProperty $appPool.PSPath -Name $settingName\n if ($events -ne \"-\") {\n Set-ItemProperty $appPool.PSPath -Name $settingName -Value $events\n }\n}\n\nfunction Run {\n $OctopusParameters = $OctopusParameters\n if ($OctopusParameters -eq $null) {\n write-host \"Using test values\"\n $OctopusParameters = New-Object \"System.Collections.Hashtable\"\n $OctopusParameters[\"ApplicationPoolName\"]=\"DefaultAppPool\"\n $OctopusParameters[\"IdleTimeoutMinutes\"]=\"\"\n $OctopusParameters[\"RegularTimeIntervalMinutes\"]=\"10\"\n $OctopusParameters[\"PeriodicRecycleTime\"]=\"14,15,16\"\n $OctopusParameters[\"RecycleEventsToLog\"]=\"Time, Requests, Schedule, Memory, IsapiUnhealthy, OnDemand, ConfigChange, PrivateMemory\"\n $OctopusParameters[\"EmptyClearsValue\"]=$true\n }\n\n $applicationPoolName = $OctopusParameters[\"ApplicationPoolName\"]\n $idleTimeout = $OctopusParameters[\"IdleTimeoutMinutes\"]\n $periodicRestart = $OctopusParameters[\"RegularTimeIntervalMinutes\"]\n $periodicRecycleTimes = $OctopusParameters[\"PeriodicRecycleTime\"]\n $recycleEventsToLog = $OctopusParameters[\"RecycleEventsToLog\"]\n $emptyClearsValue = $OctopusParameters[\"EmptyClearsValue\"]\n\n if ([string]::IsNullOrEmpty($applicationPoolName)) {\n throw \"Application pool name is required.\"\n }\n\n $appPool = Get-Item IIS:\\AppPools\\$applicationPoolName\n\n if ($emptyClearsValue -eq $true) {\n Write-Output \"Empty values will reset to default\"\n if ([string]::IsNullOrEmpty($idleTimeout)) {\n $idleTimeout = \"0\"\n }\n if ([string]::IsNullOrEmpty($periodicRestart)) {\n $periodicRestart = \"0\"\n }\n if ([string]::IsNullOrEmpty($periodicRecycleTimes)) {\n $periodicRecycleTimes = \"-1\"\n }\n if ([string]::IsNullOrEmpty($recycleEventsToLog)) {\n $recycleEventsToLog = \"-\"\n }\n }\n\n if (![string]::IsNullOrEmpty($periodicRestart)) {\n Update-IISAppPool-PeriodicRestart -appPool $appPool -appPoolName $appPool.Name -PeriodicRestart $periodicRestart\n }\n if (![string]::IsNullOrEmpty($idleTimeout)) {\n Update-IISAppPool-IdleTimeout -appPool $appPool -appPoolName $appPool.Name -idleTimeout $idleTimeout\n }\n if (![string]::IsNullOrEmpty($periodicRecycleTimes)) {\n Update-IISAppPool-ScheduledTimes -appPool $appPool -appPoolName $appPool.Name -Schedule $periodicRecycleTimes\n }\n if(![string]::IsNullOrEmpty($recycleEventsToLog)){\n Update-IISAppPool-RecycleEventsToLog -appPool $appPool -appPoolName $appPool.Name -Events $recycleEventsToLog \n }\n}\n\nRun\n",
8
+
"Octopus.Action.Script.ScriptBody": "Import-Module WebAdministration\n\nfunction Update-IISAppPool-PeriodicRestart($appPool, $periodicRestart) {\n Write-Output \"Setting worker process periodic restart time to $periodicRestart for AppPool $appPoolName.\"\n $appPool.Recycling.PeriodicRestart.Time = [TimeSpan]::FromMinutes($periodicRestart)\n $appPool | Set-Item\n}\n\nfunction Update-IISAppPool-IdleTimeout($appPool, $appPoolName, $idleTimeout) {\n Write-Output \"Setting worker process idle timeout to $idleTimeout for AppPool $appPoolName.\"\n $appPool.ProcessModel.IdleTimeout = [TimeSpan]::FromMinutes($idleTimeout)\n $appPool | Set-Item\n}\n\nfunction Update-IISAppPool-ScheduledTimes($appPool, $appPoolName, $schedule) {\n $minutes = $periodicRecycleTimes.Split(\",\")\n $minuteArrayList = New-Object System.Collections.ArrayList\n\n foreach ($minute in $minutes) {\n $minute = $minute.trim()\n\n if ($minute -eq \"-1\") {\n break\n }\n if ($minute -lt 0) {\n continue\n }\n\n $minuteArrayList.Add([TimeSpan]::FromMinutes($minute))\n }\n\n Write-Output \"Setting worker process scheduled restart times to $minuteArrayList for AppPool $appPoolName.\"\n\n $settingName = \"recycling.periodicRestart.schedule\"\n Clear-ItemProperty $appPool.PSPath -Name $settingName\n\n $doneOne = $false\n foreach ($minute in $minuteArrayList) {\n if ($doneOne -eq $false) {\n Set-ItemProperty $appPool.PSPath -Name $settingName -Value @{value=$minute}\n $doneOne = $true\n }\n else {\n New-ItemProperty $appPool.PSPath -Name $settingName -Value @{value=$minute}\n }\n }\n}\n\nfunction Update-IISAppPool-RecycleEventsToLog($appPool, $appPoolName, $events) {\n $settingName = \"Recycling.logEventOnRecycle\"\n Write-Output \"Setting $settingName for AppPool $appPoolName to $events.\"\n\n Clear-ItemProperty $appPool.PSPath -Name $settingName\n if ($events -ne \"-\") {\n Set-ItemProperty $appPool.PSPath -Name $settingName -Value $events\n }\n}\n\nfunction Update-IISAppPool-PrivateMemoryLimit($appPool, $appPoolName, $privateMemoryLimitKB) {\n Write-Output \"Setting private memory limit to $privateMemoryLimitKB KB for AppPool $appPoolName.\"\n $appPool.Recycling.PeriodicRestart.PrivateMemory = $privateMemoryLimitKB\n $appPool | Set-Item\n}\n\nfunction Run {\n $OctopusParameters = $OctopusParameters\n if ($null -eq $OctopusParameters) {\n write-host \"Using test values\"\n $OctopusParameters = New-Object \"System.Collections.Hashtable\"\n $OctopusParameters[\"ApplicationPoolName\"]=\"DefaultAppPool\"\n $OctopusParameters[\"IdleTimeoutMinutes\"]=\"\"\n $OctopusParameters[\"RegularTimeIntervalMinutes\"]=\"10\"\n $OctopusParameters[\"PeriodicRecycleTime\"]=\"14,15,16\"\n $OctopusParameters[\"RecycleEventsToLog\"]=\"Time, Requests, Schedule, Memory, IsapiUnhealthy, OnDemand, ConfigChange, PrivateMemory\"\n $OctopusParameters[\"PrivateMemoryLimitKB\"]=\"1024000\"\n $OctopusParameters[\"EmptyClearsValue\"]=$true\n }\n\n $applicationPoolName = $OctopusParameters[\"ApplicationPoolName\"]\n $idleTimeout = $OctopusParameters[\"IdleTimeoutMinutes\"]\n $periodicRestart = $OctopusParameters[\"RegularTimeIntervalMinutes\"]\n $periodicRecycleTimes = $OctopusParameters[\"PeriodicRecycleTime\"]\n $recycleEventsToLog = $OctopusParameters[\"RecycleEventsToLog\"]\n $privateMemoryLimitKB = $OctopusParameters[\"PrivateMemoryLimitKB\"]\n $emptyClearsValue = $OctopusParameters[\"EmptyClearsValue\"]\n\n if ([string]::IsNullOrEmpty($applicationPoolName)) {\n throw \"Application pool name is required.\"\n }\n\n $appPool = Get-Item IIS:\\AppPools\\$applicationPoolName\n\n if ($emptyClearsValue -eq $true) {\n Write-Output \"Empty values will reset to default\"\n if ([string]::IsNullOrEmpty($idleTimeout)) {\n $idleTimeout = \"0\"\n }\n if ([string]::IsNullOrEmpty($periodicRestart)) {\n $periodicRestart = \"0\"\n }\n if ([string]::IsNullOrEmpty($periodicRecycleTimes)) {\n $periodicRecycleTimes = \"-1\"\n }\n if ([string]::IsNullOrEmpty($recycleEventsToLog)) {\n $recycleEventsToLog = \"-\"\n }\n if ([string]::IsNullOrEmpty($privateMemoryLimitKB)) {\n $privateMemoryLimitKB = \"0\"\n }\n }\n\n if (![string]::IsNullOrEmpty($periodicRestart)) {\n Update-IISAppPool-PeriodicRestart -appPool $appPool -appPoolName $appPool.Name -PeriodicRestart $periodicRestart\n }\n if (![string]::IsNullOrEmpty($idleTimeout)) {\n Update-IISAppPool-IdleTimeout -appPool $appPool -appPoolName $appPool.Name -idleTimeout $idleTimeout\n }\n if (![string]::IsNullOrEmpty($periodicRecycleTimes)) {\n Update-IISAppPool-ScheduledTimes -appPool $appPool -appPoolName $appPool.Name -Schedule $periodicRecycleTimes\n }\n if(![string]::IsNullOrEmpty($recycleEventsToLog)){\n Update-IISAppPool-RecycleEventsToLog -appPool $appPool -appPoolName $appPool.Name -Events $recycleEventsToLog\n }\n if (![string]::IsNullOrEmpty($privateMemoryLimitKB)) {\n Update-IISAppPool-PrivateMemoryLimit -appPool $appPool -appPoolName $appPool.Name -PrivateMemoryLimitKB $privateMemoryLimitKB\n }\n}\n\nRun\n",
9
9
"Octopus.Action.Script.Syntax": "PowerShell",
10
10
"Octopus.Action.Script.ScriptSource": "Inline",
11
11
"Octopus.Action.RunOnServer": "false",
@@ -69,6 +69,17 @@
69
69
},
70
70
"Links": {}
71
71
},
72
+
{
73
+
"Id": "334a24ee-d347-4fd8-bc97-43be090fd5c1",
74
+
"Name": "PrivateMemoryLimitKB",
75
+
"Label": "Private memory limit in KB",
76
+
"HelpText": "Maximum amount of private memory (in KB) a worker process can consume before causing the application pool to recycle. A value of 0 means there is no limit.",
0 commit comments