Created
January 11, 2016 19:32
-
-
Save Dalmirog-zz/b5364beb344bd9a6639d to your computer and use it in GitHub Desktop.
Stop app pool template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Id": "ActionTemplates-21", | |
"Name": "IIS AppPool - Stop", | |
"Description": "Stops an IIS Application Pool", | |
"ActionType": "Octopus.Script", | |
"Version": 2, | |
"Properties": { | |
"Octopus.Action.Script.ScriptBody": "# Load IIS module:\nImport-Module WebAdministration\n\n# Get AppPool Name\n$appPoolName = $OctopusParameters['appPoolName']\n# Get the number of retries\n$retries = $OctopusParameters['appPoolCheckRetries']\n# Get the number of attempts\n$delay = $OctopusParameters['appPoolCheckDelay']\n\n# Check if exists\nif(Test-Path IIS:\\AppPools\\$appPoolName) {\n\n # Stop App Pool if not already stopped\n if ((Get-WebAppPoolState $appPoolName).Value -ne \"Stopped\") {\n Write-Output \"Stopping IIS app pool $appPoolName\"\n Stop-WebAppPool $appPoolName\n \n $state = (Get-WebAppPoolState $appPoolName).Value\n $counter = 1\n \n # Wait for the app pool to the \"Stopped\" before proceeding\n do{ \n $state = (Get-WebAppPoolState $appPoolName).Value\n Write-Output \"$counter/$retries Waiting for IIS app pool $appPoolName to shut down completely. Current status: $state\"\n $counter++\n Start-Sleep -Milliseconds $delay\n }\n while($state -ne \"Stopped\" -and $counter -le $retries) \n \n # Throw an error if the app pool is not stopped\n if($counter -ge $retries) { \n throw \"Could not shut down IIS app pool $appPoolName. `nTry to increase the number of retries ($retries) or delay between attempts ($delay milliseconds).\" }\n }\n}\nelse {\n Write-Output \"IIS app pool $appPoolName doesn't exist\"\n}", | |
"Octopus.Action.Script.Syntax": "PowerShell" | |
}, | |
"SensitiveProperties": {}, | |
"Parameters": [ | |
{ | |
"Name": "AppPoolName", | |
"Label": "Application pool name", | |
"HelpText": "The name of the application pool in IIS.", | |
"DefaultValue": "CMP", | |
"DisplaySettings": {} | |
}, | |
{ | |
"Name": "AppPoolCheckDelay", | |
"Label": "Status check interval", | |
"HelpText": "The delay, in milliseconds, between each attempt to query the application pool to see if its status is \"Stopped\"", | |
"DefaultValue": "500", | |
"DisplaySettings": { | |
"Octopus.ControlType": "SingleLineText" | |
} | |
}, | |
{ | |
"Name": "AppPoolCheckRetries", | |
"Label": "Status check retries", | |
"HelpText": "The number of retries before an error is thrown.", | |
"DefaultValue": "20", | |
"DisplaySettings": { | |
"Octopus.ControlType": "SingleLineText" | |
} | |
} | |
], | |
"$Meta": { | |
"ExportedAt": "2016-01-11T19:32:23.148Z", | |
"OctopusVersion": "3.2.10", | |
"Type": "ActionTemplate" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment