93 lines
4.5 KiB
PowerShell
93 lines
4.5 KiB
PowerShell
|
function Install-DeveloperCluster {
|
|||
|
<#
|
|||
|
.SYNOPSIS
|
|||
|
Installs Developer Service Fabric Cluster.
|
|||
|
.PARAMETER dataRoot
|
|||
|
Local developer cluster data directory SF executes from
|
|||
|
.PARAMETER logRoot
|
|||
|
Local developer cluster log directory SF logs to
|
|||
|
#>
|
|||
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseCmdletCorrectly", '', Justification="We know if we are calling the right parameters")]
|
|||
|
param(
|
|||
|
$dataRoot = "C:\SFDevCluster\Data",
|
|||
|
$logRoot = "C:\SFDevCluster\Log"
|
|||
|
)
|
|||
|
|
|||
|
$clusterConfigFilePath = (Join-Path $PSScriptRoot "ServiceFabricConfigTemplates\AlkamiDevClusterConfig.json");
|
|||
|
# Import the cluster setup utility module
|
|||
|
If(!(Test-RegistryKey "HKLM:\Software\Microsoft\Service Fabric SDK")) {
|
|||
|
Throw "Service Fabric SDK is not installed"
|
|||
|
}
|
|||
|
|
|||
|
$sdkInstallPath = (Get-ItemProperty 'HKLM:\Software\Microsoft\Service Fabric SDK').FabricSDKScriptsPath
|
|||
|
$modulePath = Join-Path -Path $sdkInstallPath -ChildPath "ClusterSetupUtilities.psm1"
|
|||
|
Import-Module $modulePath
|
|||
|
Write-Host "Checking to see if a local cluster is installed"
|
|||
|
if (IsLocalClusterSetup) {
|
|||
|
Write-Host "Cleaning the existing cluster..."
|
|||
|
CleanExistingCluster
|
|||
|
}
|
|||
|
# Stop SharedAccess from interfering with service fabric startup
|
|||
|
Write-Host "Prepping Machine Services..."
|
|||
|
$internetConnectionSharingService = Get-Service SharedAccess
|
|||
|
if ($internetConnectionSharingService -and $internetConnectionSharingService.Status -eq "Running") {
|
|||
|
$internetConnectionSharingService | Set-Service -StartupType Disabled
|
|||
|
$internetConnectionSharingService.Stop();
|
|||
|
}
|
|||
|
# Start RemoteRegistry as its seemingly needed for service fabric to start up
|
|||
|
$remoteRegistryService = Get-Service RemoteRegistry
|
|||
|
if ($remoteRegistryService -and $remoteRegistryService.Status -ne "Running") {
|
|||
|
$remoteRegistryService | Set-Service -StartupType Automatic
|
|||
|
$remoteRegistryService.Start();
|
|||
|
}
|
|||
|
|
|||
|
Add-HostsFileContent -contentToAdd "127.0.0.1 microservices.dev.alkamitech.com"
|
|||
|
if(!(Test-IsAdmin)) {
|
|||
|
Throw "Not running as administrator. You need to run PowerShell with administrator privileges to setup the local cluster."
|
|||
|
}
|
|||
|
|
|||
|
$clusterRoots = SetupDataAndLogRoot -clusterDataRoot $dataRoot -clusterLogRoot $logRoot -jsonFileTemplate $clusterConfigFilePath -isAuto $True
|
|||
|
$manifestFileTemplate = ConstructManifestFileTemplate -jsonTemplate $clusterConfigFilePath
|
|||
|
$clusterDataRoot = $clusterRoots[0]
|
|||
|
$clusterLogRoot = $clusterRoots[1]
|
|||
|
Write-Host "Setting up image store..."
|
|||
|
$imageStoreConnectionString = SetupImageStore -clusterDataRoot $clusterDataRoot -useImageStoreService $False
|
|||
|
Write-Host "Prepping cluster manifest..."
|
|||
|
$manifestFile = PrepareClusterManifest $manifestFileTemplate $imageStoreConnectionString "localhost" $False $False
|
|||
|
|
|||
|
if($clusterRoots[0] -eq $False) {
|
|||
|
Throw "Failed to generate ServiceFabric Cluster"
|
|||
|
}
|
|||
|
|
|||
|
PerformServiceOperationWithWaitforStatus "FabricHostSvc" "Stop-Service" "Stopped" 10 5
|
|||
|
try {
|
|||
|
New-ServiceFabricNodeConfiguration -ClusterManifest "$manifestFile" -FabricDataRoot "$clusterDataRoot" -FabricLogRoot "$clusterLogRoot" -RunFabricHostServiceAsManual
|
|||
|
}
|
|||
|
catch {
|
|||
|
Throw "Could not create Node configuration for '$manifestFile'"
|
|||
|
}
|
|||
|
|
|||
|
Set-ItemProperty 'HKLM:\Software\Microsoft\Service Fabric SDK' -Name LocalClusterNodeCount -Value 1
|
|||
|
Set-ItemProperty 'HKLM:\Software\Microsoft\Service Fabric SDK' -Name IsMeshCluster -Value "false"
|
|||
|
# Save Connection Parameters in %AppData% for REST based powershell to consume.
|
|||
|
Write-Host "Saving connection parameters..."
|
|||
|
SaveConnectionParameters -dataRoot $clusterDataRoot -isSecure $False -useMachineName $False
|
|||
|
StartLocalCluster
|
|||
|
$connParams = Get-AlkamiConnectionParameters
|
|||
|
TryConnectToCluster -connParams $connParams -waitTime 240
|
|||
|
CheckNamingServiceReady -connParams $connParams -waitTime 120
|
|||
|
$outputString = @"
|
|||
|
Local Service Fabric Cluster created successfully.
|
|||
|
|
|||
|
=================================================
|
|||
|
## To connect using Powershell, open an a new powershell window and connect using 'Connect-ServiceFabricCluster' command (without any arguments)."
|
|||
|
|
|||
|
## To connect using Service Fabric Explorer, run ServiceFabricExplorer and connect using 'Local/OneBox Cluster'."
|
|||
|
|
|||
|
## To manage using Service Fabric Local Cluster Manager (system tray app), run ServiceFabricLocalClusterManager.exe"
|
|||
|
=================================================
|
|||
|
"@
|
|||
|
|
|||
|
Write-Host $outputString -ForegroundColor Green
|
|||
|
}
|