Octopus.Script exported 2017-02-09 by bobjwalker belongs to ‘IIS’ category.
Stops a website in IIS.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Website name
WebsiteName
The name of the site in IIS
Status check interval
WebSiteCheckDelay = 500
The delay, in milliseconds, between each attempt to query the website to see if its status is “Stopped”
Status check retries
WebSiteCheckRetries = 20
The number of retries before an error is thrown.
Script body
Steps based on this template will execute the following PowerShell script.
# Load IIS module:
Import-Module WebAdministration
# Get WebSite Name
$webSiteName = $OctopusParameters['webSiteName']
# Get the number of retries
$retries = $OctopusParameters['webSiteCheckRetries']
# Get the number of attempts
$delay = $OctopusParameters['webSiteCheckDelay']
# Check if exists
if(Test-Path IIS:\Sites\$webSiteName) {
# Stop Website if not already stopped
if ((Get-WebSiteState $webSiteName).Value -ne "Stopped") {
Write-Output "Stopping IIS Website $webSiteName"
Stop-WebSite $webSiteName
$state = (Get-WebSiteState $webSiteName).Value
$counter = 1
# Wait for the Website to the "Stopped" before proceeding
do{
$state = (Get-WebSiteState $webSiteName).Value
Write-Output "$counter/$retries Waiting for IIS Website $webSiteName to shut down completely. Current status: $state"
$counter++
Start-Sleep -Milliseconds $delay
}
while($state -ne "Stopped" -and $counter -le $retries)
# Throw an error if the Website is not stopped
if($counter -gt $retries) {
throw "Could not shut down IIS Website $webSiteName. `nTry to increase the number of retries ($retries) or delay between attempts ($delay milliseconds)." }
}
}
else {
Write-Output "IIS Website $webSiteName doesn't exist"
}
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "9eb40453-ac5d-4cb0-8666-046ff6305a3a",
"Name": "IIS Website - Stop",
"Description": "Stops a website in IIS.",
"Version": 8,
"ExportedAt": "2017-02-09T23:04:46.440Z",
"ActionType": "Octopus.Script",
"Author": "bobjwalker",
"Parameters": [
{
"Name": "WebsiteName",
"Label": "Website name",
"HelpText": "The name of the site in IIS",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "WebSiteCheckDelay",
"Label": "Status check interval",
"HelpText": "The delay, in milliseconds, between each attempt to query the website to see if its status is \"Stopped\"",
"DefaultValue": "500",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "WebSiteCheckRetries",
"Label": "Status check retries",
"HelpText": "The number of retries before an error is thrown.",
"DefaultValue": "20",
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptBody": "# Load IIS module:\nImport-Module WebAdministration\n\n# Get WebSite Name\n$webSiteName = $OctopusParameters['webSiteName']\n# Get the number of retries\n$retries = $OctopusParameters['webSiteCheckRetries']\n# Get the number of attempts\n$delay = $OctopusParameters['webSiteCheckDelay']\n\n# Check if exists\nif(Test-Path IIS:\\Sites\\$webSiteName) {\n\n # Stop Website if not already stopped\n if ((Get-WebSiteState $webSiteName).Value -ne \"Stopped\") {\n Write-Output \"Stopping IIS Website $webSiteName\"\n Stop-WebSite $webSiteName\n \n $state = (Get-WebSiteState $webSiteName).Value\n $counter = 1\n \n # Wait for the Website to the \"Stopped\" before proceeding\n do{ \n $state = (Get-WebSiteState $webSiteName).Value\n Write-Output \"$counter/$retries Waiting for IIS Website $webSiteName 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 Website is not stopped\n if($counter -gt $retries) { \n throw \"Could not shut down IIS Website $webSiteName. `nTry to increase the number of retries ($retries) or delay between attempts ($delay milliseconds).\" }\n }\n}\nelse {\n Write-Output \"IIS Website $webSiteName doesn't exist\"\n}",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.ScriptFileName": null,
"Octopus.Action.Package.NuGetFeedId": null,
"Octopus.Action.Package.NuGetPackageId": null
},
"Category": "IIS",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/iis-website-stop.json",
"Website": "/step-templates/9eb40453-ac5d-4cb0-8666-046ff6305a3a",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAIAAAAiOjnJAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAF8hJREFUeNrsnXtwW2V6xhVLlmzJtuRL5Mv6lgt2jOMkxJkQtsWBgYbszgBZKPxTAtmZsvyzbZfpTDudMC0dys60MBs67LQDme1mCUxbaLNZoDtJFmaDA+QCXogdx7ET32JHtmTLlmTdIzt9dD5HkY4ulo7OOZKl9xmNR5alcySfn973eb/rmlu3bilIJLFVQP8CEoFFIrBIBBaJRGCRCCwSgUUiEVgkAotEYJFIBBaJwCIRWCQSgUUisEgEFolEYJEILBKBRSIRWCQCi0RgkUhpSkX/ghmXb9bpdd9cHJ93hT8SeoJWrWoq17H7VTrNWp0m/BFSTK3Jw3mFA2b7gMUBekDS9dswCRCDrK1aD8gay3W4TzzlHViA6evJOfCUDkkrcgbI2oxlO+orENIIrJwFy+0PAKYe8GS2I9PJeWoEsK51xs6GirwNY7kJFkjqHp3pmbDKzFO0EMDuX2/MwxiW46kQuY9x5r4ZGJ93405G3oa2UNnZUPlER0P+BLC8M+9AjZn3jEDWWV+xt7UWVozAylkhSyJXMhOGXw3aQWWB1+rcKk9+RPTKbbzW0DJG8x776PyZz8fODUy3L3ibZDsvvFcOJ8fVDJb9M0XApnB9u/wzWkXNCk3z8k/97hWPh9B1YnBK5hQJtpAcc8/aryqwfOMK++ngzfltbJISS7dNoX9g+abSJzBhx/om0sSrsuSiRsU/gi+gj5lqq3SaF3ZtzLHMuBrAcl1UmI8o5o4rvGOiHbNyX/BWsS8eYcDr3Z7RcUGtqfBq2xpfD3/E46+2uVtnnVv8AUO8Vz3SWvtkR0POhK4sBgvxCTxZjojJU7SqDyiMB+IlyjMjlqN/GHP7A6keVa2yN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