Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portal AD connection #45

Merged
merged 8 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Modules/ArcGIS/ArcGISUtility.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ function Wait-ForServiceToReachDesiredState
$MaxSeconds=300,

[System.Int32]
$MaxAttempts=-1
$MaxAttempts=-1,

[Parameter(Mandatory=$false)]
[System.String]
$MachineName
)

$Attempts = 0
Expand All @@ -125,8 +129,12 @@ function Wait-ForServiceToReachDesiredState
if ($Attempts++ -gt 0) { # to skip the message for first attempt
Write-Verbose "Checking state of Service '$ServiceName'. Attempt # $Attempts"
}
if($MachineName -ne $null -or $MachineName -ne ""){
$Service = Get-Service -Name $ServiceName -ErrorAction Ignore -ComputerName $MachineName
Copy link
Contributor

@shailesh91 shailesh91 Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue -This query fails when fetching Service status from a remote machine since the local system account of the machine making the request doesn't have necessary permissions.

}else{
$Service = Get-Service -Name $ServiceName -ErrorAction Ignore
}

$Service = Get-Service -Name $ServiceName -ErrorAction Ignore

$msg = "Service '$ServiceName' not ready."
if ($Service) {
Expand Down
60 changes: 55 additions & 5 deletions Modules/ArcGIS/DSCResources/ArcGIS_Portal/ArcGIS_Portal.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ function Set-TargetResource {
Write-Verbose $PortalSelfResponse
}
}
$StandByRestartRequired = $False
$StandByMachineName = ""
if(-not($Join)){
# set system property userstoreconfig > AD only done on primary machine.
#Dont need to restart standby machine since join hasn't happened yet.
Expand Down Expand Up @@ -681,11 +683,21 @@ function Set-TargetResource {
$RestartRequired = $true
}
}
if($RestartRequired){
$machines = Get-RegisteredMachine -PortalHostName $FQDN -Token $token.token
if($machines.machines.count > 2){
$StandByRestartRequired = $true
$StandByMachineName = ($machine.machines| Where-Object { (Get-FQDN $_.machineName) -ne $FQDN }).machineName
}
}
}
if ($RestartRequired)
{
Restart-PortalService
Wait-ForUrl "https://$($FQDN):7443/arcgis/portaladmin" -HttpMethod 'GET'
if($StandByRestartRequired){
Restart-PortalService -MachineName $StandByMachineName
}
}

}
Expand Down Expand Up @@ -957,15 +969,25 @@ function Restart-PortalService {
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory=$false)]
[System.String]
$ServiceName = 'Portal for ArcGIS'
$ServiceName = 'Portal for ArcGIS',

[Parameter(Mandatory=$false)]
[System.String]
$MachineName
)

try {
Write-Verbose "Restarting Service $ServiceName"
Stop-Service -Name $ServiceName -Force -ErrorAction Ignore
if($MachineName -ne $null -or $MachineName -ne ""){
Get-Service -Name $ServiceName -ComputerName $MachineName | Set-Service -Status Stopped -Force -ErrorAction Ignore
}else{
Stop-Service -Name $ServiceName -Force -ErrorAction Ignore
}

Write-Verbose 'Stopping the service'
Wait-ForServiceToReachDesiredState -ServiceName $ServiceName -DesiredState 'Stopped'
Wait-ForServiceToReachDesiredState -ServiceName $ServiceName -DesiredState 'Stopped' -MachineName $MachineName
Write-Verbose 'Stopped the service'
}
catch {
Expand All @@ -974,8 +996,13 @@ function Restart-PortalService {

try {
Write-Verbose 'Starting the service'
Start-Service -Name $ServiceName -ErrorAction Ignore
Wait-ForServiceToReachDesiredState -ServiceName $ServiceName -DesiredState 'Running'
if($MachineName -ne $null -or $MachineName -ne ""){
Get-Service -Name $ServiceName -ComputerName $MachineName | Set-Service -Status Running -Force -ErrorAction Ignore
}else{
Start-Service -Name $ServiceName -ErrorAction Ignore
}

Wait-ForServiceToReachDesiredState -ServiceName $ServiceName -DesiredState 'Running' -MachineName $MachineName
Write-Verbose "Restarted Service '$ServiceName'"
}
catch {
Expand Down Expand Up @@ -1031,6 +1058,29 @@ function Set-LoggingLevel {
$ServiceRestartRequired
}

function Get-RegisteredMachine {
[CmdletBinding()]
param(
[System.String]
$PortalHostName = 'localhost',

[System.String]
$SiteName = 'arcgis',

[System.Int32]
$Port = 7443,

[System.String]
$Token,

[System.String]
$Referer = 'http://localhost'
)

Invoke-ArcGISWebRequest -Url ("https://$($PortalHostName):$($Port)/$SiteName/portaladmin/machines") `
-HttpFormParameters @{ f = 'json'; token = $Token; } -Referer $Referer -HttpMethod 'GET'
}

function Get-PortalSecurityConfig {
[CmdletBinding()]
param(
Expand Down