Skip to content
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
21 changes: 16 additions & 5 deletions step-templates/iis-apppool-update-recycle-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"Name": "IIS AppPool - Update Recycle Settings",
"Description": "Update the worker process and app pool timeout/recycle times.",
"ActionType": "Octopus.Script",
"Version": 7,
"Version": 8,
"Properties": {
"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",
"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",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.RunOnServer": "false",
Expand Down Expand Up @@ -69,6 +69,17 @@
},
"Links": {}
},
{
"Id": "334a24ee-d347-4fd8-bc97-43be090fd5c1",
"Name": "PrivateMemoryLimitKB",
"Label": "Private memory limit in KB",
"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.",
"DefaultValue": "",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
},
"Links": {}
},
{
"Id": "bb164dea-1843-4655-a0e2-b29f990b44b7",
"Name": "EmptyClearsValue",
Expand All @@ -81,12 +92,12 @@
"Links": {}
}
],
"LastModifiedOn": "2021-07-26T16:50:00.000+00:00",
"LastModifiedBy": "bobjwalker",
"LastModifiedOn": "2025-05-22T12:45:32Z",
"LastModifiedBy": "janv8000",
"$Meta": {
"ExportedAt": "2017-07-05T23:25:56.598Z",
"OctopusVersion": "3.14.1",
"Type": "ActionTemplate"
},
"Category": "iis"
}
}