Skip to content

Commit cbda504

Browse files
authored
Merge pull request #1606 from janv8000/feature/iis_recycle_on_memory
IIS: allow setting max amount of private memory
2 parents 61b0feb + 688a327 commit cbda504

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

step-templates/iis-apppool-update-recycle-settings.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"Name": "IIS AppPool - Update Recycle Settings",
44
"Description": "Update the worker process and app pool timeout/recycle times.",
55
"ActionType": "Octopus.Script",
6-
"Version": 7,
6+
"Version": 8,
77
"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",
99
"Octopus.Action.Script.Syntax": "PowerShell",
1010
"Octopus.Action.Script.ScriptSource": "Inline",
1111
"Octopus.Action.RunOnServer": "false",
@@ -69,6 +69,17 @@
6969
},
7070
"Links": {}
7171
},
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.",
77+
"DefaultValue": "",
78+
"DisplaySettings": {
79+
"Octopus.ControlType": "SingleLineText"
80+
},
81+
"Links": {}
82+
},
7283
{
7384
"Id": "bb164dea-1843-4655-a0e2-b29f990b44b7",
7485
"Name": "EmptyClearsValue",
@@ -81,12 +92,12 @@
8192
"Links": {}
8293
}
8394
],
84-
"LastModifiedOn": "2021-07-26T16:50:00.000+00:00",
85-
"LastModifiedBy": "bobjwalker",
95+
"LastModifiedOn": "2025-05-22T12:45:32Z",
96+
"LastModifiedBy": "janv8000",
8697
"$Meta": {
8798
"ExportedAt": "2017-07-05T23:25:56.598Z",
8899
"OctopusVersion": "3.14.1",
89100
"Type": "ActionTemplate"
90101
},
91102
"Category": "iis"
92-
}
103+
}

0 commit comments

Comments
 (0)