Skip to content

Commit

Permalink
Changes to SqlServerDsc
Browse files Browse the repository at this point in the history
- Now the helper function Restart-SqlService, after restarting the SQL Server
  service, does not return until it can connect to the SQL Server instance, and
  the instance returns status 'Online' (issue dsccommunity#1008).
  If it fails to connect within the timeout period (defaults to 120 seconds) it
  throws an error.
  • Loading branch information
johlju committed Jan 15, 2018
1 parent 4678b02 commit bf02f90
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 103 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
- Updated the security token for AppVeyor status badge in README.md. When we
renamed the repository the security token was changed
([issue #1012](https://github.com/PowerShell/SqlServerDsc/issues/1012)).
- Now the helper function Restart-SqlService, after restarting the SQL Server
service, does not return until it can connect to the SQL Server instance, and
the instance returns status 'Online' ([issue #1008](https://github.com/PowerShell/SqlServerDsc/issues/1008)).
If it fails to connect within the timeout period (defaults to 120 seconds) it
throws an error.
- Fixed typo in comment-base help for helper function Test-AvailabilityReplicaSeedingModeAutomatic.
- Style cleanup in helper function tests.
- Changes to SqlAG
Expand Down Expand Up @@ -123,6 +128,11 @@
name is correctly returned as a string ([issue #982](https://github.com/PowerShell/SqlServerDsc/issues/982)).
- Added integration tests ([issue #980](https://github.com/PowerShell/SqlServerDsc/issues/980)).
- Minor code style cleanup.
- The timing issue that the resource returned before SQL Server service was
actually restarted has been solved by a change in the helper function
Restart-SqlService ([issue #1008](https://github.com/PowerShell/SqlServerDsc/issues/1008)).
Now Restart-SqlService waits for the instance to return status 'Online' or
throws an error saying it failed to connect within the timeout period.
- Changes to SqlSetup
- Added parameter `ASServerMode` to support installing Analysis Services in
Multidimensional mode, Tabular mode and PowerPivot mode
Expand Down
55 changes: 55 additions & 0 deletions SqlServerDscHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,61 @@ function Restart-SqlService
$_ | Start-Service
}
}

Write-Verbose -Message ($script:localizedData.WaitingInstanceTimeout -f $SQLServer, $SQLInstanceName, $Timeout) -Verbose

$startJobScriptBlock = {
param
(
[Parameter()]
[System.String]
$ServerName,

[Parameter()]
[System.String]
$InstanceName,

[Parameter()]
[System.String]
$ScriptRoot
)

Import-Module -Name (Join-Path -Path $ScriptRoot -ChildPath 'SqlServerDscHelper.psm1')

do
{
# This call, if it fails, will take between ~9-10 seconds to return.
$serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName -ErrorAction SilentlyContinue
if ($serverObject.Status -ne 'Online')
{
# Waiting 2 seconds to not hammer the SQL Server instance.
Start-Sleep -Seconds 2
}
} until ($serverObject.Status -eq 'Online')
}

$startJobResult = Start-Job -ScriptBlock $startJobScriptBlock -ArgumentList @(
$SQLServer
$SQLInstanceName
$PSScriptRoot
)

Wait-Job -Job $startJobResult -Timeout $Timeout

if ($startJobResult.JobStateInfo.State -ne 'Completed')
{
# Output any verbose messages and error messages.
Receive-Job -Job $startJobResult

# Make sure the job is stopped.
Stop-Job -Job $startJobResult

$errorMessage = $script:localizedData.FailedToConnectToInstanceTimeout -f $SQLServer, $SQLInstanceName, $Timeout
New-InvalidOperationException -Message $errorMessage
}

# Make sure the job is removed.
Remove-Job -Job $startJobResult -Force
}

<#
Expand Down
Loading

0 comments on commit bf02f90

Please sign in to comment.