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 12, 2018
1 parent 6146987 commit ae538b4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 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.
- Changes to SqlAlias
- Fixed issue where exception was thrown if reg keys did not exist
([issue #949](https://github.com/PowerShell/SqlServerDsc/issues/949)).
Expand Down Expand Up @@ -83,6 +88,11 @@
- Added a read-only parameter ServiceAccountName so that the service account
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)).
- 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
52 changes: 52 additions & 0 deletions SqlServerDscHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,58 @@ function Restart-SqlService
$_ | Start-Service
}
}

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

$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
}
}

<#
Expand Down

0 comments on commit ae538b4

Please sign in to comment.