Skip to content

Instantly share code, notes, and snippets.

@ncthbrt
Created February 28, 2017 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncthbrt/cc8848b7fb93b1438b70bf9ad7ca8602 to your computer and use it in GitHub Desktop.
Save ncthbrt/cc8848b7fb93b1438b70bf9ad7ca8602 to your computer and use it in GitHub Desktop.
# This script is to be executed on the vm after intial provisioning
Param(
[Parameter(Mandatory=$true)]
[int[]]$ports,
[string]$rulePrefix='akka'
)
foreach($port in $ports){
$rules=@();
$ruleName="$($rulePrefix):$port";
try{
Get-NetFirewallRule -DisplayName $ruleName -ErrorAction Stop;
Set-NetFirewallRule -DisplayName $ruleName `
-LocalPort $port `
-Direction Inbound `
-Action Allow `
-Protocol TCP;
} catch [Exception]{
New-NetFirewallRule -DisplayName $ruleName `
-LocalPort $port `
-Direction Inbound `
-Action Allow `
-Protocol TCP;
}
}
# This script is to be executed on the vm after intial provisioning
Param(
[Parameter(Mandatory=$true)]
[string]$username
[Parameter(Mandatory=$true)]
[securestring]$password
[Parameter(Mandatory=$true)]
[string]$resourceGroupName
[Parameter(Mandatory=$true)]
[string]$role
[Parameter(Mandatory=$true)]
[string]$scriptPath,
[Object[]]
$scriptArguments=@()
)
$ErrorActionPreference = 'Stop';
# try {
# Get-AzureRmSubscription | out-null
# }
# catch {
# Login-AzureRmAccount
# }
$virtualMachines=Find-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.Compute/virtualMachines" -ExpandProperties;
$matchingMachines= $virtualMachines | Where-Object {$_.Tags["Role"] -eq $role};
$publicIps=Get-AzureRmPublicIpAddress -ResourceGroupName $resourceGroupName;
$networkInterfaces=Get-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName;
$targetIPs=@();
foreach($machine in $matchingMachines){
$matchingInterface = $networkInterfaces | Where-Object { $machine.Properties.networkProfile.networkInterfaces.id -eq $_.Id };
$ipConfiguration= @($matchingInterface) | Get-AzureRmNetworkInterfaceIpConfig;
$publicIP= ($publicIps | Where-Object { $_.IpConfiguration.Id -eq $ipConfiguration.Id}).IpAddress;
$credential= New-Object System.Management.Automation.PSCredential ($username, $password);
$sessionOptions = New-PSSessionOption -SkipCACheck -SkipCNCheck;
$targetIPs+=@($publicIP);
}
Write-Host "Establising a connection to $targetIPs";
$session = New-PSSession -Credential $credential -ComputerName $targetIPs -ErrorAction Stop -Verbose -UseSSL -SessionOption $sessionOptions;
Write-Host "Started Session on $targetIPs";
Invoke-Command -Session $session -FilePath $scriptPath -ArgumentList $scriptArguments;
Write-Host "Disconnecting from $targetIPs";
Disconnect-PSSession -Session $session | out-null;
Param(
[Parameter(Mandatory=$true)]
[string]$rootFolder,
[Parameter(Mandatory=$true)]
[string]$applicationName,
[int]$delay=0
)
Push-Location "$rootFolder";
try{
if(Test-Path "$rootFolder/Production/"){
Invoke-Expression -Command "$rootFolder/Production/$($applicationName).exe uninstall"
Start-Sleep -Seconds $delay
}
if(Test-Path "$rootFolder/Staging/"){
if(Test-Path "$rootFolder/Production/"){
Remove-Item -Recurse "$rootFolder/Production";
}
Rename-Item -Path "$rootFolder/Staging" -NewName "Production";
}
Push-Location "$rootFolder/Production"
try{
Invoke-Expression -Command "$rootFolder/Production/$($applicationName).exe install"
Invoke-Expression -Command "$rootFolder/Production/$($applicationName).exe start"
}finally{
Pop-Location
}
}finally{
Pop-Location
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment