Skip to content

Instantly share code, notes, and snippets.

@Buthrakaur

Buthrakaur/SetParameters_envX.xml Secret

Last active Jul 24, 2016
Embed
What would you like to do?
function Deploy-TopShelfService-Package {
param($DestServer, $SiteName, $UserName, $Password)
$serverUrl = "https://${DestServer}:8172/msdeploy.axd?site=$SiteName"
$dest = "auto,ComputerName=""$serverUrl"",UserName='$UserName',Password='$Password',IncludeAcls='False',AuthType='Basic'"
$webAppNameParam = "name='IIS Web Application Name',value='$SiteName/$VirtualDirectory'"
Write-Host "Deploying TopShelf service" -ForegroundColor Cyan
$cmdBase = 'Import-Module WebAdministration;$virtualFolder=[System.Environment]::ExpandEnvironmentVariables((gi ''IIS:\Sites\' + $SiteName + '\'+$slnName+''').PhysicalPath); $svc=Join-Path $virtualFolder bin\'+$slnName+'.exe;'
$preSyncCommand = 'If(Test-Path -path $svc) { Write-Host "Trying to stop service..."; & $svc stop }'
$preSyncCommand = "powershell `"$cmdBase $preSyncCommand`""
$throwOnError = "if (`$lastexitcode -ne 0) {throw 'Command failed'}"
$uninstall = "Write-Host 'Uninstalling service...'; & `$svc uninstall;"
$install = "Write-Host 'Installing service...'; & `$svc install -username:$appUser -password:'$appPass'; $throwOnError"
$start = "Write-Host 'Starting service...'; & `$svc start; $throwOnError"
$postSyncCommand = "powershell `"$cmdBase $uninstall $install $start`""
Exec { cmd.exe /C $("$MsDeployExe -verb:sync -source:package=`"$packagePath`" -dest:$dest -setParam:$webAppNameParam -setParamFile:`"$packageSetParametersPath`" -allowUntrusted -skip:Directory=\\App_Data -preSync:runCommand='$preSyncCommand',waitInterval=30000 -postSync:runCommand='$postSyncCommand',waitInterval=30000") }
Write-Host "msdeploy: $LASTEXITCODE"
}
<parameters>
<parameter name="OracleCommandTimeout" defaultValue="00:01:00">
<parameterValidation kind="AllowEmpty" />
<parameterEntry kind="XmlFile"
scope="\\app\.exe\.config$"
match="/configuration/applicationSettings/app.Settings/setting[@name='OracleCommandTimeout']/value/text()" />
</parameter>
<parameter name="DB Connection String" defaultValue="">
<parameterEntry kind="XmlFile"
scope="\\app\.exe\.config$"
match="/configuration/connectionStrings/add[@name='DB']/@connectionString" />
</parameter>
<parameter name="Logs Path" defaultValue=".\\App_Data\\Logs\\">
<parameterValidation kind="AllowEmpty" />
<parameterEntry kind="XmlFile"
scope="\\log4net\.config$"
match="/log4net/appender/file/@value" />
</parameter>
</parameters>
<?xml version="1.0" encoding="utf-8"?>
<parameters>
<setParameter name="Deployment Host" value="hhh" />
<setParameter name="Deployment User" value="xxx\yyy" />
<setParameter name="Deployment Pass" value="zzz" />
<setParameter name="DB Connection String" value="Data Source=(DESCRIPTION..." />
<setParameter name="Logs Path" value="xxx" />
</parameters>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment