Skip to content

Commit

Permalink
Merge branch 'CarlosSardo-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hnrkndrssn committed Sep 1, 2015
2 parents 33ce97e + 4c51228 commit 30243be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion step-templates/iis-apppool-restart.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"ActionType": "Octopus.Script",
"Version": 8,
"Properties": {
"Octopus.Action.Script.ScriptBody": "# Load IIS module:\nImport-Module WebAdministration\n\n# Get AppPool Name\n$appPoolName = $OctopusParameters['appPoolName']\n\n# Start App Pool if stopped else restart\nif ((Get-WebAppPoolState($appPoolName)).Value -eq \"Stopped\"){\n Write-Output \"Starting IIS app pool $appPoolName\"\n Start-WebAppPool $appPoolName\n}\nelse {\n Write-Output \"Restarting IIS app pool $appPoolName\"\n Restart-WebAppPool $appPoolName\n}\n"
"Octopus.Action.Script.ScriptBody": "# Load IIS module:\nImport-Module WebAdministration\n\n# Get AppPool Name\n$appPoolName = $OctopusParameters['appPoolName']\n\n# Check if exists\nif (Test-Path IIS:\\AppPools\\$appPoolName){\n # Start App Pool if stopped else restart\nif ((Get-WebAppPoolState($appPoolName)).Value -eq \"Stopped\"){\n Write-Output \"Starting IIS app pool $appPoolName\"\n Start-WebAppPool $appPoolName\n}\nelse {\n Write-Output \"Restarting IIS app pool $appPoolName\"\n Restart-WebAppPool $appPoolName\n}\n}\n"
},
"SensitiveProperties": {},
"Parameters": [
Expand Down
29 changes: 23 additions & 6 deletions step-templates/iis-vdir-create.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"Id": "ActionTemplates-161",
"Id": "ActionTemplates-5",
"Name": "IIS Virtual Directory - Create",
"Description": "Create an IIS virtual directory.",
"ActionType": "Octopus.Script",
"Version": 3,
"Properties": {
"Octopus.Action.Script.ScriptBody": "## Original script by PaulStovell\n\n## --------------------------------------------------------------------------------------\n## Input\n## --------------------------------------------------------------------------------------\n\n$virtualPath = $OctopusParameters['VirtualPath']\n$physicalPath = $OctopusParameters['PhysicalPath']\n$parentSite = $OctopusParameters['ParentSite']\n\n## --------------------------------------------------------------------------------------\n## Helpers\n## --------------------------------------------------------------------------------------\n# Helper for validating input parameters\nfunction Validate-Parameter([string]$foo, [string[]]$validInput, $parameterName) {\n Write-Host \"${parameterName}: $foo\"\n if (! $foo) {\n throw \"No value was set for $parameterName, and it cannot be empty\"\n }\n \n if ($validInput) {\n if (! $validInput -contains $foo) {\n throw \"'$input' is not a valid input for '$parameterName'\"\n }\n }\n \n}\n\n# Helper to run a block with a retry if things go wrong\n$maxFailures = 5\n$sleepBetweenFailures = Get-Random -minimum 1 -maximum 4\nfunction Execute-WithRetry([ScriptBlock] $command) {\n\t$attemptCount = 0\n\t$operationIncomplete = $true\n\n\twhile ($operationIncomplete -and $attemptCount -lt $maxFailures) {\n\t\t$attemptCount = ($attemptCount + 1)\n\n\t\tif ($attemptCount -ge 2) {\n\t\t\tWrite-Output \"Waiting for $sleepBetweenFailures seconds before retrying...\"\n\t\t\tStart-Sleep -s $sleepBetweenFailures\n\t\t\tWrite-Output \"Retrying...\"\n\t\t}\n\n\t\ttry {\n\t\t\t& $command\n\n\t\t\t$operationIncomplete = $false\n\t\t} catch [System.Exception] {\n\t\t\tif ($attemptCount -lt ($maxFailures)) {\n\t\t\t\tWrite-Output (\"Attempt $attemptCount of $maxFailures failed: \" + $_.Exception.Message)\n\t\t\t\n\t\t\t}\n\t\t\telse {\n\t\t\t throw \"Failed to execute command\"\n\t\t\t}\n\t\t}\n\t}\n}\n\n## --------------------------------------------------------------------------------------\n## Configuration\n## --------------------------------------------------------------------------------------\nValidate-Parameter $virtualPath -parameterName \"Virtual path\"\nValidate-Parameter $physicalPath -parameterName \"Physical path\"\nValidate-Parameter $parentSite -parameterName \"Parent site\"\n\nAdd-PSSnapin WebAdministration -ErrorAction SilentlyContinue\nImport-Module WebAdministration -ErrorAction SilentlyContinue\n\n\n## --------------------------------------------------------------------------------------\n## Run\n## --------------------------------------------------------------------------------------\n\nWrite-Host \"Getting web site $parentSite\"\n$site = Get-Website -name $parentSite\nif (!$site) {\n throw \"The web site '$parentSite' does not exist. Please create the site first.\"\n}\n\n$parts = $virtualPath -split \"[/\\\\]\"\n$name = \"\"\n\nfor ($i = 0; $i -lt $parts.Length; $i++) {\n $name = $name + \"/\" + $parts[$i]\n $name = $name.TrimStart('/').TrimEnd('/')\n if ($i -eq $parts.Length - 1) {\n \n }\n elseif ([string]::IsNullOrEmpty($name) -eq $false -and $name -ne \"/\") {\n Write-Host \"Ensuring parent exists: $name\"\n\n $app = Get-WebApplication -Name $name -Site $parentSite\n\n if (!$app) {\n $vdir = Get-WebVirtualDirectory -Name $name -site $parentSite\n if (!$vdir) {\n throw \"The application or virtual directory '$name' does not exist\"\n }\n }\n }\n}\n\n$existing = Get-WebVirtualDirectory -site $parentSite -Name $name\n\n\nExecute-WithRetry { \n if (!$existing) {\n Write-Host \"Creating virtual directory '$name'\"\n New-Item IIS:\\Sites\\$parentSite\\$name -type VirtualDirectory -physicalPath $physicalPath\n Write-Host \"Virtual directory created\"\n } else {\n Write-Host \"The virtual directory '$name' already exists. Checking physical path.\"\n\n $currentPath = (Get-ItemProperty IIS:\\Sites\\$parentSite\\$name).physicalPath\n Write-Host \"Physical path currently set to $currentPath\"\n\n if ([string]::Compare($currentPath, $physicalPath, $True) -ne 0) {\n Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -name physicalPath -value $physicalPath\n Write-Host \"Physical path changed to $physicalPath\"\n }\n }\n}\n"
"Octopus.Action.Script.ScriptBody": "## --------------------------------------------------------------------------------------\n## Input\n## --------------------------------------------------------------------------------------\n\n$virtualPath = $OctopusParameters['VirtualPath']\n$physicalPath = $OctopusParameters['PhysicalPath']\n$parentSite = $OctopusParameters['ParentSite']\n$username = $OctopusParameters['Username']\n$password = $OctopusParameters['Password']\n\n## --------------------------------------------------------------------------------------\n## Helpers\n## --------------------------------------------------------------------------------------\n# Helper for validating input parameters\nfunction Validate-Parameter([string]$foo, [string[]]$validInput, $parameterName) {\n Write-Host \"${parameterName}: $foo\"\n if (! $foo) {\n throw \"No value was set for $parameterName, and it cannot be empty\"\n }\n\n if ($validInput) {\n if (! $validInput -contains $foo) {\n throw \"'$input' is not a valid input for '$parameterName'\"\n }\n }\n\n}\n\n# Helper to run a block with a retry if things go wrong\n$maxFailures = 5\n$sleepBetweenFailures = Get-Random -minimum 1 -maximum 4\nfunction Execute-WithRetry([ScriptBlock] $command) {\n\t$attemptCount = 0\n\t$operationIncomplete = $true\n\n\twhile ($operationIncomplete -and $attemptCount -lt $maxFailures) {\n\t\t$attemptCount = ($attemptCount + 1)\n\n\t\tif ($attemptCount -ge 2) {\n\t\t\tWrite-Output \"Waiting for $sleepBetweenFailures seconds before retrying...\"\n\t\t\tStart-Sleep -s $sleepBetweenFailures\n\t\t\tWrite-Output \"Retrying...\"\n\t\t}\n\n\t\ttry {\n\t\t\t& $command\n\n\t\t\t$operationIncomplete = $false\n\t\t} catch [System.Exception] {\n\t\t\tif ($attemptCount -lt ($maxFailures)) {\n\t\t\t\tWrite-Output (\"Attempt $attemptCount of $maxFailures failed: \" + $_.Exception.Message)\n\n\t\t\t}\n\t\t\telse {\n\t\t\t throw \"Failed to execute command\"\n\t\t\t}\n\t\t}\n\t}\n}\n\n## --------------------------------------------------------------------------------------\n## Configuration\n## --------------------------------------------------------------------------------------\nValidate-Parameter $virtualPath -parameterName \"Virtual path\"\nValidate-Parameter $physicalPath -parameterName \"Physical path\"\nValidate-Parameter $parentSite -parameterName \"Parent site\"\n\nAdd-PSSnapin WebAdministration -ErrorAction SilentlyContinue\nImport-Module WebAdministration -ErrorAction SilentlyContinue\n\n\n## --------------------------------------------------------------------------------------\n## Run\n## --------------------------------------------------------------------------------------\n\nWrite-Host \"Getting web site $parentSite\"\n$site = Get-Website -name $parentSite\nif (!$site) {\n throw \"The web site '$parentSite' does not exist. Please create the site first.\"\n}\n\n$parts = $virtualPath -split \"[/\\\\]\"\n$name = \"\"\n\nfor ($i = 0; $i -lt $parts.Length; $i++) {\n $name = $name + \"/\" + $parts[$i]\n $name = $name.TrimStart('/').TrimEnd('/')\n if ($i -eq $parts.Length - 1) {\n\n }\n elseif ([string]::IsNullOrEmpty($name) -eq $false -and $name -ne \"/\") {\n Write-Host \"Ensuring parent exists: $name\"\n\n $app = Get-WebApplication -Name $name -Site $parentSite\n\n if (!$app) {\n $vdir = Get-WebVirtualDirectory -Name $name -site $parentSite\n if (!$vdir) {\n throw \"The application or virtual directory '$name' does not exist\"\n }\n }\n }\n}\n\n$existing = Get-WebVirtualDirectory -site $parentSite -Name $name\n\n\nExecute-WithRetry {\n\n ## Init\n $virtualDirectoryPath = \"IIS:\\Sites\\$parentSite\\$name\"\n\n if (!$existing) {\n Write-Host \"Creating virtual directory '$name'\"\n\n ## Create Virtual Directory where physicalpath is an UNC-path (New-WebVirtualDirectory wont do)\n ##New-WebVirtualDirectory -Site $parentSite -Name $name -PhysicalPath $physicalPath\n\n New-Item $virtualDirectoryPath -type VirtualDirectory -physicalPath $physicalPath\n\n Write-Host \"Virtual directory created\"\n } else {\n Write-Host \"The virtual directory '$name' already exists. Checking physical path.\"\n\n $currentPath = (Get-ItemProperty IIS:\\Sites\\$parentSite\\$name).physicalPath\n Write-Host \"Physical path currently set to $currentPath\"\n\n if ([string]::Compare($currentPath, $physicalPath, $True) -ne 0) {\n Set-ItemProperty IIS:\\Sites\\$parentSite\\$name -name physicalPath -value $physicalPath\n Write-Host \"Physical path changed to $physicalPath\"\n }\n }\n\n ## Set vdir pass-through credentails, if applicable\n if (![string]::IsNullOrEmpty($username) -and ![string]::IsNullOrEmpty($password)){\n Write-Host \"Setting Pass-through credentials for username '$username'\"\n\n Set-ItemProperty $virtualDirectoryPath -Name username -Value $username\n Set-ItemProperty $virtualDirectoryPath -Name password -Value $password\n\n Write-Host \"Pass-through credentials set\"\n }\n}\n",
"Octopus.Action.Script.Syntax": "PowerShell"
},
"SensitiveProperties": {},
"Parameters": [
Expand Down Expand Up @@ -35,13 +36,29 @@
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "Username",
"Label": "Username",
"HelpText": "Pass-through authentication username",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "Password",
"Label": "Password",
"HelpText": "Pass-through authentication password",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "Sensitive"
}
}
],
"LastModifiedOn": "2015-05-05T09:39:39.137+00:00",
"LastModifiedBy": "DavidDeSloovere",
"$Meta": {
"ExportedAt": "2015-05-05T09:39:41.830Z",
"OctopusVersion": "2.6.5.1010",
"ExportedAt": "2015-08-25T13:55:15.518Z",
"OctopusVersion": "3.0.9.2259",
"Type": "ActionTemplate"
}
}

0 comments on commit 30243be

Please sign in to comment.