diff --git a/CHANGELOG.md b/CHANGELOG.md index 15410953b7..4bd06ec0c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ - Removed helper function Get-SQLPSInstance and Get-SQLPSInstanceName because there is no resource using it any longer. - Changes to xSQLServer - Fixed typos in markdown files; CHANGELOG, CONTRIBUTING, README and ISSUE_TEMPLATE. +- Changes to xSQLServerNetwork + - Added optional parameter SQLServer with default value of $env:COMPUTERNAME (issue #528). + - Added optional parameter RestartTimeout with default value of 120 seconds. + - Now the resource supports restarting a sql server in a cluster (issue #527). ## 7.0.0.0 diff --git a/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.psm1 b/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.psm1 index 5c8fb2e256..e63ed8819c 100644 --- a/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.psm1 +++ b/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.psm1 @@ -1,4 +1,8 @@ -Function Get-TargetResource +Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) ` + -ChildPath 'xSQLServerHelper.psm1') ` + -Force + +Function Get-TargetResource { [CmdletBinding()] [OutputType([System.Collections.Hashtable])] @@ -29,7 +33,7 @@ { throw "Unable to resolve SQL version for instance" } - + $smo = $dom_get.Load("Microsoft.SqlServer.Smo, Version=$version.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91") $sqlWmiManagement = $dom_get.Load("Microsoft.SqlServer.SqlWmiManagement, Version=$version.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91") @@ -55,7 +59,7 @@ { [System.AppDomain]::Unload($dom_get) } - + return $returnValue } @@ -63,6 +67,11 @@ Function Set-TargetResource { [CmdletBinding()] param( + [Parameter()] + [ValidateNotNullOrEmpty()] + [System.String] + $SQLServer = $env:COMPUTERNAME, + [parameter(Mandatory = $true)] [System.String] $InstanceName, @@ -83,7 +92,11 @@ Function Set-TargetResource $TCPPort, [System.Boolean] - $RestartService = $false + $RestartService = $false, + + [Parameter()] + [System.UInt16] + $RestartTimeout = 120 ) Write-Verbose "xSQLServerNetwork.Set-TargetResource ..." @@ -103,7 +116,7 @@ Function Set-TargetResource { throw "Unable to resolve SQL version for instance" } - + $smo = $dom_set.Load("Microsoft.SqlServer.Smo, Version=$version.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91") $sqlWmiManagement = $dom_set.Load("Microsoft.SqlServer.SqlWmiManagement, Version=$version.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91") @@ -147,58 +160,7 @@ Function Set-TargetResource if($RestartService) { - Write-Verbose "SQL Service will be restarted ..." - if($InstanceName -eq "MSSQLSERVER") - { - $dbServiceName = "MSSQLSERVER" - $agtServiceName = "SQLSERVERAGENT" - } - else - { - $dbServiceName = "MSSQL`$$InstanceName" - $agtServiceName = "SQLAgent`$$InstanceName" - } - - $sqlService = $wmi.Services[$dbServiceName] - $agentService = $wmi.Services[$agtServiceName] - $startAgent = ($agentService.ServiceState -eq "Running") - - if ($sqlService -eq $null) - { - throw "$dbServiceName service was not found, restart service failed" - } - - Write-Verbose "Stopping [$dbServiceName] service ..." - $sqlService.Stop() - - while($sqlService.ServiceState -ne "Stopped") - { - Start-Sleep -Milliseconds 500 - $sqlService.Refresh() - } - Write-Verbose "[$dbServiceName] service stopped" - - Write-Verbose "Starting [$dbServiceName] service ..." - $sqlService.Start() - - while($sqlService.ServiceState -ne "Running") - { - Start-Sleep -Milliseconds 500 - $sqlService.Refresh() - } - Write-Verbose "[$dbServiceName] service started" - - if ($startAgent) - { - Write-Verbose "Staring [$agtServiceName] service ..." - $agentService.Start() - while($agentService.ServiceState -ne "Running") - { - Start-Sleep -Milliseconds 500 - $agentService.Refresh() - } - Write-Verbose "[$agtServiceName] service started" - } + Restart-SqlService -SQLServer $SQLServer -SQLInstanceName $InstanceName -Timeout $RestartTimeout } } Finally @@ -212,6 +174,11 @@ Function Test-TargetResource [CmdletBinding()] [OutputType([System.Boolean])] param( + [Parameter()] + [ValidateNotNullOrEmpty()] + [System.String] + $SQLServer = $env:COMPUTERNAME, + [parameter(Mandatory = $true)] [System.String] $InstanceName, @@ -232,7 +199,11 @@ Function Test-TargetResource $TCPPort, [System.Boolean] - $RestartService = $false + $RestartService = $false, + + [Parameter()] + [System.UInt16] + $RestartTimeout = 120 ) Write-Verbose "xSQLServerNetwork.Test-TargetResource ..." @@ -244,8 +215,8 @@ Function Test-TargetResource IsEnabled = $IsEnabled TCPDynamicPorts = $TCPDynamicPorts TCPPort = $TCPPort - } - + } + Write-Verbose "Calling xSQLServerNetwork.Get-TargetResource ..." $currentState = Get-TargetResource -InstanceName $InstanceName -ProtocolName $ProtocolName @@ -267,7 +238,7 @@ Function Test-TargetResource } } - Write-Verbose "States match" + Write-Verbose "States match" return $true } diff --git a/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.schema.mof b/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.schema.mof index cf1be7c24e..37892fdbad 100644 --- a/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.schema.mof +++ b/DSCResources/MSFT_xSQLServerNetwork/MSFT_xSQLServerNetwork.schema.mof @@ -3,8 +3,10 @@ class MSFT_xSQLServerNetwork : OMI_BaseResource { [Key, Description("SQL Server instance name of which network protocol should be configured")] String InstanceName; [Required, Description("Network protocol name that should be configured"), ValueMap{"tcp"}, Values{"tcp"}] String ProtocolName; + [Write, Description("The host name of the SQL Server to be configured.")] String SQLServer; [Write, Description("Is network protocol should be enabled or disabled")] Boolean IsEnabled; [Write, Description("If dynamic ports are used should be set to 0, otherwise leave empty"), ValueMap{"0"}, Values{"0"}] String TCPDynamicPorts; [Write, Description("Sets static port for TCP/IP")] String TCPPort; [Write, Description("Controls if affected SQL Service should be restarted automatically")] Boolean RestartService; + [Write, Description("Timeout value for restarting the SQL services. The default value is 120 seconds.")] UInt16 RestartTimeout; }; diff --git a/README.md b/README.md index 7479050625..176eda8c84 100644 --- a/README.md +++ b/README.md @@ -739,8 +739,8 @@ SQL Max Memory = TotalPhysicalMemory - (NumOfSQLThreads\*ThreadStackSize) - (102 #### Parameters * **[String] SQLInstance** _(Key)_: The name of the SQL instance to be configured. -* **[String] SQLServer** _(Write)_: The host name of the SQL Server to be configured. Default value is *$env:COMPUTERNAME*. -* **[Boolean] DynamicAlloc** _(Write)_: If set to $true then max memory will be dynamically configured. When this is set parameter is set to $true, the parameter MaxMemory must be set to $null or not be configured. Default value is *$false*. +* **[String] SQLServer** _(Write)_: The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. +* **[Boolean] DynamicAlloc** _(Write)_: If set to $true then max memory will be dynamically configured. When this is set parameter is set to $true, the parameter MaxMemory must be set to $null or not be configured. Default value is $false. * **[String] Ensure** _(Write)_: When set to 'Present' then min and max memory will be set to either the value in parameter MinMemory and MaxMemory or dynamically configured when parameter DynamicAlloc is set to $true. When set to 'Absent' min and max memory will be set to default values. { *Present* | Absent }. * **[Sint32] MinMemory** _(Write)_: Minimum amount of memory, in MB, in the buffer pool used by the instance of SQL Server. * **[Sint32] MaxMemory** _(Write)_: Maximum amount of memory, in MB, in the buffer pool used by the instance of SQL Server. @@ -765,10 +765,12 @@ No description. * **[String] InstanceName** _(Key)_: name of SQL Server instance for which network will be configured. * **[String] ProtocolName** _(Required)_: Name of network protocol to be configured. Only tcp is currently supported. { tcp }. +* **[String] SQLServer** _(Write)_: The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME. * **[Boolean] IsEnabled** _(Write)_: Enables/Disables network protocol. * **[String] TCPDynamicPorts** _(Write)_: 0 if Dynamic ports should be used otherwise empty. { 0 }. * **[String] TCPPort** _(Write)_: Custom TCP port. -* **[Boolean] RestartService** _(Write)_: If true will restart SQL Service instance service after update. Default false. +* **[Boolean] RestartService** _(Write)_: If true will restart SQL Service instance service after update. The default value is $false. +* **[Uint16] RestartTimeout** _(Write)_: Timeout value for restarting the SQL services. The default value is 120 seconds. #### Examples